Search in sources :

Example 6 with VcsAnnotationLocalChangesListener

use of com.intellij.openapi.vcs.changes.VcsAnnotationLocalChangesListener in project intellij-community by JetBrains.

the class SvnAnnotationIsClosedTest method testClosedByCommitFromIdea.

@Test
public void testClosedByCommitFromIdea() throws Exception {
    final SubTree tree = new SubTree(myWorkingCopyDir);
    checkin();
    VcsTestUtil.editFileInCommand(myProject, tree.myS1File, "1\n2\n3\n4\n");
    checkin();
    VcsTestUtil.editFileInCommand(myProject, tree.myS1File, "1\n2\n3**\n4\n");
    checkin();
    final VcsAnnotationLocalChangesListener listener = ProjectLevelVcsManager.getInstance(myProject).getAnnotationLocalChangesListener();
    final FileAnnotation annotation = createTestAnnotation(myVcs.getAnnotationProvider(), tree.myS1File);
    annotation.setCloser(() -> {
        myIsClosed = true;
        listener.unregisterAnnotation(tree.myS1File, annotation);
    });
    listener.registerAnnotation(tree.myS1File, annotation);
    VcsTestUtil.editFileInCommand(myProject, tree.myS1File, "1\n2\n3**\n4++\n");
    // not closed on typing
    Assert.assertFalse(myIsClosed);
    myDirtyScopeManager.markEverythingDirty();
    myChangeListManager.ensureUpToDate(false);
    final Change change = myChangeListManager.getChange(tree.myS1File);
    Assert.assertNotNull(change);
    final List<VcsException> exceptions = myVcs.getCheckinEnvironment().commit(Collections.singletonList(change), "commit");
    Assert.assertTrue(exceptions == null || exceptions.isEmpty());
    myDirtyScopeManager.fileDirty(tree.myS1File);
    myChangeListManager.ensureUpToDate(false);
    // wait for after-events like annotations recalculation
    myChangeListManager.ensureUpToDate(false);
    // zipper updater
    sleep(100);
    Assert.assertTrue(myIsClosed);
}
Also used : VcsAnnotationLocalChangesListener(com.intellij.openapi.vcs.changes.VcsAnnotationLocalChangesListener) VcsException(com.intellij.openapi.vcs.VcsException) FileAnnotation(com.intellij.openapi.vcs.annotate.FileAnnotation) Change(com.intellij.openapi.vcs.changes.Change) Test(org.junit.Test)

Example 7 with VcsAnnotationLocalChangesListener

use of com.intellij.openapi.vcs.changes.VcsAnnotationLocalChangesListener in project intellij-community by JetBrains.

the class SvnAnnotationIsClosedTest method testClosedChangedByUpdateInIdea.

@Test
public void testClosedChangedByUpdateInIdea() throws Exception {
    final SubTree tree = new SubTree(myWorkingCopyDir);
    //#1
    checkin();
    VcsTestUtil.editFileInCommand(myProject, tree.myS1File, "1\n2\n3\n4\n");
    //#2
    checkin();
    VcsTestUtil.editFileInCommand(myProject, tree.myS1File, "1\n2\n3**\n4\n");
    //#3
    checkin();
    // take #2
    runInAndVerifyIgnoreOutput("up", "-r", "2");
    final VcsAnnotationLocalChangesListener listener = ProjectLevelVcsManager.getInstance(myProject).getAnnotationLocalChangesListener();
    final FileAnnotation annotation = createTestAnnotation(myVcs.getAnnotationProvider(), tree.myS1File);
    annotation.setCloser(() -> {
        myIsClosed = true;
        listener.unregisterAnnotation(tree.myS1File, annotation);
    });
    listener.registerAnnotation(tree.myS1File, annotation);
    VcsTestUtil.editFileInCommand(myProject, tree.myS1File, "1+\n2\n3\n4\n");
    myDirtyScopeManager.markEverythingDirty();
    myChangeListManager.ensureUpToDate(false);
    Assert.assertFalse(myIsClosed);
    ProjectLevelVcsManagerEx.getInstanceEx(myProject).getOptions(VcsConfiguration.StandardOption.UPDATE).setValue(false);
    final CommonUpdateProjectAction action = new CommonUpdateProjectAction();
    action.getTemplatePresentation().setText("1");
    action.actionPerformed(new AnActionEvent(null, dataId -> {
        if (CommonDataKeys.PROJECT.is(dataId)) {
            return myProject;
        }
        return null;
    }, "test", new Presentation(), ActionManager.getInstance(), 0));
    myChangeListManager.ensureUpToDate(false);
    // wait for after-events like annotations recalculation
    myChangeListManager.ensureUpToDate(false);
    // zipper updater
    sleep(100);
    Assert.assertTrue(myIsClosed);
}
Also used : VcsTestUtil(com.intellij.openapi.vcs.VcsTestUtil) FileAnnotation(com.intellij.openapi.vcs.annotate.FileAnnotation) Change(com.intellij.openapi.vcs.changes.Change) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager) VcsRevisionDescription(com.intellij.openapi.vcs.history.VcsRevisionDescription) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsAnnotationLocalChangesListener(com.intellij.openapi.vcs.changes.VcsAnnotationLocalChangesListener) CommonUpdateProjectAction(com.intellij.openapi.vcs.update.CommonUpdateProjectAction) ProjectLevelVcsManager(com.intellij.openapi.vcs.ProjectLevelVcsManager) Presentation(com.intellij.openapi.actionSystem.Presentation) Test(org.junit.Test) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) File(java.io.File) ActionManager(com.intellij.openapi.actionSystem.ActionManager) VcsConfiguration(com.intellij.openapi.vcs.VcsConfiguration) List(java.util.List) Assert(junit.framework.Assert) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) VcsDirtyScopeManager(com.intellij.openapi.vcs.changes.VcsDirtyScopeManager) ProjectLevelVcsManagerEx(com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) VcsException(com.intellij.openapi.vcs.VcsException) Collections(java.util.Collections) Before(org.junit.Before) VcsAnnotationLocalChangesListener(com.intellij.openapi.vcs.changes.VcsAnnotationLocalChangesListener) CommonUpdateProjectAction(com.intellij.openapi.vcs.update.CommonUpdateProjectAction) FileAnnotation(com.intellij.openapi.vcs.annotate.FileAnnotation) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Presentation(com.intellij.openapi.actionSystem.Presentation) Test(org.junit.Test)

