Search in sources :

Example 1 with GutterMark

use of com.intellij.codeInsight.daemon.GutterMark in project intellij-community by JetBrains.

the class EditorGutterComponentImpl method processIconsRow.

private void processIconsRow(int line, @NotNull List<GutterMark> row, @NotNull LineGutterIconRendererProcessor processor) {
    int middleCount = 0;
    int middleSize = 0;
    int x = getIconAreaOffset() + 2;
    final int y = myEditor.logicalPositionToXY(new LogicalPosition(line, 0)).y;
    for (GutterMark r : row) {
        if (!checkDumbAware(r))
            continue;
        final GutterIconRenderer.Alignment alignment = ((GutterIconRenderer) r).getAlignment();
        final Icon icon = scaleIcon(r.getIcon());
        if (alignment == GutterIconRenderer.Alignment.LEFT) {
            processor.process(x, y + getTextAlignmentShift(icon), r);
            x += icon.getIconWidth() + GAP_BETWEEN_ICONS;
        } else if (alignment == GutterIconRenderer.Alignment.CENTER) {
            middleCount++;
            middleSize += icon.getIconWidth() + GAP_BETWEEN_ICONS;
        }
    }
    final int leftSize = x - getIconAreaOffset();
    x = getIconAreaOffset() + myIconsAreaWidth;
    for (GutterMark r : row) {
        if (!checkDumbAware(r))
            continue;
        if (((GutterIconRenderer) r).getAlignment() == GutterIconRenderer.Alignment.RIGHT) {
            Icon icon = scaleIcon(r.getIcon());
            x -= icon.getIconWidth();
            processor.process(x, y + getTextAlignmentShift(icon), r);
            x -= GAP_BETWEEN_ICONS;
        }
    }
    int rightSize = myIconsAreaWidth + getIconAreaOffset() - x + 1;
    if (middleCount > 0) {
        middleSize -= GAP_BETWEEN_ICONS;
        x = getIconAreaOffset() + leftSize + (myIconsAreaWidth - leftSize - rightSize - middleSize) / 2;
        for (GutterMark r : row) {
            if (!checkDumbAware(r))
                continue;
            if (((GutterIconRenderer) r).getAlignment() == GutterIconRenderer.Alignment.CENTER) {
                Icon icon = scaleIcon(r.getIcon());
                processor.process(x, y + getTextAlignmentShift(icon), r);
                x += icon.getIconWidth() + GAP_BETWEEN_ICONS;
            }
        }
    }
}
Also used : ScalableIcon(com.intellij.openapi.util.ScalableIcon) NonHideableIconGutterMark(com.intellij.codeInsight.daemon.NonHideableIconGutterMark) GutterMark(com.intellij.codeInsight.daemon.GutterMark) RelativePoint(com.intellij.ui.awt.RelativePoint) HintHint(com.intellij.ui.HintHint)

Example 2 with GutterMark

use of com.intellij.codeInsight.daemon.GutterMark in project intellij-community by JetBrains.

the class EditorGutterComponentImpl method buildGutterRenderersCache.

private void buildGutterRenderersCache() {
    myLineToGutterRenderers = new TIntObjectHashMap<>();
    processRangeHighlighters(0, myEditor.getDocument().getTextLength(), highlighter -> {
        GutterMark renderer = highlighter.getGutterIconRenderer();
        if (renderer == null) {
            return;
        }
        if (!areIconsShown() && !(renderer instanceof NonHideableIconGutterMark)) {
            return;
        }
        if (!isHighlighterVisible(highlighter)) {
            return;
        }
        int lineStartOffset = EditorUtil.getNotFoldedLineStartOffset(myEditor, highlighter.getStartOffset());
        int line = myEditor.getDocument().getLineNumber(lineStartOffset);
        List<GutterMark> renderers = myLineToGutterRenderers.get(line);
        if (renderers == null) {
            renderers = new SmartList<>();
            myLineToGutterRenderers.put(line, renderers);
        }
        renderers.add(renderer);
    });
    myLineToGutterRenderers.transformValues(value -> {
        List<GutterMark> newValue = value;
        for (GutterMarkPreprocessor preprocessor : GutterMarkPreprocessor.EP_NAME.getExtensions()) {
            newValue = preprocessor.processMarkers(value);
        }
        if (newValue.size() >= 5) {
            newValue = newValue.subList(0, 4);
        }
        return newValue;
    });
}
Also used : NonHideableIconGutterMark(com.intellij.codeInsight.daemon.NonHideableIconGutterMark) NonHideableIconGutterMark(com.intellij.codeInsight.daemon.NonHideableIconGutterMark) GutterMark(com.intellij.codeInsight.daemon.GutterMark) RelativePoint(com.intellij.ui.awt.RelativePoint) HintHint(com.intellij.ui.HintHint)

Example 3 with GutterMark

use of com.intellij.codeInsight.daemon.GutterMark in project intellij-community by JetBrains.

the class EditorGutterComponentImpl method mouseMoved.

