Search in sources :

Example 6 with GutterIconRenderer

use of com.intellij.openapi.editor.markup.GutterIconRenderer in project intellij-community by JetBrains.

the class RunLineMarkerProvider method getLineMarkerInfo.

@Nullable
@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element) {
    List<RunLineMarkerContributor> contributors = RunLineMarkerContributor.EXTENSION.allForLanguage(element.getLanguage());
    Icon icon = null;
    List<Info> infos = null;
    for (RunLineMarkerContributor contributor : contributors) {
        Info info = contributor.getInfo(element);
        if (info == null) {
            continue;
        }
        if (icon == null) {
            icon = info.icon;
        }
        if (infos == null) {
            infos = new SmartList<>();
        }
        infos.add(info);
    }
    if (icon == null)
        return null;
    if (infos.size() > 1) {
        Collections.sort(infos, COMPARATOR);
        final Info first = infos.get(0);
        for (Iterator<Info> it = infos.iterator(); it.hasNext(); ) {
            Info info = it.next();
            if (info != first && first.shouldReplace(info)) {
                it.remove();
            }
        }
    }
    final DefaultActionGroup actionGroup = new DefaultActionGroup();
    for (Info info : infos) {
        for (AnAction action : info.actions) {
            actionGroup.add(new LineMarkerActionWrapper(element, action));
        }
        if (info != infos.get(infos.size() - 1)) {
            actionGroup.add(new Separator());
        }
    }
    List<Info> finalInfos = infos;
    Function<PsiElement, String> tooltipProvider = element1 -> {
        final StringBuilder tooltip = new StringBuilder();
        for (Info info : finalInfos) {
            if (info.tooltipProvider != null) {
                String string = info.tooltipProvider.apply(element1);
                if (string == null)
                    continue;
                if (tooltip.length() != 0) {
                    tooltip.append("\n");
                }
                tooltip.append(string);
            }
        }
        return tooltip.length() == 0 ? null : tooltip.toString();
    };
    return new LineMarkerInfo<PsiElement>(element, element.getTextRange(), icon, Pass.LINE_MARKERS, tooltipProvider, null, GutterIconRenderer.Alignment.CENTER) {

        @Nullable
        @Override
        public GutterIconRenderer createGutterRenderer() {
            return new LineMarkerGutterIconRenderer<PsiElement>(this) {

                @Override
                public AnAction getClickAction() {
                    return null;
                }

                @Override
                public boolean isNavigateAction() {
                    return true;
                }

                @Nullable
                @Override
                public ActionGroup getPopupMenuActions() {
                    return actionGroup;
                }
            };
        }
    };
}
Also used : java.util(java.util) AllIcons(com.intellij.icons.AllIcons) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer) AnAction(com.intellij.openapi.actionSystem.AnAction) ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) Pass(com.intellij.codeHighlighting.Pass) LineMarkerProviderDescriptor(com.intellij.codeInsight.daemon.LineMarkerProviderDescriptor) Nullable(org.jetbrains.annotations.Nullable) SmartList(com.intellij.util.SmartList) Function(com.intellij.util.Function) PsiElement(com.intellij.psi.PsiElement) Info(com.intellij.execution.lineMarker.RunLineMarkerContributor.Info) NotNull(org.jetbrains.annotations.NotNull) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) Separator(com.intellij.openapi.actionSystem.Separator) javax.swing(javax.swing) Info(com.intellij.execution.lineMarker.RunLineMarkerContributor.Info) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) AnAction(com.intellij.openapi.actionSystem.AnAction) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) Separator(com.intellij.openapi.actionSystem.Separator) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with GutterIconRenderer

use of com.intellij.openapi.editor.markup.GutterIconRenderer in project intellij-community by JetBrains.

the class RunLineMarkerTest method testTestClassWithMain.

public void testTestClassWithMain() throws Exception {
    myFixture.addClass("package junit.framework; public class TestCase {}");
    myFixture.configureByText("MainTest.java", "public class <caret>MainTest extends junit.framework.TestCase {\n" + "    public static void main(String[] args) {\n" + "    }\n" + "    public void testFoo() {\n" + "    }\n" + "}");
    List<GutterMark> marks = myFixture.findGuttersAtCaret();
    assertEquals(1, marks.size());
    GutterIconRenderer mark = (GutterIconRenderer) marks.get(0);
    ActionGroup group = mark.getPopupMenuActions();
    assertNotNull(group);
    TestActionEvent event = new TestActionEvent();
    List<AnAction> list = ContainerUtil.findAll(group.getChildren(event), action -> {
        TestActionEvent actionEvent = new TestActionEvent();
        action.update(actionEvent);
        String text = actionEvent.getPresentation().getText();
        return text != null && text.startsWith("Run ") && text.endsWith("'");
    });
    assertEquals(list.toString(), 2, list.size());
    list.get(0).update(event);
    assertEquals("Run 'MainTest.main()'", event.getPresentation().getText());
    list.get(1).update(event);
    assertEquals("Run 'MainTest'", event.getPresentation().getText());
}
Also used : ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) GutterMark(com.intellij.codeInsight.daemon.GutterMark) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer) AnAction(com.intellij.openapi.actionSystem.AnAction) TestActionEvent(com.intellij.testFramework.TestActionEvent)

