Home Forums General XMetaL Discussion File changes lost when closing document Reply To: File changes lost when closing document


Reply to: File changes lost when closing document

It does not seem to have anything to do with the file read-only flag.

1. Create a macro that sets the the document container to read-only.
        var range = ActiveDocument.Range;      
        range.ReadOnlyContainer = true;
2. Open a dita file.
3. Make some changes.
4. Run macro.
5. Close the document.
6. Xmetal asks to save changes.
7. Choose yes.
8. Reopen document.
The changes you made to that document before the ReadOnlyContainer was set to true that you supposedly  just saved to disk were in fact not saved but lost. I suspect the save operation aborts simply because the document container is read-only, but there are a number of case where that may not be the case.

Update: I think I found a bit of a workaround for what I need. By applying the ReadOnlyContainer to the DOM doc node, it seems to prevent editing but still saves properly when a user closes the document. The user can still delete the root node in normal mode but that’s about it.
var doc = ActiveDocument.documentElement;
var range = ActiveDocument.Range;
range.ReadOnlyContainer = true;
range = null;