XML Editing via GenericDomValue

Hi All,

I have a custom editor that is editing an XML file through IDEA DOM, just like the example at:

http://www.jetbrains.com/idea/documentation/dom-rp.html

Everything is working great for read and I'm reading my xml elements as GenericDomValue.

The issue is when I try and change a value after editing by calling GenericDomValue.setValue() I get an exception:

     Assertion failed: Write access is allowed only inside write-action only

Should I be waiting until the very end of editing everything to try and save all the changes at once, rather than doing it as it happens?

Or do I need to do something else before calling setValue()?

Thanks for the help.

Tegan

0
2 comments

You should wrap all your write operations into a WriteCommandAction. The
scope of this action should be precisely what you want to be undone in a
single Ctrl+Z.

0
Avatar
Permanently deleted user

Thank you Peter, that worked perfectly, and I get all the ctrl-Z!

For anyone following, a simple code snipped of how I implemented it is:

    /**
     * Write the value to the DOM.
     */
    public void write(GenericDomValue dom) {
        //Writing to the DOM is wrapped in a WriteCommandAction, this allows ctrl-Z to work.
        PsiFile file = dom.getRoot().getFile();
        Project project = file.getProject();
        new WriteCommandAction(project, file) {
            protected void run(final Result result) throws Throwable {
                dom.setStringValue(value);
            }
        }.execute();
    }

0

Please sign in to leave a comment.