Multiple file modifications and undo

Hi, my plugin have to modify several files by user's action. I want to do it in modal opertion with progressbar, so i wrote something like that:

class MyTask extends Task.Modal {

     void run() {
          for(PsiClass class : someClasses) {
               ApplicationManager.getApplication().runWriteAction(new Runnable() {
                    //some write action
               }
          }
     }
}


ProgressManager.getInstance().run(
new MyTask());

I got an exception "Write acces is allowed from event dispatch thread only". It's strange cause http://confluence.jetbrains.net/display/IDEADEV/IntelliJ+IDEA+Architectural+Overview says write actions are avaliable from modal operations.
Ok, I rewrote it to:


class MyTask extends Task.Modal {
     void run() {
          for(PsiClass class : someClasses) {
          ApplicationManager.getApplication().invokeAndWait (new Runnable() {
                         void run() {
                              ApplicationManager.getApplication().runWriteAction(new Runnable() {
                                   //some write action
                              }
                         }
                    }
               
          }
     }
}

ProgressManager.getInstance().run(new MyTask());

It works fine, but i can't make undo for my action.
Is it possible to change several files in modal operation and make undo for them? Thanks.

1 comment
Comment actions Permalink

Supporting undo is done exactly the same way regardless of the number of affected files: by wrapping the operation in CommandProcessor.executeCommand().

0

Please sign in to leave a comment.