Skip to content

Commit 9bd3284

Browse files
tobias-melcherBeckerWdf
authored andcommitted
make "Text editor code mining color" configurable in preferences
introduce a new entry in preference page "General"->"Appearance"->"Colors and Fonts" so that code mining color can be configured by the end user Introduce a slightly brighter default color for code minings in the dark theme.
1 parent d6a50a4 commit 9bd3284

File tree

9 files changed

+107
-5
lines changed

9 files changed

+107
-5
lines changed

bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationPainter.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,12 @@ private static class Decoration {
444444
*/
445445
private ReusableRegion fReusableRegion= new ReusableRegion();
446446

447+
/**
448+
* Color used to draw inline annotations.
449+
* @since 3.26
450+
*/
451+
private Color fInlineAnnotationColor;
452+
447453
/**
448454
* Creates a new annotation painter for the given source viewer and with the
449455
* given annotation access. The painter is not initialized, i.e. no
@@ -1647,4 +1653,18 @@ public void paint(int reason) {
16471653
@Override
16481654
public void setPositionManager(IPaintPositionManager manager) {
16491655
}
1656+
1657+
/**
1658+
* @since 3.26
1659+
*/
1660+
public void setInlineAnnotationColor(Color color) {
1661+
fInlineAnnotationColor= color;
1662+
}
1663+
1664+
/**
1665+
* @since 3.26
1666+
*/
1667+
public Color getInlineAnnotationColor() {
1668+
return fInlineAnnotationColor;
1669+
}
16501670
}

bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationSupport.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,11 @@ public void install(ISourceViewer viewer, AnnotationPainter painter) {
366366
visibleLines= new VisibleLines();
367367
text.addMouseListener(fMouseTracker);
368368
text.addMouseMoveListener(fMouseTracker);
369-
setColor(text.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
369+
Color c= painter.getInlineAnnotationColor();
370+
if (c == null) {
371+
c= text.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY);
372+
}
373+
setColor(c);
370374
GC gc= new GC(viewer.getTextWidget());
371375
gc.setFont(viewer.getTextWidget().getFont());
372376
fFontMetrics= gc.getFontMetrics();

bundles/org.eclipse.ui.editors/build.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ bin.includes = .,\
1616
plugin.properties,\
1717
about.html,\
1818
icons/,\
19-
META-INF/
19+
META-INF/,\
20+
css/
2021

2122
src.includes = about.html,\
2223
schema/
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
IEclipsePreferences#org-eclipse-ui-workbench:org-eclipse-ui-editors {
3+
preferences:
4+
'org.eclipse.ui.editors.inlineAnnotationColor=155,155,155'
5+
}

bundles/org.eclipse.ui.editors/plugin.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,7 @@ HyperlinkDetectorsPreferencePage= Hyperlinking
151151

152152
#--- Unused label ---
153153
dummy=
154+
155+
#--- color definition for code mining annotations
156+
TEXT_EDITOR_CODE_MINING_COLOR= Text editor code mining color
157+
TEXT_EDITOR_CODE_MINING_COLOR_DESCRIPTION= The default color used for text editor code mining annotations.

bundles/org.eclipse.ui.editors/plugin.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,16 @@
11191119
label="test"
11201120
value="232,232,232">
11211121
</colorDefinition>
1122+
<colorDefinition
1123+
categoryId="org.eclipse.ui.workbenchMisc"
1124+
id="org.eclipse.ui.editors.inlineAnnotationColor"
1125+
isEditable="true"
1126+
label="%TEXT_EDITOR_CODE_MINING_COLOR"
1127+
value="128,128,128">
1128+
<description>
1129+
%TEXT_EDITOR_CODE_MINING_COLOR_DESCRIPTION
1130+
</description>
1131+
</colorDefinition>
11221132

11231133
<theme
11241134
id="org.eclipse.ui.ide.systemDefault">
@@ -1161,4 +1171,16 @@
11611171
id="org.eclipse.ui.internal.editors.annotationCodeMiningProvider">
11621172
</codeMiningProvider>
11631173
</extension>
1174+
<extension
1175+
point="org.eclipse.e4.ui.css.swt.theme">
1176+
<stylesheet
1177+
uri="css/e4-dark_preferencestyle.css">
1178+
<themeid
1179+
refid="org.eclipse.e4.ui.css.theme.e4_dark">
1180+
</themeid>
1181+
<themeid
1182+
refid="com.sap.adt.tools.core.ui.darkthemepoc">
1183+
</themeid>
1184+
</stylesheet>
1185+
</extension>
11641186
</plugin>

