Example usage for com.intellij.openapi.command.undo UndoableAction UndoableAction

List of usage examples for com.intellij.openapi.command.undo UndoableAction UndoableAction

Introduction

In this page you can find the example usage for com.intellij.openapi.command.undo UndoableAction UndoableAction.

Prototype

UndoableAction

Source Link

Usage

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);
    }
}