Search in sources :

Example 6 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 7 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 8 with GutterMark

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

the class DescriptionTypeRelatedItemLineMarkerProviderTest method testInspectionDescription.

public void testInspectionDescription() {
    myFixture.copyDirectoryToProject("inspectionDescriptions", "inspectionDescriptions");
    final GutterMark gutter = myFixture.findGutter("MyWithDescriptionInspection.java");
    DevKitGutterTargetsChecker.checkGutterTargets(gutter, "Description", AllIcons.FileTypes.Html, "MyWithDescription.html");
}
Also used : GutterMark(com.intellij.codeInsight.daemon.GutterMark)

Example 9 with GutterMark

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

the class DevKitGutterTargetsChecker method checkGutterTargets.

public static void checkGutterTargets(final GutterMark gutterMark, final String tooltip, final Icon icon, final String... expectedTargets) {
    assertNotNull(gutterMark);
    assertEquals(tooltip, gutterMark.getTooltipText());
    assertEquals(icon, gutterMark.getIcon());
    final Collection<PsiElement> targetElements;
    if (gutterMark instanceof LineMarkerInfo.LineMarkerGutterIconRenderer) {
        final LineMarkerInfo.LineMarkerGutterIconRenderer renderer = UsefulTestCase.assertInstanceOf(gutterMark, LineMarkerInfo.LineMarkerGutterIconRenderer.class);
        final LineMarkerInfo lineMarkerInfo = renderer.getLineMarkerInfo();
        GutterIconNavigationHandler handler = lineMarkerInfo.getNavigationHandler();
        if (handler instanceof NavigationGutterIconRenderer) {
            targetElements = ((NavigationGutterIconRenderer) handler).getTargetElements();
        } else {
            throw new IllegalArgumentException(handler + ": handler not supported");
        }
    } else {
        throw new IllegalArgumentException(gutterMark.getClass() + ": gutter not supported");
    }
    UsefulTestCase.assertSameElements(ContainerUtil.map(targetElements, element -> SymbolPresentationUtil.getSymbolPresentableText(element)), expectedTargets);
}
Also used : GutterIconNavigationHandler(com.intellij.codeInsight.daemon.GutterIconNavigationHandler) GutterMark(com.intellij.codeInsight.daemon.GutterMark) Collection(java.util.Collection) ContainerUtil(com.intellij.util.containers.ContainerUtil) TestCase.assertNotNull(junit.framework.TestCase.assertNotNull) SymbolPresentationUtil(com.intellij.psi.presentation.java.SymbolPresentationUtil) Function(com.intellij.util.Function) GutterIconNavigationHandler(com.intellij.codeInsight.daemon.GutterIconNavigationHandler) PsiElement(com.intellij.psi.PsiElement) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) UsefulTestCase(com.intellij.testFramework.UsefulTestCase) NavigationGutterIconRenderer(com.intellij.codeInsight.navigation.NavigationGutterIconRenderer) javax.swing(javax.swing) TestCase.assertEquals(junit.framework.TestCase.assertEquals) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) NavigationGutterIconRenderer(com.intellij.codeInsight.navigation.NavigationGutterIconRenderer) PsiElement(com.intellij.psi.PsiElement)

Example 10 with GutterMark

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

the class ExtensionPointDeclarationRelatedItemLineMarkerProviderTest method assertSingleEPDeclaration.

private void assertSingleEPDeclaration(String filePath) {
    // index
    myFixture.configureByFile("plugin.xml");
    final GutterMark gutter = myFixture.findGutter(filePath);
    DevKitGutterTargetsChecker.checkGutterTargets(gutter, "Extension Point Declaration", AllIcons.Nodes.Plugin, "extensionPoint");
}
Also used : GutterMark(com.intellij.codeInsight.daemon.GutterMark)

Aggregations

GutterMark (com.intellij.codeInsight.daemon.GutterMark)23 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 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 ContainerUtil (com.intellij.util.containers.ContainerUtil)2 ColorIconCache (com.intellij.xml.util.ColorIconCache)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 GutterIconNavigationHandler (com.intellij.codeInsight.daemon.GutterIconNavigationHandler)1