Search in sources :

Example 11 with EditorGutterComponentEx

use of com.intellij.openapi.editor.ex.EditorGutterComponentEx 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 12 with EditorGutterComponentEx

use of com.intellij.openapi.editor.ex.EditorGutterComponentEx in project intellij-community by JetBrains.

the class CaretImpl method requestRepaint.

private void requestRepaint(VerticalInfo oldCaretInfo) {
    int lineHeight = myEditor.getLineHeight();
    Rectangle visibleArea = myEditor.getScrollingModel().getVisibleArea();
    final EditorGutterComponentEx gutter = myEditor.getGutterComponentEx();
    final EditorComponentImpl content = myEditor.getContentComponent();
    int updateWidth = myEditor.getScrollPane().getHorizontalScrollBar().getValue() + visibleArea.width;
    if (Math.abs(myCaretInfo.y - oldCaretInfo.y) <= 2 * lineHeight) {
        int minY = Math.min(oldCaretInfo.y, myCaretInfo.y);
        int maxY = Math.max(oldCaretInfo.y + oldCaretInfo.height, myCaretInfo.y + myCaretInfo.height);
        content.repaintEditorComponent(0, minY, updateWidth, maxY - minY);
        gutter.repaint(0, minY, gutter.getWidth(), maxY - minY);
    } else {
        content.repaintEditorComponent(0, oldCaretInfo.y, updateWidth, oldCaretInfo.height + lineHeight);
        gutter.repaint(0, oldCaretInfo.y, updateWidth, oldCaretInfo.height + lineHeight);
        content.repaintEditorComponent(0, myCaretInfo.y, updateWidth, myCaretInfo.height + lineHeight);
        gutter.repaint(0, myCaretInfo.y, updateWidth, myCaretInfo.height + lineHeight);
    }
}
Also used : EditorGutterComponentEx(com.intellij.openapi.editor.ex.EditorGutterComponentEx)

Example 13 with EditorGutterComponentEx

use of com.intellij.openapi.editor.ex.EditorGutterComponentEx in project intellij-plugins by JetBrains.

the class SplitFileEditor method createComponent.

@NotNull
private JComponent createComponent() {
    final JBSplitter splitter = new JBSplitter(false, 0.5f, 0.15f, 0.85f);
    splitter.setSplitterProportionKey(MY_PROPORTION_KEY);
    splitter.setFirstComponent(myMainEditor.getComponent());
    splitter.setSecondComponent(mySecondEditor.getComponent());
    myToolbarWrapper = new SplitEditorToolbar(splitter);
    if (myMainEditor instanceof TextEditor) {
        myToolbarWrapper.addGutterToTrack(((EditorGutterComponentEx) ((TextEditor) myMainEditor).getEditor().getGutter()));
    }
    if (mySecondEditor instanceof TextEditor) {
        myToolbarWrapper.addGutterToTrack(((EditorGutterComponentEx) ((TextEditor) mySecondEditor).getEditor().getGutter()));
    }
    final JPanel result = new JPanel(new BorderLayout());
    result.add(myToolbarWrapper, BorderLayout.NORTH);
    result.add(splitter, BorderLayout.CENTER);
    adjustEditorsVisibility();
    return result;
}
Also used : EditorGutterComponentEx(com.intellij.openapi.editor.ex.EditorGutterComponentEx) JBSplitter(com.intellij.ui.JBSplitter) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

EditorGutterComponentEx (com.intellij.openapi.editor.ex.EditorGutterComponentEx)13 EditorEx (com.intellij.openapi.editor.ex.EditorEx)6 NotNull (org.jetbrains.annotations.NotNull)4 Editor (com.intellij.openapi.editor.Editor)3 VcsRevisionNumber (com.intellij.openapi.vcs.history.VcsRevisionNumber)2 FileHyperlinkInfo (com.intellij.execution.filters.FileHyperlinkInfo)1 HyperlinkInfo (com.intellij.execution.filters.HyperlinkInfo)1 EditorHyperlinkSupport (com.intellij.execution.impl.EditorHyperlinkSupport)1 AllIcons (com.intellij.icons.AllIcons)1 Disposable (com.intellij.openapi.Disposable)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1 ColorKey (com.intellij.openapi.editor.colors.ColorKey)1 EditorFontType (com.intellij.openapi.editor.colors.EditorFontType)1 EditorMouseEventArea (com.intellij.openapi.editor.event.EditorMouseEventArea)1 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1