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;
}
};
}
};
}
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());
}
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);
}
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);
}
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;
}
Aggregations