Example 8 with VcsAnnotationLocalChangesListener

use of com.intellij.openapi.vcs.changes.VcsAnnotationLocalChangesListener in project intellij-community by JetBrains.

the class AnnotateToggleAction method doAnnotate.

private static void doAnnotate(@NotNull final Editor editor, @NotNull final Project project, @Nullable final VirtualFile currentFile, @NotNull final FileAnnotation fileAnnotation, @NotNull final AbstractVcs vcs, @NotNull final UpToDateLineNumberProvider upToDateLineNumbers, final boolean warnAboutSuspiciousAnnotations) {
    if (warnAboutSuspiciousAnnotations) {
        int expectedLines = Math.max(upToDateLineNumbers.getLineCount(), 1);
        int actualLines = Math.max(fileAnnotation.getLineCount(), 1);
        if (Math.abs(expectedLines - actualLines) > 1) {
            // 1 - for different conventions about files ending with line separator
            editor.setHeaderComponent(new MyEditorNotificationPanel(editor, vcs, () -> {
                doAnnotate(editor, project, currentFile, fileAnnotation, vcs, upToDateLineNumbers, false);
            }));
            return;
        }
    }
    Disposable disposable = new Disposable() {

        @Override
        public void dispose() {
            fileAnnotation.dispose();
        }
    };
    if (fileAnnotation.getFile() != null && fileAnnotation.getFile().isInLocalFileSystem()) {
        VcsAnnotationLocalChangesListener changesListener = ProjectLevelVcsManager.getInstance(project).getAnnotationLocalChangesListener();
        changesListener.registerAnnotation(fileAnnotation.getFile(), fileAnnotation);
        Disposer.register(disposable, new Disposable() {

            @Override
            public void dispose() {
                changesListener.unregisterAnnotation(fileAnnotation.getFile(), fileAnnotation);
            }
        });
    }
    editor.getGutter().closeAllAnnotations();
    fileAnnotation.setCloser(() -> {
        UIUtil.invokeLaterIfNeeded(() -> {
            if (project.isDisposed())
                return;
            editor.getGutter().closeAllAnnotations();
        });
    });
    fileAnnotation.setReloader(newFileAnnotation -> {
        if (editor.getGutter().isAnnotationsShown()) {
            assert Comparing.equal(fileAnnotation.getFile(), newFileAnnotation.getFile());
            doAnnotate(editor, project, currentFile, newFileAnnotation, vcs, upToDateLineNumbers, false);
        }
    });
    final EditorGutterComponentEx editorGutter = (EditorGutterComponentEx) editor.getGutter();
    final List<AnnotationFieldGutter> gutters = new ArrayList<>();
    final AnnotationSourceSwitcher switcher = fileAnnotation.getAnnotationSourceSwitcher();
    final AnnotationPresentation presentation = new AnnotationPresentation(fileAnnotation, upToDateLineNumbers, switcher, disposable);
    if (currentFile != null && vcs.getCommittedChangesProvider() != null) {
        presentation.addAction(new ShowDiffFromAnnotation(fileAnnotation, vcs, currentFile));
    }
    presentation.addAction(new CopyRevisionNumberFromAnnotateAction(fileAnnotation));
    presentation.addAction(Separator.getInstance());
    final Couple<Map<VcsRevisionNumber, Color>> bgColorMap = computeBgColors(fileAnnotation, editor);
    final Map<VcsRevisionNumber, Integer> historyIds = computeLineNumbers(fileAnnotation);
    if (switcher != null) {
        switcher.switchTo(switcher.getDefaultSource());
        final LineAnnotationAspect revisionAspect = switcher.getRevisionAspect();
        final CurrentRevisionAnnotationFieldGutter currentRevisionGutter = new CurrentRevisionAnnotationFieldGutter(fileAnnotation, revisionAspect, presentation, bgColorMap);
        final MergeSourceAvailableMarkerGutter mergeSourceGutter = new MergeSourceAvailableMarkerGutter(fileAnnotation, presentation, bgColorMap);
        SwitchAnnotationSourceAction switchAction = new SwitchAnnotationSourceAction(switcher, editorGutter);
        presentation.addAction(switchAction);
        switchAction.addSourceSwitchListener(currentRevisionGutter);
        switchAction.addSourceSwitchListener(mergeSourceGutter);
        currentRevisionGutter.consume(switcher.getDefaultSource());
        mergeSourceGutter.consume(switcher.getDefaultSource());
        gutters.add(currentRevisionGutter);
        gutters.add(mergeSourceGutter);
    }
    final LineAnnotationAspect[] aspects = fileAnnotation.getAspects();
    for (LineAnnotationAspect aspect : aspects) {
        gutters.add(new AspectAnnotationFieldGutter(fileAnnotation, aspect, presentation, bgColorMap));
    }
    if (historyIds != null) {
        gutters.add(new HistoryIdColumn(fileAnnotation, presentation, bgColorMap, historyIds));
    }
    gutters.add(new HighlightedAdditionalColumn(fileAnnotation, presentation, bgColorMap));
    final AnnotateActionGroup actionGroup = new AnnotateActionGroup(gutters, editorGutter, bgColorMap);
    presentation.addAction(actionGroup, 1);
    gutters.add(new ExtraFieldGutter(fileAnnotation, presentation, bgColorMap, actionGroup));
    presentation.addAction(new AnnotateCurrentRevisionAction(fileAnnotation, vcs));
    presentation.addAction(new AnnotatePreviousRevisionAction(fileAnnotation, vcs));
    addActionsFromExtensions(presentation, fileAnnotation);
    for (AnnotationFieldGutter gutter : gutters) {
        final AnnotationGutterLineConvertorProxy proxy = new AnnotationGutterLineConvertorProxy(upToDateLineNumbers, gutter);
        if (gutter.isGutterAction()) {
            editor.getGutter().registerTextAnnotation(proxy, proxy);
        } else {
            editor.getGutter().registerTextAnnotation(proxy);
        }
    }
}
Also used : EditorGutterComponentEx(com.intellij.openapi.editor.ex.EditorGutterComponentEx) ArrayList(java.util.ArrayList) LineAnnotationAspect(com.intellij.openapi.vcs.annotate.LineAnnotationAspect) AnnotationSourceSwitcher(com.intellij.openapi.vcs.annotate.AnnotationSourceSwitcher) VcsAnnotationLocalChangesListener(com.intellij.openapi.vcs.changes.VcsAnnotationLocalChangesListener) Disposable(com.intellij.openapi.Disposable) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with VcsAnnotationLocalChangesListener

