How to add Undo (Ctrl+Z) support for changes made by an external program?

I'm working on a code formatter plugin[/url] which uses external programs to reformat .java files. Right now I do it about like this:

My problem is that when I press Ctrl+Z, IDEA gives an error message "Cannot Undo: Following files have changes that cannot be undone".

How can I make my plugin support undo?

Comment actions Permalink

As far as I know, IDEA cannot undo any external changes. The most promising approach seems to be to make the change to some temporary file, load its content and put it into the actual file with IDEA's Document API to make it aware of the change. Although that's probably not very efficient.


Comment actions Permalink

I managed to do it like you suggested. First I make temporary copies of the files and afterwards I use the Document interface to move the changes back to the original files:

For details, see the net.orfjackal.extformatter.plugin.ExternalizedCodeStyleManager class in my plugin[/url].


Please sign in to leave a comment.