Search code examples
mps

How to run an undo action on a node in Jetbrains MPS?


I am creating a plugin which will have two buttons to perform Undo and Redo operation on a particular node. I want to know if it is possible to execute the IDE undo and redo operation problematically?


Solution

  • I found the below code performs the Undo and Redo operation in Jetbrain's MPS.

    foreach editor in FileEditorManager.getInstance(project).getAllEditors() { 
      if (editor.getName() != null && editor.getName().equals("EDITER_TO_UPDATE")) { 
        SwingUtilities.invokeLater(new Runnable() { 
          @Override 
          public void run() { 
            if (operations.equals(Operations.UNDO)) { 
              UndoManagerImpl.getInstance(project).undo(editor); 
            } else if (operations.equals(Operations.REDO)) { 
              UndoManagerImpl.getInstance(project).redo(editor); 
            } 
          } 
        }); 
      } 
    }