Search in sources :

Example 6 with GlobalUndoableAction

use of com.intellij.openapi.command.undo.GlobalUndoableAction in project android by JetBrains.

the class AndroidDbManager method processAddOrRemove.

public void processAddOrRemove(final AndroidDataSource dataSource, final boolean add) {
    final Project project = myDbFacade.getProject();
    final UndoableAction action = new GlobalUndoableAction() {

        public void undo() throws UnexpectedUndoException {
            if (add) {
                removeDataSourceInner(project, dataSource);
            } else {
                addDataSourceInner(project, dataSource);
            }
        }

        public void redo() throws UnexpectedUndoException {
            if (add) {
                addDataSourceInner(project, dataSource);
            } else {
                removeDataSourceInner(project, dataSource);
            }
        }
    };
    final String commandName = add ? DatabaseMessages.message("command.name.add.data.source") : DatabaseMessages.message("command.name.remove.data.source");
    new WriteCommandAction(project, commandName) {

        protected void run(@NotNull final Result result) throws Throwable {
            action.redo();
            UndoManager.getInstance(project).undoableActionPerformed(action);
        }

        @Override
        protected UndoConfirmationPolicy getUndoConfirmationPolicy() {
            return UndoConfirmationPolicy.REQUEST_CONFIRMATION;
        }
    }.execute();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) UndoConfirmationPolicy(com.intellij.openapi.command.UndoConfirmationPolicy) GlobalUndoableAction(com.intellij.openapi.command.undo.GlobalUndoableAction) GlobalUndoableAction(com.intellij.openapi.command.undo.GlobalUndoableAction) UndoableAction(com.intellij.openapi.command.undo.UndoableAction) Result(com.intellij.openapi.application.Result)

Aggregations

GlobalUndoableAction (com.intellij.openapi.command.undo.GlobalUndoableAction)6 UndoableAction (com.intellij.openapi.command.undo.UndoableAction)3 Project (com.intellij.openapi.project.Project)3 UndoConfirmationPolicy (com.intellij.openapi.command.UndoConfirmationPolicy)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2 Application (com.intellij.openapi.application.Application)1 Result (com.intellij.openapi.application.Result)1 UndoManager (com.intellij.openapi.command.undo.UndoManager)1 UnexpectedUndoException (com.intellij.openapi.command.undo.UnexpectedUndoException)1 Document (com.intellij.openapi.editor.Document)1 PsiCompiledElement (com.intellij.psi.PsiCompiledElement)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 Charset (java.nio.charset.Charset)1 List (java.util.List)1 DClassElement (org.jetbrains.plugins.groovy.annotator.intentions.dynamic.elements.DClassElement)1 DItemElement (org.jetbrains.plugins.groovy.annotator.intentions.dynamic.elements.DItemElement)1 GrTypeElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement)1