List of usage examples for com.intellij.openapi.command.undo GlobalUndoableAction GlobalUndoableAction
public GlobalUndoableAction()
From source file:com.intellij.tasks.actions.context.ClearContextAction.java
License:Apache License
public void actionPerformed(final AnActionEvent e) { final Project project = getProject(e); GlobalUndoableAction action = new GlobalUndoableAction() { public void undo() throws UnexpectedUndoException { }/*from w ww .j ava2 s. co m*/ public void redo() throws UnexpectedUndoException { WorkingContextManager.getInstance(project).clearContext(); } }; UndoableCommand.execute(project, action, "Clear context", "Context"); }
From source file:org.intellij.plugins.intelliLang.Configuration.java
License:Apache License
public static <T> void replaceInjectionsWithUndo(final Project project, final T add, final T remove, final List<? extends PsiElement> psiElementsToRemove, final PairProcessor<T, T> actualProcessor) { final UndoableAction action = new GlobalUndoableAction() { public void undo() { actualProcessor.process(remove, add); }/*from w w w .j ava 2 s .c o m*/ public void redo() { actualProcessor.process(add, remove); } }; final List<PsiFile> psiFiles = ContainerUtil.mapNotNull(psiElementsToRemove, new NullableFunction<PsiElement, PsiFile>() { public PsiFile fun(final PsiElement psiAnnotation) { return psiAnnotation instanceof PsiCompiledElement ? null : psiAnnotation.getContainingFile(); } }); new WriteCommandAction.Simple(project, "Language Injection Configuration Update", PsiUtilCore.toPsiFileArray(psiFiles)) { public void run() { for (PsiElement annotation : psiElementsToRemove) { annotation.delete(); } actualProcessor.process(add, remove); UndoManager.getInstance(project).undoableActionPerformed(action); } @Override protected UndoConfirmationPolicy getUndoConfirmationPolicy() { return UndoConfirmationPolicy.REQUEST_CONFIRMATION; } }.execute(); }