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

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

Introduction

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

Prototype

public BasicUndoableAction() 

Source Link

Usage

From source file:com.android.tools.idea.gradle.AndroidGradleJavaProjectModelModifier.java

License:Apache License

private static void registerUndoAction(@NotNull Project project) {
    UndoManager.getInstance(project).undoableActionPerformed(new BasicUndoableAction() {
        @Override/*  w w  w.ja v a  2s  .c  om*/
        public void undo() throws UnexpectedUndoException {
            requestProjectSync(project);
        }

        @Override
        public void redo() throws UnexpectedUndoException {
            requestProjectSync(project);
        }
    });
}

From source file:com.intellij.codeInsight.ExternalAnnotationsManagerImpl.java

License:Apache License

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;//from  w w w .j  a  va2  s . c o  m
    }

    final Set<PsiFile> annotationFiles = xmlFiles == null ? new THashSet<PsiFile>()
            : new THashSet<PsiFile>(xmlFiles);

    new WriteCommandAction(project) {
        @Override
        protected void run(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<PsiFile>(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();
}

From source file:com.intellij.refactoring.changeSignature.ChangeSignatureProcessorBase.java

License:Apache License

@Override
protected void performRefactoring(UsageInfo[] usages) {
    RefactoringTransaction transaction = getTransaction();
    final RefactoringElementListener elementListener = transaction == null ? null
            : transaction.getElementListener(myChangeInfo.getMethod());
    final String fqn = QualifiedNameProviders.elementToFqn(myChangeInfo.getMethod());
    if (fqn != null) {
        UndoableAction action = new BasicUndoableAction() {
            @Override//from   w  w w.  j  ava2s  . c o m
            public void undo() {
                if (elementListener instanceof UndoRefactoringElementListener) {
                    ((UndoRefactoringElementListener) elementListener)
                            .undoElementMovedOrRenamed(myChangeInfo.getMethod(), fqn);
                }
            }

            @Override
            public void redo() {
            }
        };
        UndoManager.getInstance(myProject).undoableActionPerformed(action);
    }
    try {
        final ChangeSignatureUsageProcessor[] processors = ChangeSignatureUsageProcessor.EP_NAME
                .getExtensions();

        final ResolveSnapshotProvider resolveSnapshotProvider = myChangeInfo.isParameterNamesChanged()
                ? VariableInplaceRenamer.INSTANCE.forLanguage(myChangeInfo.getMethod().getLanguage())
                : null;
        final List<ResolveSnapshotProvider.ResolveSnapshot> snapshots = new ArrayList<ResolveSnapshotProvider.ResolveSnapshot>();
        for (ChangeSignatureUsageProcessor processor : processors) {
            if (resolveSnapshotProvider != null) {
                processor.registerConflictResolvers(snapshots, resolveSnapshotProvider, usages, myChangeInfo);
            }
        }

        for (UsageInfo usage : usages) {
            for (ChangeSignatureUsageProcessor processor : processors) {
                if (processor.processUsage(myChangeInfo, usage, true, usages))
                    break;
            }
        }

        LOG.assertTrue(myChangeInfo.getMethod().isValid());
        for (ChangeSignatureUsageProcessor processor : processors) {
            if (processor.processPrimaryMethod(myChangeInfo))
                break;
        }

        for (UsageInfo usage : usages) {
            for (ChangeSignatureUsageProcessor processor : processors) {
                if (processor.processUsage(myChangeInfo, usage, false, usages))
                    break;
            }
        }

        if (!snapshots.isEmpty()) {
            for (ParameterInfo parameterInfo : myChangeInfo.getNewParameters()) {
                for (ResolveSnapshotProvider.ResolveSnapshot snapshot : snapshots) {
                    snapshot.apply(parameterInfo.getName());
                }
            }
        }
        final PsiElement method = myChangeInfo.getMethod();
        LOG.assertTrue(method.isValid());
        if (elementListener != null && myChangeInfo.isNameChanged()) {
            elementListener.elementRenamed(method);
        }
    } catch (IncorrectOperationException e) {
        LOG.error(e);
    }
}

From source file:com.intellij.refactoring.rename.RenameUtil.java

License:Apache License

public static void doRename(final PsiElement element, String newName, UsageInfo[] usages, final Project project,
        @Nullable final RefactoringElementListener listener) throws IncorrectOperationException {
    final RenamePsiElementProcessor processor = RenamePsiElementProcessor.forElement(element);
    final String fqn = element instanceof PsiFile ? ((PsiFile) element).getVirtualFile().getPath()
            : QualifiedNameProviders.elementToFqn(element);
    if (fqn != null) {
        UndoableAction action = new BasicUndoableAction() {
            @Override/*from  w w  w  .j a  va  2 s.c o m*/
            public void undo() throws UnexpectedUndoException {
                if (listener instanceof UndoRefactoringElementListener) {
                    ((UndoRefactoringElementListener) listener).undoElementMovedOrRenamed(element, fqn);
                }
            }

            @Override
            public void redo() throws UnexpectedUndoException {
            }
        };
        UndoManager.getInstance(project).undoableActionPerformed(action);
    }
    processor.renameElement(element, newName, usages, listener);
}