@Override
public void mouseMoved(final MouseEvent e) {
    String toolTip = null;
    final GutterIconRenderer renderer = getGutterRenderer(e);
    TooltipController controller = TooltipController.getInstance();
    if (renderer != null) {
        toolTip = renderer.getTooltipText();
    } else {
        TextAnnotationGutterProvider provider = getProviderAtPoint(e.getPoint());
        if (provider != null) {
            final int line = getLineNumAtPoint(e.getPoint());
            toolTip = provider.getToolTip(line, myEditor);
            if (!Comparing.equal(toolTip, myLastGutterToolTip)) {
                controller.cancelTooltip(GUTTER_TOOLTIP_GROUP, e, true);
                myLastGutterToolTip = toolTip;
            }
        } else {
            ActiveGutterRenderer lineRenderer = getActiveRendererByMouseEvent(e);
            if (lineRenderer != null) {
                toolTip = lineRenderer.getTooltipText();
            }
        }
    }
    if (toolTip != null && !toolTip.isEmpty()) {
        final Ref<Point> t = new Ref<>(e.getPoint());
        int line = EditorUtil.yPositionToLogicalLine(myEditor, e);
        List<GutterMark> row = getGutterRenderers(line);
        Balloon.Position ballPosition = Balloon.Position.atRight;
        if (row != null) {
            final TreeMap<Integer, GutterMark> xPos = new TreeMap<>();
            final int[] currentPos = { 0 };
            processIconsRow(line, row, (x, y, r) -> {
                xPos.put(x, r);
                if (renderer == r) {
                    currentPos[0] = x;
                    Icon icon = scaleIcon(r.getIcon());
                    t.set(new Point(x + icon.getIconWidth() / 2, y + icon.getIconHeight() / 2));
                }
            });
            List<Integer> xx = new ArrayList<>(xPos.keySet());
            int posIndex = xx.indexOf(currentPos[0]);
            if (xPos.size() > 1 && posIndex == 0) {
                ballPosition = Balloon.Position.below;
            }
        }
        RelativePoint showPoint = new RelativePoint(this, t.get());
        controller.showTooltipByMouseMove(myEditor, showPoint, ((EditorMarkupModel) myEditor.getMarkupModel()).getErrorStripTooltipRendererProvider().calcTooltipRenderer(toolTip), false, GUTTER_TOOLTIP_GROUP, new HintHint(this, t.get()).setAwtTooltip(true).setPreferredPosition(ballPosition));
    } else {
        controller.cancelTooltip(GUTTER_TOOLTIP_GROUP, e, false);
    }
}
Also used : TIntArrayList(gnu.trove.TIntArrayList) Balloon(com.intellij.openapi.ui.popup.Balloon) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) NonHideableIconGutterMark(com.intellij.codeInsight.daemon.NonHideableIconGutterMark) GutterMark(com.intellij.codeInsight.daemon.GutterMark) RelativePoint(com.intellij.ui.awt.RelativePoint) HintHint(com.intellij.ui.HintHint) Ref(com.intellij.openapi.util.Ref) HintHint(com.intellij.ui.HintHint) TooltipController(com.intellij.codeInsight.hint.TooltipController) ScalableIcon(com.intellij.openapi.util.ScalableIcon)

Example 4 with GutterMark

use of com.intellij.codeInsight.daemon.GutterMark in project intellij-community by JetBrains.

the class UpdateHighlightersUtil method createOrReuseHighlighterFor.