use of com.intellij.openapi.vcs.changes.VcsAnnotationLocalChangesListener in project intellij-community by JetBrains.

the class SvnAnnotationIsClosedTest method testClosedByUpdateInIdea.

@Test
public void testClosedByUpdateInIdea() throws Exception {
    final SubTree tree = new SubTree(myWorkingCopyDir);
    //#1
    checkin();
    VcsTestUtil.editFileInCommand(myProject, tree.myS1File, "1\n2\n3\n4\n");
    //#2
    checkin();
    VcsTestUtil.editFileInCommand(myProject, tree.myS1File, "1\n2\n3**\n4\n");
    //#3
    checkin();
    runInAndVerifyIgnoreOutput("up", "-r", "2");
    final VcsAnnotationLocalChangesListener listener = ProjectLevelVcsManager.getInstance(myProject).getAnnotationLocalChangesListener();
    final FileAnnotation annotation = createTestAnnotation(myVcs.getAnnotationProvider(), tree.myS1File);
    annotation.setCloser(() -> {
        myIsClosed = true;
        listener.unregisterAnnotation(tree.myS1File, annotation);
    });
    listener.registerAnnotation(tree.myS1File, annotation);
    myDirtyScopeManager.markEverythingDirty();
    myChangeListManager.ensureUpToDate(false);
    imitUpdate(myProject);
    Assert.assertTrue(myIsClosed);
}
Also used : VcsAnnotationLocalChangesListener(com.intellij.openapi.vcs.changes.VcsAnnotationLocalChangesListener) FileAnnotation(com.intellij.openapi.vcs.annotate.FileAnnotation) Test(org.junit.Test)

