Search in sources :

Example 6 with BasicUndoableAction

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

the class ChangeSignatureProcessorBase method performRefactoring.

@Override
protected void performRefactoring(@NotNull UsageInfo[] usages) {
    RefactoringTransaction transaction = getTransaction();
    final ChangeInfo changeInfo = myChangeInfo;
    final RefactoringElementListener elementListener = transaction == null ? null : transaction.getElementListener(changeInfo.getMethod());
    final String fqn = CopyReferenceAction.elementToFqn(changeInfo.getMethod());
    if (fqn != null) {
        UndoableAction action = new BasicUndoableAction() {

            @Override
            public void undo() {
                if (elementListener instanceof UndoRefactoringElementListener) {
                    ((UndoRefactoringElementListener) elementListener).undoElementMovedOrRenamed(changeInfo.getMethod(), fqn);
                }
            }

            @Override
            public void redo() {
            }
        };
        UndoManager.getInstance(myProject).undoableActionPerformed(action);
    }
    try {
        doChangeSignature(changeInfo, usages);
        final PsiElement method = changeInfo.getMethod();
        LOG.assertTrue(method.isValid());
        if (elementListener != null && changeInfo.isNameChanged()) {
            elementListener.elementRenamed(method);
        }
    } catch (IncorrectOperationException e) {
        LOG.error(e);
    }
}
Also used : RefactoringElementListener(com.intellij.refactoring.listeners.RefactoringElementListener) UndoRefactoringElementListener(com.intellij.refactoring.listeners.UndoRefactoringElementListener) RefactoringTransaction(com.intellij.refactoring.listeners.impl.RefactoringTransaction) UndoRefactoringElementListener(com.intellij.refactoring.listeners.UndoRefactoringElementListener) BasicUndoableAction(com.intellij.openapi.command.undo.BasicUndoableAction) UndoableAction(com.intellij.openapi.command.undo.UndoableAction) IncorrectOperationException(com.intellij.util.IncorrectOperationException) BasicUndoableAction(com.intellij.openapi.command.undo.BasicUndoableAction) PsiElement(com.intellij.psi.PsiElement)

Example 7 with BasicUndoableAction

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

the class CommandMerger method flushCurrentCommand.

void flushCurrentCommand() {
    if (hasActions()) {
        if (!myAdditionalAffectedDocuments.isEmpty()) {
            DocumentReference[] refs = myAdditionalAffectedDocuments.toArray(new DocumentReference[myAdditionalAffectedDocuments.size()]);
            myCurrentActions.add(new BasicUndoableAction(refs) {

                @Override
                public void undo() {
                }

                @Override
                public void redo() {
                }
            });
        }
        myManager.getUndoStacksHolder().addToStacks(new UndoableGroup(myCommandName, isGlobal(), myManager, myStateBefore, myStateAfter, myCurrentActions, myUndoConfirmationPolicy, isTransparent(), myValid));
    }
    reset();
}
Also used : BasicUndoableAction(com.intellij.openapi.command.undo.BasicUndoableAction) DocumentReference(com.intellij.openapi.command.undo.DocumentReference)

Example 8 with BasicUndoableAction

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

the class ExternalAnnotationsManagerImpl method annotateExternally.

