From b950589b471370ea2d353505192c3ee3f71e686e Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Thu, 21 Nov 2019 15:43:06 +0300 Subject: [PATCH] vcs: add API to customize presentation of annotation column GitOrigin-RevId: f59dc4d53c6cd7ba3f6cee423c7ad4b5c5fe9e07 --- .../vcs/annotate/LineAnnotationAspect.java | 28 +++++++++++++++++ .../actions/AspectAnnotationFieldGutter.java | 30 +++++++++++++++++-- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/annotate/LineAnnotationAspect.java b/platform/vcs-api/src/com/intellij/openapi/vcs/annotate/LineAnnotationAspect.java index 6afc4ff1c185..72d8dca85002 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/annotate/LineAnnotationAspect.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/annotate/LineAnnotationAspect.java @@ -15,9 +15,13 @@ */ package com.intellij.openapi.vcs.annotate; +import com.intellij.openapi.editor.colors.ColorKey; +import com.intellij.openapi.editor.colors.EditorFontType; import com.intellij.openapi.vcs.VcsBundle; import org.jetbrains.annotations.Nullable; +import java.awt.*; + /** * Represents one part of a line annotation which is shown in the editor when the "Annotate" * action is invoked. Classes implementing this interface can also implement @@ -62,4 +66,28 @@ public interface LineAnnotationAspect { * @return {@code true} if this aspect will be shown on Annotate action */ boolean isShowByDefault(); + + /** + * Used to override default text style + */ + @Nullable + default EditorFontType getStyle(int line) { + return null; + } + + /** + * Used to override default text color + */ + @Nullable + default ColorKey getColor(int line) { + return null; + } + + /** + * Used to override default background color + */ + @Nullable + default Color getBgColor(int line) { + return null; + } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AspectAnnotationFieldGutter.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AspectAnnotationFieldGutter.java index 7cddf4167ab0..d56abe4cc707 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AspectAnnotationFieldGutter.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AspectAnnotationFieldGutter.java @@ -17,6 +17,8 @@ package com.intellij.openapi.vcs.actions; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorGutterAction; +import com.intellij.openapi.editor.colors.ColorKey; +import com.intellij.openapi.editor.colors.EditorFontType; import com.intellij.openapi.util.Couple; import com.intellij.openapi.vcs.annotate.FileAnnotation; import com.intellij.openapi.vcs.annotate.LineAnnotationAspect; @@ -62,9 +64,8 @@ public class AspectAnnotationFieldGutter extends AnnotationFieldGutter { @Nullable @Override public String getToolTip(final int line, final Editor editor) { - if (myAspect.getTooltipText(line) != null) { - return myAspect.getTooltipText(line); - } + String text = myAspect.getTooltipText(line); + if (text != null) return text; return isAvailable() ? myAnnotation.getHtmlToolTip(line) : null; } @@ -83,6 +84,29 @@ public class AspectAnnotationFieldGutter extends AnnotationFieldGutter { return super.getCursor(line); } + @Override + public EditorFontType getStyle(int line, Editor editor) { + EditorFontType style = myAspect.getStyle(line); + if (style != null) return style; + return super.getStyle(line, editor); + } + + @Nullable + @Override + public ColorKey getColor(int line, Editor editor) { + ColorKey color = myAspect.getColor(line); + if (color != null) return color; + return super.getColor(line, editor); + } + + @Nullable + @Override + public Color getBgColor(int line, Editor editor) { + Color color = myAspect.getBgColor(line); + if (color != null) return color; + return super.getBgColor(line, editor); + } + @Override public boolean isShowByDefault() { return myAspect.isShowByDefault();