Example 10 with VcsAnnotationLocalChangesListener

use of com.intellij.openapi.vcs.changes.VcsAnnotationLocalChangesListener in project intellij-community by JetBrains.

the class SvnAnnotationIsClosedTest method testClosedByCommitFromIdea.

@Test
public void testClosedByCommitFromIdea() throws Exception {
    final SubTree tree = new SubTree(myWorkingCopyDir);
    checkin();
    VcsTestUtil.editFileInCommand(myProject, tree.myS1File, "1\n2\n3\n4\n");
    checkin();
    VcsTestUtil.editFileInCommand(myProject, tree.myS1File, "1\n2\n3**\n4\n");
    checkin();
    final VcsAnnotationLocalChangesListener listener = ProjectLevelVcsManager.getInstance(myProject).getAnnotationLocalChangesListener();
    final FileAnnotation annotation = createTestAnnotation(myVcs.getAnnotationProvider(), tree.myS1File);
    annotation.setCloser(() -> {
        myIsClosed = true;
        listener.unregisterAnnotation(tree.myS1File, annotation);
    });
    listener.registerAnnotation(tree.myS1File, annotation);
    VcsTestUtil.editFileInCommand(myProject, tree.myS1File, "1\n2\n3**\n4++\n");
    // not closed on typing
    Assert.assertFalse(myIsClosed);
    myDirtyScopeManager.markEverythingDirty();
    myChangeListManager.ensureUpToDate(false);
    final Change change = myChangeListManager.getChange(tree.myS1File);
    Assert.assertNotNull(change);
    final List<VcsException> exceptions = myVcs.getCheckinEnvironment().commit(Collections.singletonList(change), "commit");
    Assert.assertTrue(exceptions == null || exceptions.isEmpty());
    myDirtyScopeManager.fileDirty(tree.myS1File);
    myChangeListManager.ensureUpToDate(false);
    // wait for after-events like annotations recalculation
    myChangeListManager.ensureUpToDate(false);
    // zipper updater
    sleep(100);
    Assert.assertTrue(myIsClosed);
}
Also used : VcsAnnotationLocalChangesListener(com.intellij.openapi.vcs.changes.VcsAnnotationLocalChangesListener) VcsException(com.intellij.openapi.vcs.VcsException) FileAnnotation(com.intellij.openapi.vcs.annotate.FileAnnotation) Change(com.intellij.openapi.vcs.changes.Change) Test(org.junit.Test)

Aggregations

VcsAnnotationLocalChangesListener (com.intellij.openapi.vcs.changes.VcsAnnotationLocalChangesListener)17 FileAnnotation (com.intellij.openapi.vcs.annotate.FileAnnotation)16 Test (org.junit.Test)16 Change (com.intellij.openapi.vcs.changes.Change)10 VcsException (com.intellij.openapi.vcs.VcsException)4 LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 File (java.io.File)4 ActionManager (com.intellij.openapi.actionSystem.ActionManager)2 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)2 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)2 Presentation (com.intellij.openapi.actionSystem.Presentation)2 ProjectLevelVcsManager (com.intellij.openapi.vcs.ProjectLevelVcsManager)2 VcsConfiguration (com.intellij.openapi.vcs.VcsConfiguration)2 VcsTestUtil (com.intellij.openapi.vcs.VcsTestUtil)2 ChangeListManager (com.intellij.openapi.vcs.changes.ChangeListManager)2 VcsDirtyScopeManager (com.intellij.openapi.vcs.changes.VcsDirtyScopeManager)2 ProjectLevelVcsManagerEx (com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx)2 VcsRevisionDescription (com.intellij.openapi.vcs.history.VcsRevisionDescription)2 CommonUpdateProjectAction (com.intellij.openapi.vcs.update.CommonUpdateProjectAction)2