private void annotateExternally(@NotNull final VirtualFile root, @NotNull final PsiModifierListOwner listOwner, @NotNull final Project project, @NotNull final String packageName, @NotNull final String annotationFQName, @NotNull final PsiFile fromFile, @Nullable final PsiNameValuePair[] value) {
    List<XmlFile> xmlFiles = findExternalAnnotationsXmlFiles(listOwner);
    final XmlFile existingXml = findXmlFileInRoot(xmlFiles, root);
    if (existingXml != null && !FileModificationService.getInstance().preparePsiElementForWrite(existingXml)) {
        notifyAfterAnnotationChanging(listOwner, annotationFQName, false);
        return;
    }
    final Set<PsiFile> annotationFiles = xmlFiles == null ? new THashSet<>() : new THashSet<>(xmlFiles);
    new WriteCommandAction(project) {

        @Override
        protected void run(@NotNull final Result result) throws Throwable {
            if (existingXml != null) {
                annotateExternally(listOwner, annotationFQName, existingXml, fromFile, value);
            } else {
                XmlFile newXml = createAnnotationsXml(root, packageName);
                if (newXml == null) {
                    notifyAfterAnnotationChanging(listOwner, annotationFQName, false);
                } else {
                    annotationFiles.add(newXml);
                    cacheExternalAnnotations(packageName, fromFile, new SmartList<>(annotationFiles));
                    annotateExternally(listOwner, annotationFQName, newXml, fromFile, value);
                }
            }
            UndoManager.getInstance(project).undoableActionPerformed(new BasicUndoableAction() {

                @Override
                public void undo() {
                    dropCache();
                    notifyChangedExternally();
                }

                @Override
                public void redo() {
                    dropCache();
                    notifyChangedExternally();
                }
            });
        }
    }.execute();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) XmlFile(com.intellij.psi.xml.XmlFile) SmartList(com.intellij.util.SmartList) BasicUndoableAction(com.intellij.openapi.command.undo.BasicUndoableAction) Result(com.intellij.openapi.application.Result)

Example 9 with BasicUndoableAction

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

the class CCSubtaskPlaceholderAction method performAnswerPlaceholderAction.

@Override
protected void performAnswerPlaceholderAction(@NotNull CCState state) {
    Editor editor = state.getEditor();
    final int offset = editor.getCaretModel().getOffset();
    TaskFile taskFile = state.getTaskFile();
    int subtaskIndex = state.getTaskFile().getTask().getActiveSubtaskIndex();
    AnswerPlaceholder existingPlaceholder = StudyUtils.getAnswerPlaceholder(offset, taskFile.getAnswerPlaceholders());
    if (existingPlaceholder == null) {
        return;
    }
    AnswerPlaceholderSubtaskInfo info = getInfo(state, subtaskIndex, existingPlaceholder);
    if (info == null) {
        return;
    }
    EduUtils.runUndoableAction(state.getProject(), getTitle(), new BasicUndoableAction(state.getEditor().getDocument()) {

        @Override
        public void undo() throws UnexpectedUndoException {
            undoAction(existingPlaceholder, subtaskIndex, info);
            StudyUtils.drawAllAnswerPlaceholders(editor, taskFile);
        }

        @Override
        public void redo() throws UnexpectedUndoException {
            redoAction(existingPlaceholder, subtaskIndex, info);
            StudyUtils.drawAllAnswerPlaceholders(editor, taskFile);
        }
    });
}
Also used : TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) AnswerPlaceholder(com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder) AnswerPlaceholderSubtaskInfo(com.jetbrains.edu.learning.courseFormat.AnswerPlaceholderSubtaskInfo) UnexpectedUndoException(com.intellij.openapi.command.undo.UnexpectedUndoException) Editor(com.intellij.openapi.editor.Editor) BasicUndoableAction(com.intellij.openapi.command.undo.BasicUndoableAction)

Aggregations

BasicUndoableAction (com.intellij.openapi.command.undo.BasicUndoableAction)9 UnexpectedUndoException (com.intellij.openapi.command.undo.UnexpectedUndoException)3 DocumentReference (com.intellij.openapi.command.undo.DocumentReference)2 UndoableAction (com.intellij.openapi.command.undo.UndoableAction)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 UndoRefactoringElementListener (com.intellij.refactoring.listeners.UndoRefactoringElementListener)2 AnswerPlaceholder (com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder)2 Language (com.intellij.lang.Language)1 Result (com.intellij.openapi.application.Result)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 Editor (com.intellij.openapi.editor.Editor)1 ReadonlyStatusHandler (com.intellij.openapi.vfs.ReadonlyStatusHandler)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 XmlFile (com.intellij.psi.xml.XmlFile)1 RefactoringElementListener (com.intellij.refactoring.listeners.RefactoringElementListener)1 RefactoringTransaction (com.intellij.refactoring.listeners.impl.RefactoringTransaction)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 SmartList (com.intellij.util.SmartList)1 AnswerPlaceholderSubtaskInfo (com.jetbrains.edu.learning.courseFormat.AnswerPlaceholderSubtaskInfo)1