General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion File changes lost when closing document

  • gcrews

    File changes lost when closing document

    Participants 3
    Replies 4
    Last Activity 9 years, 8 months ago

    XMetaL(R) Author Enterprise 7.0
    Version#: 7.0.0.111

    I have a macro that has the following code:
    var range = ActiveDocument.Range;
    range.SelectAll();
    range.ReadOnlyContainer = true;

    I use it to set the document to read only when the local file has become read-only.
    It sets the read-only property correctly, however it seems to cause an issue when closing the document.

    • User makes some changes
    • Code above executes and makes the page read only.
    • User closes the file.
    • Xmetal prompts to save the document or not.
    • If the user chooses “Yes” save document, the file is closed but nothing was actually saved.

    It appears that you will always unknowingly lose any changes you make a document in code view or while the ReadOnlyContainer is false.  If the ReadOnlyContainer is then set to true on the document when you close the document, XMetaL will prompt to save the changes or not.  Yet, the changes will not be saved regardless of the file read-only flag even if you “yes”.

    I have even tried setting the ReadOnlyContainer back to false on the On_Before_Document_Save macro.

    How do I make an entire document read-only in XMetaL but not cause any previous changes or code view changes the user made get lost inadvertently when they close the document?

    Reply

    Derek Read

    Reply to: File changes lost when closing document

    For a file that is read only on disk the steps I've diagrammed in the attached image should happen. I can't figure out how to get around that with scripting unless you have code in the event File_Close or File_CloseAll that does something different from this normal behaviour.

    Is that possible?

    Reply

    gcrews

    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.SelectAll();
            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.SelectNodeContents(doc);
    range.ReadOnlyContainer = true;
    range = null;

    Reply

    Derek Read

    Reply to: File changes lost when closing document

    So, you are setting ReadOnlyContainer on the document node (.DOCUMENT would be returned for the node name if you asked for range.ContainerNode right after the second line in your script). That node is a special node (something that probably only appears in our DOM and allows some APIs to do some special things — our CSS engine recognizes $DOCUMENT for the same node). The .DOCUMENT node contains the root element node.

    The behaviour is working as designed. If you set that node to be a ReadOnlyContainer node the entire document becomes readonly (if you try to change it you are given a different message than if you set ReadOnlyContainer on the root element) and that functions slightly differently from setting ReadOnlyContainer on the root element. The assumption the API makes when you set it on .DOCUMENT is that it is impossible for the document to have been altered (and so the behaviour you are seeing is a fallout of that assumption).

    I doubt that would be something we'd want to alter without having a really good reason for it as that is likely to spider out to affect other behaviours and APIs.

    Can you change your logic so the document is saved right after the change (which I assume is actually being done in script)? After your script saves the document then you would set ReadOnlyContainer.

    Reply

    gcrews

    Reply to: File changes lost when closing document

    I suspected that was what was going on, thanks for the information.

    I am trying to solve the issue where a file should be read-only in XmetaL but it has become writable. A file may correctly be read-only when someone opens it but if they switch to code view or preview and back to normal or something it may become writable and they may have made changes. Setting the document node to ready-only will work for what we need. 

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support