Search in sources :

Example 1 with AbnormalCommandTerminationException

use of com.intellij.openapi.command.AbnormalCommandTerminationException in project intellij-community by JetBrains.

the class CommandProcessorImpl method finishCommand.

@Override
public void finishCommand(final Project project, final Object command, final Throwable throwable) {
    if (myCurrentCommand != command)
        return;
    final boolean failed;
    try {
        if (throwable instanceof AbnormalCommandTerminationException) {
            final AbnormalCommandTerminationException rollback = (AbnormalCommandTerminationException) throwable;
            if (ApplicationManager.getApplication().isUnitTestMode()) {
                throw new RuntimeException(rollback);
            }
            failed = true;
        } else if (throwable != null) {
            failed = true;
            if (throwable instanceof Error) {
                throw (Error) throwable;
            } else if (throwable instanceof RuntimeException)
                throw (RuntimeException) throwable;
            CommandLog.LOG.error(throwable);
        } else {
            failed = false;
        }
    } finally {
        super.finishCommand(project, command, throwable);
    }
    if (failed) {
        if (project != null) {
            FileEditor editor = new FocusBasedCurrentEditorProvider().getCurrentEditor();
            final UndoManager undoManager = UndoManager.getInstance(project);
            if (undoManager.isUndoAvailable(editor)) {
                undoManager.undo(editor);
            }
        }
        Messages.showErrorDialog(project, "Cannot perform operation. Too complex, sorry.", "Failed to Perform Operation");
    }
}
Also used : FileEditor(com.intellij.openapi.fileEditor.FileEditor) UndoManager(com.intellij.openapi.command.undo.UndoManager) AbnormalCommandTerminationException(com.intellij.openapi.command.AbnormalCommandTerminationException)

Aggregations

AbnormalCommandTerminationException (com.intellij.openapi.command.AbnormalCommandTerminationException)1 UndoManager (com.intellij.openapi.command.undo.UndoManager)1 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1