private static void createOrReuseHighlighterFor(@NotNull final HighlightInfo info, // if null global scheme will be used
@Nullable final EditorColorsScheme colorsScheme, @NotNull final Document document, final int group, @NotNull final PsiFile psiFile, @NotNull MarkupModelEx markup, @Nullable HighlightersRecycler infosToRemove, @NotNull final Map<TextRange, RangeMarker> ranges2markersCache, @NotNull SeverityRegistrar severityRegistrar) {
    int infoStartOffset = info.startOffset;
    int infoEndOffset = info.endOffset;
    final int docLength = document.getTextLength();
    if (infoEndOffset > docLength) {
        infoEndOffset = docLength;
        infoStartOffset = Math.min(infoStartOffset, infoEndOffset);
    }
    if (infoEndOffset == infoStartOffset && !info.isAfterEndOfLine()) {
        // empty highlighter beyond file boundaries
        if (infoEndOffset == docLength)
            return;
        //show something in case of empty highlightinfo
        infoEndOffset++;
    }
    info.setGroup(group);
    int layer = getLayer(info, severityRegistrar);
    RangeHighlighterEx highlighter = infosToRemove == null ? null : (RangeHighlighterEx) infosToRemove.pickupHighlighterFromGarbageBin(info.startOffset, info.endOffset, layer);
    final TextRange finalInfoRange = new TextRange(infoStartOffset, infoEndOffset);
    final TextAttributes infoAttributes = info.getTextAttributes(psiFile, colorsScheme);
    Consumer<RangeHighlighterEx> changeAttributes = finalHighlighter -> {
        if (infoAttributes != null) {
            finalHighlighter.setTextAttributes(infoAttributes);
        }
        info.setHighlighter(finalHighlighter);
        finalHighlighter.setAfterEndOfLine(info.isAfterEndOfLine());
        Color color = info.getErrorStripeMarkColor(psiFile, colorsScheme);
        finalHighlighter.setErrorStripeMarkColor(color);
        if (info != finalHighlighter.getErrorStripeTooltip()) {
            finalHighlighter.setErrorStripeTooltip(info);
        }
        GutterMark renderer = info.getGutterIconRenderer();
        finalHighlighter.setGutterIconRenderer((GutterIconRenderer) renderer);
        ranges2markersCache.put(finalInfoRange, info.getHighlighter());
        if (info.quickFixActionRanges != null) {
            List<Pair<HighlightInfo.IntentionActionDescriptor, RangeMarker>> list = new ArrayList<>(info.quickFixActionRanges.size());
            for (Pair<HighlightInfo.IntentionActionDescriptor, TextRange> pair : info.quickFixActionRanges) {
                TextRange textRange = pair.second;
                RangeMarker marker = getOrCreate(document, ranges2markersCache, textRange);
                list.add(Pair.create(pair.first, marker));
            }
            info.quickFixActionMarkers = ContainerUtil.createLockFreeCopyOnWriteList(list);
        }
        ProperTextRange fixRange = info.getFixTextRange();
        if (finalInfoRange.equals(fixRange)) {
            info.fixMarker = null;
        } else {
            info.fixMarker = getOrCreate(document, ranges2markersCache, fixRange);
        }
    };
    if (highlighter == null) {
        highlighter = markup.addRangeHighlighterAndChangeAttributes(infoStartOffset, infoEndOffset, layer, null, HighlighterTargetArea.EXACT_RANGE, false, changeAttributes);
    } else {
        markup.changeAttributesInBatch(highlighter, changeAttributes);
    }
    boolean attributesSet = Comparing.equal(infoAttributes, highlighter.getTextAttributes());
    assert attributesSet : "Info: " + infoAttributes + "; colorsScheme: " + (colorsScheme == null ? "[global]" : colorsScheme.getName()) + "; highlighter:" + highlighter.getTextAttributes();
}
Also used : com.intellij.openapi.util(com.intellij.openapi.util) java.util(java.util) GutterMark(com.intellij.codeInsight.daemon.GutterMark) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) Document(com.intellij.openapi.editor.Document) THashSet(gnu.trove.THashSet) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) ContainerUtil(com.intellij.util.containers.ContainerUtil) THashMap(gnu.trove.THashMap) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) RangeMarker(com.intellij.openapi.editor.RangeMarker) RedBlackTree(com.intellij.openapi.editor.impl.RedBlackTree) com.intellij.openapi.editor.markup(com.intellij.openapi.editor.markup) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) Consumer(com.intellij.util.Consumer) RangeMarkerTree(com.intellij.openapi.editor.impl.RangeMarkerTree) RangeMarker(com.intellij.openapi.editor.RangeMarker) GutterMark(com.intellij.codeInsight.daemon.GutterMark) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) List(java.util.List)

Example 5 with GutterMark

use of com.intellij.codeInsight.daemon.GutterMark in project intellij-plugins by JetBrains.

the class DartServerOverrideMarkerProviderTest method checkGutter.

public static void checkGutter(final List<GutterMark> gutters, final String expectedText, final Icon expectedIcon) {
    final List<String> textList = Lists.newArrayList();
    for (GutterMark gutter : gutters) {
        final String text = gutter.getTooltipText();
        textList.add(text);
        if (expectedText.equals(text) && expectedIcon.equals(gutter.getIcon())) {
            return;
        }
    }
    fail("Not found gutter mark: " + expectedText + "  " + expectedIcon + "\nin\n" + StringUtil.join(textList, "\n"));
}
Also used : GutterMark(com.intellij.codeInsight.daemon.GutterMark)

Aggregations

GutterMark (com.intellij.codeInsight.daemon.GutterMark)24 NonHideableIconGutterMark (com.intellij.codeInsight.daemon.NonHideableIconGutterMark)6 HintHint (com.intellij.ui.HintHint)6 RelativePoint (com.intellij.ui.awt.RelativePoint)6 ScalableIcon (com.intellij.openapi.util.ScalableIcon)4 JSTestOptions (com.intellij.lang.javascript.JSTestOptions)3 Ref (com.intellij.openapi.util.Ref)3 LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)2 TooltipController (com.intellij.codeInsight.hint.TooltipController)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 Document (com.intellij.openapi.editor.Document)2 MarkupModelEx (com.intellij.openapi.editor.ex.MarkupModelEx)2 RangeHighlighterEx (com.intellij.openapi.editor.ex.RangeHighlighterEx)2 com.intellij.openapi.editor.markup (com.intellij.openapi.editor.markup)2 Project (com.intellij.openapi.project.Project)2 Balloon (com.intellij.openapi.ui.popup.Balloon)2 PsiElement (com.intellij.psi.PsiElement)2 ContainerUtil (com.intellij.util.containers.ContainerUtil)2 ColorIconCache (com.intellij.xml.util.ColorIconCache)2 NotNull (org.jetbrains.annotations.NotNull)2