List of usage examples for com.intellij.openapi.command.undo UndoableAction UndoableAction
UndoableAction
From source file:org.exbin.deltahex.intellij.HexUndoIntelliJHandler.java
License:Apache License
private void commandAdded(final BinaryDataCommand command) { UndoableAction action = new UndoableAction() { @Override//from www .ja v a 2 s . c o m public void undo() throws CannotUndoException { commandPosition--; try { command.undo(); } catch (Exception ex) { ex.printStackTrace(); } undoUpdated(); } @Override public void redo() throws CannotRedoException { commandPosition++; try { command.redo(); } catch (Exception ex) { ex.printStackTrace(); } undoUpdated(); } @Nullable @Override public DocumentReference[] getAffectedDocuments() { return new DocumentReference[] { documentReference }; } @Override public boolean isGlobal() { return false; } }; CommandProcessor commandProcessor = CommandProcessor.getInstance(); commandProcessor.executeCommand(project, new Runnable() { @Override public void run() { undoManager.undoableActionPerformed(action); } }, command.getCaption(), "DeltaHex"); commandPosition++; undoUpdated(); for (BinaryDataUndoUpdateListener listener : listeners) { listener.undoCommandAdded(command); } }