Example 8 with GutterIconRenderer

use of com.intellij.openapi.editor.markup.GutterIconRenderer in project android by JetBrains.

the class AndroidColorAnnotatorTest method checkAnnotationImage.

private void checkAnnotationImage(Annotation first, String basename) throws IOException {
    GutterIconRenderer renderer = first.getGutterIconRenderer();
    assertThat(renderer).isNotNull();
    Icon icon = renderer.getIcon();
    @SuppressWarnings("UndesirableClassUsage") BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = image.createGraphics();
    icon.paintIcon(null, graphics, 0, 0);
    graphics.dispose();
    File thumbnail = new File(getTestDataPath(), basename);
    BufferedImage baselineImage = ImageDiffUtil.convertToARGB(ImageIO.read(thumbnail));
    assertThat(baselineImage).isNotNull();
    // 5% difference allowed
    ImageDiffUtil.assertImageSimilar(getName(), baselineImage, image, 5.0);
}
Also used : ColorIcon(com.intellij.util.ui.ColorIcon) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) BufferedImage(java.awt.image.BufferedImage)

Example 9 with GutterIconRenderer

use of com.intellij.openapi.editor.markup.GutterIconRenderer in project intellij-community by JetBrains.

the class EditBreakpointActionHandler method perform.

@Override
public void perform(@NotNull Project project, AnActionEvent event) {
    DataContext dataContext = event.getDataContext();
    Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
    if (editor == null)
        return;
    final Pair<GutterIconRenderer, Object> pair = XBreakpointUtil.findSelectedBreakpoint(project, editor);
    Object breakpoint = pair.second;
    GutterIconRenderer breakpointGutterRenderer = pair.first;
    if (breakpointGutterRenderer == null)
        return;
    editBreakpoint(project, editor, breakpoint, breakpointGutterRenderer);
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) Editor(com.intellij.openapi.editor.Editor) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer)

Example 10 with GutterIconRenderer

use of com.intellij.openapi.editor.markup.GutterIconRenderer in project intellij-community by JetBrains.

the class XDebuggerEditBreakpointActionHandler method isEnabled.

@Override
public boolean isEnabled(@NotNull Project project, AnActionEvent event) {
    DataContext dataContext = event.getDataContext();
    Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
    if (editor == null)
        return false;
    final Pair<GutterIconRenderer, Object> pair = XBreakpointUtil.findSelectedBreakpoint(project, editor);
    return pair.first != null && pair.second instanceof XLineBreakpointImpl;
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) XLineBreakpointImpl(com.intellij.xdebugger.impl.breakpoints.XLineBreakpointImpl) Editor(com.intellij.openapi.editor.Editor) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer)

Aggregations

GutterIconRenderer (com.intellij.openapi.editor.markup.GutterIconRenderer)11 ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)3 AnAction (com.intellij.openapi.actionSystem.AnAction)3 PsiElement (com.intellij.psi.PsiElement)3 NotNull (org.jetbrains.annotations.NotNull)3 Pass (com.intellij.codeHighlighting.Pass)2 LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)2 AllIcons (com.intellij.icons.AllIcons)2 DataContext (com.intellij.openapi.actionSystem.DataContext)2 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)2 Document (com.intellij.openapi.editor.Document)2 Editor (com.intellij.openapi.editor.Editor)2 PsiFile (com.intellij.psi.PsiFile)2 ColorIcon (com.intellij.util.ui.ColorIcon)2 ArrayList (java.util.ArrayList)2 javax.swing (javax.swing)2 Nullable (org.jetbrains.annotations.Nullable)2 GutterMark (com.intellij.codeInsight.daemon.GutterMark)1 LineMarkerProvider (com.intellij.codeInsight.daemon.LineMarkerProvider)1 LineMarkerProviderDescriptor (com.intellij.codeInsight.daemon.LineMarkerProviderDescriptor)1