bundles/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ public abstract class AbstractDecoratedTextEditor extends StatusTextEditor {
196196
* Preference key for highlight color of current line.
197197
*/
198198
private final static String CURRENT_LINE_COLOR= AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR;
199+
/**
200+
* Preference key for inline annotation color
201+
*/
202+
private final static String INLINE_ANNOTATION_COLOR= AbstractDecoratedTextEditorPreferenceConstants.EDITOR_INLINE_ANNOTATION_COLOR;
199203
/**
200204
* Preference key for showing print margin ruler.
201205
*/
@@ -456,6 +460,7 @@ protected void configureSourceViewerDecorationSupport(SourceViewerDecorationSupp
456460

457461
support.setCursorLinePainterPreferenceKeys(CURRENT_LINE, CURRENT_LINE_COLOR);
458462
support.setMarginPainterPreferenceKeys(PRINT_MARGIN, PRINT_MARGIN_COLOR, PRINT_MARGIN_COLUMN);
463+
support.setInlineAnnotationColorPreferenceKey(INLINE_ANNOTATION_COLOR);
459464
}
460465

461466
/*

bundles/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditorPreferenceConstants.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,18 @@ private AbstractDecoratedTextEditorPreferenceConstants() {
7171
*/
7272
public final static String EDITOR_CURRENT_LINE_COLOR= "currentLineColor"; //$NON-NLS-1$
7373

74+
/**
75+
* A named preference that holds the color used to render the text editor inline annotation
76+
*
77+
* @since 3.18
78+
*/
79+
public final static String EDITOR_INLINE_ANNOTATION_COLOR= "org.eclipse.ui.editors.inlineAnnotationColor"; //$NON-NLS-1$
80+
7481
/**
7582
* A named preference that holds the number of spaces used per tab in the text editor.
7683
* <p>
77-
* Value is of type <code>int</code>: positive int value specifying the number of
78-
* spaces per tab.
84+
* Value is of type <code>int</code>: positive int value specifying the number of spaces per
85+
* tab.
7986
* </p>
8087
*/
8188
public final static String EDITOR_TAB_WIDTH= "tabWidth"; //$NON-NLS-1$

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/SourceViewerDecorationSupport.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
import org.eclipse.jface.preference.IPreferenceStore;
2828
import org.eclipse.jface.preference.PreferenceConverter;
29+
import org.eclipse.jface.resource.ColorRegistry;
30+
import org.eclipse.jface.resource.JFaceResources;
2931
import org.eclipse.jface.util.IPropertyChangeListener;
3032
import org.eclipse.jface.util.PropertyChangeEvent;
3133

@@ -45,6 +47,7 @@
4547
import org.eclipse.jface.text.source.ISourceViewer;
4648
import org.eclipse.jface.text.source.ISourceViewerExtension5;
4749
import org.eclipse.jface.text.source.MatchingCharacterPainter;
50+
import org.eclipse.jface.text.source.inlined.AbstractInlinedAnnotation;
4851

4952

5053

@@ -210,6 +213,8 @@ public void draw(Annotation annotation, GC gc, StyledText textWidget, int offset
210213
private MatchingCharacterPainter fMatchingCharacterPainter;
211214
/** The character painter's pair matcher */
212215
private ICharacterPairMatcher fCharacterPairMatcher;
216+
/** The inline annotation color key */
217+
private String fInlineAnnotationColorKey;
213218

214219
/** Map with annotation type preference per annotation type */
215220
private Map<Object, AnnotationPreference> fAnnotationTypeKeyMap= new LinkedHashMap<>();
@@ -357,6 +362,10 @@ public void uninstall() {
357362

358363
if (fPreferenceStore != null) {
359364
fPreferenceStore.removePropertyChangeListener(fPropertyChangeListener);
365+
ColorRegistry registry = JFaceResources.getColorRegistry();
366+
if (registry != null) {
367+
registry.removeListener(fPropertyChangeListener);
368+
}
360369
fPropertyChangeListener= null;
361370
fPreferenceStore= null;
362371
}
@@ -438,6 +447,15 @@ public void setMarginPainterPreferenceKeys(String enableKey, String colorKey, St
438447
fMarginPainterColumnKey= columnKey;
439448
}
440449

450+
/**
451+
* Set inline annotation color key.
452+
*
453+
* @since 3.18
454+
*/
455+
public void setInlineAnnotationColorPreferenceKey(String inlineAnnotationColor) {
456+
fInlineAnnotationColorKey = inlineAnnotationColor;
457+
}
458+
441459
/**
442460
* Sets the preference keys for the matching character painter.
443461
*
@@ -610,7 +628,15 @@ protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
610628
return;
611629
}
612630
}
613-
631+
if (fInlineAnnotationColorKey!=null && fInlineAnnotationColorKey.equals(p) && fAnnotationPainter!=null) {
632+
ColorRegistry registry = JFaceResources.getColorRegistry();
633+
if (registry != null) {
634+
Color color = registry.get(fInlineAnnotationColorKey);
635+
fAnnotationPainter.setInlineAnnotationColor(color);
636+
fAnnotationPainter.setAnnotationTypeColor(AbstractInlinedAnnotation.TYPE, color);
637+
fAnnotationPainter.paint(IPainter.CONFIGURATION);
638+
}
639+
}
614640
}
615641

616642
/**
@@ -863,6 +889,14 @@ protected AnnotationPainter createAnnotationPainter() {
863889
painter.addTextStyleStrategy(AnnotationPreference.STYLE_DASHED_BOX, fgDashedBoxStrategy);
864890
painter.addTextStyleStrategy(AnnotationPreference.STYLE_UNDERLINE, fgUnderlineStrategy);
865891

892+
ColorRegistry registry = JFaceResources.getColorRegistry();
893+
if (registry != null) {
894+
Color color = registry.get(fInlineAnnotationColorKey);
895+
painter.setInlineAnnotationColor(color);
896+
if (fPropertyChangeListener != null) {
897+
registry.addListener(fPropertyChangeListener);
898+
}
899+
}
866900
return painter;
867901
}
868902

0 commit comments

Comments
 (0)