Search in sources :

Example 6 with LocalHistoryAction

use of com.intellij.history.LocalHistoryAction in project intellij-community by JetBrains.

the class ActionsTest method testSavingDocumentBeforeAndAfterAction.

public void testSavingDocumentBeforeAndAfterAction() throws Exception {
    VirtualFile f = createFile("f.txt", "file1");
    loadContent(f);
    setContent(f, "file2");
    setDocumentTextFor(f, "doc1");
    LocalHistoryAction a = LocalHistory.getInstance().startAction("name");
    setDocumentTextFor(f, "doc2");
    a.finish();
    List<Revision> rr = getRevisionsFor(f);
    assertEquals(5, rr.size());
    assertContent("doc2", rr.get(0).findEntry());
    assertEquals("name", rr.get(1).getChangeSetName());
    assertContent("doc1", rr.get(1).findEntry());
    assertContent("file2", rr.get(2).findEntry());
    assertContent("file1", rr.get(3).findEntry());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Revision(com.intellij.history.core.revisions.Revision) LocalHistoryAction(com.intellij.history.LocalHistoryAction)

Example 7 with LocalHistoryAction

use of com.intellij.history.LocalHistoryAction in project intellij-community by JetBrains.

the class ActionsTest method testActionInsideCommandSurroundedWithSomeChanges.

public void testActionInsideCommandSurroundedWithSomeChanges() throws Exception {
    // see testActionInsideCommand comment
    final VirtualFile f = createFile("f.txt");
    CommandProcessor.getInstance().executeCommand(myProject, new RunnableAdapter() {

        @Override
        public void doRun() throws IOException {
            setContent(f, "file");
            setDocumentTextFor(f, "doc1");
            LocalHistoryAction a = LocalHistory.getInstance().startAction("action");
            setDocumentTextFor(f, "doc2");
            a.finish();
            saveDocument(f);
            setContent(f, "doc3");
        }
    }, "command", null);
    List<Revision> rr = getRevisionsFor(f);
    assertEquals(4, rr.size());
    assertContent("doc3", rr.get(0).findEntry());
    assertContent("doc1", rr.get(1).findEntry());
    assertContent("", rr.get(2).findEntry());
    assertEquals("command", rr.get(1).getChangeSetName());
    assertNull(rr.get(2).getChangeSetName());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RunnableAdapter(com.intellij.history.utils.RunnableAdapter) Revision(com.intellij.history.core.revisions.Revision) LocalHistoryAction(com.intellij.history.LocalHistoryAction) IOException(java.io.IOException)

Example 8 with LocalHistoryAction

use of com.intellij.history.LocalHistoryAction in project intellij-community by JetBrains.

the class GettingContentAtDateTest method testWithUnsavedDocuments.

public void testWithUnsavedDocuments() throws Exception {
    setContent(f, "FILE1", TIMESTAMP_INCREMENT);
    Clock.setTime(TIMESTAMP_INCREMENT * 2);
    LocalHistoryAction a = LocalHistory.getInstance().startAction(null);
    setDocumentTextFor(f, "DOC1");
    a.finish();
    Clock.setTime(TIMESTAMP_INCREMENT * 3);
    a = LocalHistory.getInstance().startAction(null);
    setDocumentTextFor(f, "DOC2");
    a.finish();
    FileDocumentManager.getInstance().saveAllDocuments();
    setContent(f, "FILE2", TIMESTAMP_INCREMENT * 4);
    assertContentAt(new FileRevisionTimestampComparator() {

        @Override
        public boolean isSuitable(long revisionTimestamp) {
            return revisionTimestamp == TIMESTAMP_INCREMENT * 4;
        }
    }, "FILE2");
    assertContentAt(new FileRevisionTimestampComparator() {

        @Override
        public boolean isSuitable(long revisionTimestamp) {
            return revisionTimestamp == TIMESTAMP_INCREMENT * 3;
        }
    }, "DOC2");
    assertContentAt(new FileRevisionTimestampComparator() {

        @Override
        public boolean isSuitable(long revisionTimestamp) {
            return revisionTimestamp == TIMESTAMP_INCREMENT * 2;
        }
    }, "DOC1");
    assertContentAt(new FileRevisionTimestampComparator() {

        @Override
        public boolean isSuitable(long revisionTimestamp) {
            return revisionTimestamp == TIMESTAMP_INCREMENT;
        }
    }, "FILE1");
}
Also used : FileRevisionTimestampComparator(com.intellij.history.FileRevisionTimestampComparator) LocalHistoryAction(com.intellij.history.LocalHistoryAction)

Example 9 with LocalHistoryAction

use of com.intellij.history.LocalHistoryAction in project android by JetBrains.

the class AndroidInferNullityAnnotationAction method applyRunnable.

// Intellij code from InferNullityAnnotationsAction.
private static Runnable applyRunnable(Project project, Computable<UsageInfo[]> computable) {
    return () -> {
        LocalHistoryAction action = LocalHistory.getInstance().startAction(INFER_NULLITY_ANNOTATIONS);
        try {
            new WriteCommandAction(project, INFER_NULLITY_ANNOTATIONS) {

                @Override
                protected void run(@NotNull Result result) throws Throwable {
                    UsageInfo[] infos = computable.compute();
                    if (infos.length > 0) {
                        Set<PsiElement> elements = new LinkedHashSet<>();
                        for (UsageInfo info : infos) {
                            PsiElement element = info.getElement();
                            if (element != null) {
                                ContainerUtil.addIfNotNull(elements, element.getContainingFile());
                            }
                        }
                        if (!FileModificationService.getInstance().preparePsiElementsForWrite(elements))
                            return;
                        SequentialModalProgressTask progressTask = new SequentialModalProgressTask(project, INFER_NULLITY_ANNOTATIONS, false);
                        progressTask.setMinIterationTime(200);
                        progressTask.setTask(new AnnotateTask(project, progressTask, infos));
                        ProgressManager.getInstance().run(progressTask);
                    } else {
                        NullityInferrer.nothingFoundMessage(project);
                    }
                }
            }.execute();
        } finally {
            action.finish();
        }
    };
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) LocalHistoryAction(com.intellij.history.LocalHistoryAction) NotNull(org.jetbrains.annotations.NotNull) UsageInfo(com.intellij.usageView.UsageInfo) PsiElement(com.intellij.psi.PsiElement) SequentialModalProgressTask(com.intellij.util.SequentialModalProgressTask) Result(com.intellij.openapi.application.Result)

Example 10 with LocalHistoryAction

use of com.intellij.history.LocalHistoryAction in project intellij-community by JetBrains.

the class MethodDuplicatesHandler method replaceDuplicate.

private static void replaceDuplicate(final Project project, final Map<PsiMember, List<Match>> duplicates, final Set<PsiMember> methods) {
    final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
    if (progressIndicator != null && progressIndicator.isCanceled())
        return;
    final Runnable replaceRunnable = () -> {
        LocalHistoryAction a = LocalHistory.getInstance().startAction(REFACTORING_NAME);
        try {
            for (final PsiMember member : methods) {
                final List<Match> matches = duplicates.get(member);
                if (matches == null)
                    continue;
                final int duplicatesNo = matches.size();
                WindowManager.getInstance().getStatusBar(project).setInfo(getStatusMessage(duplicatesNo));
                CommandProcessor.getInstance().executeCommand(project, () -> PostprocessReformattingAspect.getInstance(project).postponeFormattingInside(() -> {
                    final MatchProvider matchProvider = member instanceof PsiMethod ? new MethodDuplicatesMatchProvider((PsiMethod) member, matches) : new ConstantMatchProvider(member, project, matches);
                    DuplicatesImpl.invoke(project, matchProvider);
                }), REFACTORING_NAME, REFACTORING_NAME);
                WindowManager.getInstance().getStatusBar(project).setInfo("");
            }
        } finally {
            a.finish();
        }
    };
    ApplicationManager.getApplication().invokeLater(replaceRunnable, ModalityState.NON_MODAL);
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) LocalHistoryAction(com.intellij.history.LocalHistoryAction)

Aggregations

LocalHistoryAction (com.intellij.history.LocalHistoryAction)24 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 Result (com.intellij.openapi.application.Result)7 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)7 NotNull (org.jetbrains.annotations.NotNull)7 UsageInfo (com.intellij.usageView.UsageInfo)4 Revision (com.intellij.history.core.revisions.Revision)3 Project (com.intellij.openapi.project.Project)3 PsiElement (com.intellij.psi.PsiElement)3 IncorrectOperationException (com.intellij.util.IncorrectOperationException)3 SequentialModalProgressTask (com.intellij.util.SequentialModalProgressTask)3 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)2 ArtifactDependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel)2 DependenciesModel (com.android.tools.idea.gradle.dsl.model.dependencies.DependenciesModel)2 AndroidModuleInfo (com.android.tools.idea.model.AndroidModuleInfo)2 RepositoryUrlManager (com.android.tools.idea.templates.RepositoryUrlManager)2 BuildFileModifier (com.google.idea.blaze.base.buildmodifier.BuildFileModifier)2 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)2 LocalHistory (com.intellij.history.LocalHistory)2 Module (com.intellij.openapi.module.Module)2