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