Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make "Text editor code mining color" configurable in preferences #2400

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,12 @@ private static class Decoration {
*/
private ReusableRegion fReusableRegion= new ReusableRegion();

/**
* Color used to draw inline annotations.
* @since 3.26
*/
private Color fInlineAnnotationColor;

/**
* Creates a new annotation painter for the given source viewer and with the
* given annotation access. The painter is not initialized, i.e. no
Expand Down Expand Up @@ -1647,4 +1653,18 @@ public void paint(int reason) {
@Override
public void setPositionManager(IPaintPositionManager manager) {
}

/**
* @since 3.26
*/
public void setInlineAnnotationColor(Color color) {
fInlineAnnotationColor= color;
}

/**
* @since 3.26
*/
public Color getInlineAnnotationColor() {
return fInlineAnnotationColor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,11 @@ public void install(ISourceViewer viewer, AnnotationPainter painter) {
visibleLines= new VisibleLines();
text.addMouseListener(fMouseTracker);
text.addMouseMoveListener(fMouseTracker);
setColor(text.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
Color c= painter.getInlineAnnotationColor();
if (c == null) {
c= text.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY);
}
setColor(c);
GC gc= new GC(viewer.getTextWidget());
gc.setFont(viewer.getTextWidget().getFont());
fFontMetrics= gc.getFontMetrics();
Expand Down
3 changes: 2 additions & 1 deletion bundles/org.eclipse.ui.editors/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ bin.includes = .,\
plugin.properties,\
about.html,\
icons/,\
META-INF/
META-INF/,\
css/

src.includes = about.html,\
schema/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

IEclipsePreferences#org-eclipse-ui-workbench:org-eclipse-ui-editors {
preferences:
'org.eclipse.ui.editors.inlineAnnotationColor=155,155,155'
}
4 changes: 4 additions & 0 deletions bundles/org.eclipse.ui.editors/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,7 @@ HyperlinkDetectorsPreferencePage= Hyperlinking

#--- Unused label ---
dummy=

#--- color definition for code mining annotations
TEXT_EDITOR_CODE_MINING_COLOR= Text editor code mining color
TEXT_EDITOR_CODE_MINING_COLOR_DESCRIPTION= The default color used for text editor code mining annotations.
19 changes: 19 additions & 0 deletions bundles/org.eclipse.ui.editors/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,16 @@
label="test"
value="232,232,232">
</colorDefinition>
<colorDefinition
categoryId="org.eclipse.ui.workbenchMisc"
id="org.eclipse.ui.editors.inlineAnnotationColor"
isEditable="true"
label="%TEXT_EDITOR_CODE_MINING_COLOR"
value="128,128,128">
<description>
%TEXT_EDITOR_CODE_MINING_COLOR_DESCRIPTION
</description>
</colorDefinition>

<theme
id="org.eclipse.ui.ide.systemDefault">
Expand Down Expand Up @@ -1161,4 +1171,13 @@
id="org.eclipse.ui.internal.editors.annotationCodeMiningProvider">
</codeMiningProvider>
</extension>
<extension
point="org.eclipse.e4.ui.css.swt.theme">
<stylesheet
uri="css/e4-dark_preferencestyle.css">
<themeid
refid="org.eclipse.e4.ui.css.theme.e4_dark">
</themeid>
</stylesheet>
</extension>
</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ public abstract class AbstractDecoratedTextEditor extends StatusTextEditor {
* Preference key for highlight color of current line.
*/
private final static String CURRENT_LINE_COLOR= AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR;
/**
* Preference key for inline annotation color
*/
private final static String INLINE_ANNOTATION_COLOR= AbstractDecoratedTextEditorPreferenceConstants.EDITOR_INLINE_ANNOTATION_COLOR;
/**
* Preference key for showing print margin ruler.
*/
Expand Down Expand Up @@ -456,6 +460,7 @@ protected void configureSourceViewerDecorationSupport(SourceViewerDecorationSupp

support.setCursorLinePainterPreferenceKeys(CURRENT_LINE, CURRENT_LINE_COLOR);
support.setMarginPainterPreferenceKeys(PRINT_MARGIN, PRINT_MARGIN_COLOR, PRINT_MARGIN_COLUMN);
support.setInlineAnnotationColorPreferenceKey(INLINE_ANNOTATION_COLOR);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,18 @@ private AbstractDecoratedTextEditorPreferenceConstants() {
*/
public final static String EDITOR_CURRENT_LINE_COLOR= "currentLineColor"; //$NON-NLS-1$

/**
* A named preference that holds the color used to render the text editor inline annotation
*
* @since 3.18
*/
public final static String EDITOR_INLINE_ANNOTATION_COLOR= "org.eclipse.ui.editors.inlineAnnotationColor"; //$NON-NLS-1$
tobiasmelcher marked this conversation as resolved.
Show resolved Hide resolved

/**
* A named preference that holds the number of spaces used per tab in the text editor.
* <p>
* Value is of type <code>int</code>: positive int value specifying the number of
* spaces per tab.
* Value is of type <code>int</code>: positive int value specifying the number of spaces per
* tab.
* </p>
*/
public final static String EDITOR_TAB_WIDTH= "tabWidth"; //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;

Expand All @@ -45,6 +47,7 @@
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.ISourceViewerExtension5;
import org.eclipse.jface.text.source.MatchingCharacterPainter;
import org.eclipse.jface.text.source.inlined.AbstractInlinedAnnotation;



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

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

if (fPreferenceStore != null) {
fPreferenceStore.removePropertyChangeListener(fPropertyChangeListener);
ColorRegistry registry = JFaceResources.getColorRegistry();
if (registry != null) {
registry.removeListener(fPropertyChangeListener);
}
fPropertyChangeListener= null;
fPreferenceStore= null;
}
Expand Down Expand Up @@ -438,6 +447,15 @@ public void setMarginPainterPreferenceKeys(String enableKey, String colorKey, St
fMarginPainterColumnKey= columnKey;
}

/**
* Set inline annotation color key.
*
* @since 3.18
*/
public void setInlineAnnotationColorPreferenceKey(String inlineAnnotationColor) {
tobiasmelcher marked this conversation as resolved.
Show resolved Hide resolved
fInlineAnnotationColorKey = inlineAnnotationColor;
}

/**
* Sets the preference keys for the matching character painter.
*
Expand Down Expand Up @@ -610,7 +628,15 @@ protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
return;
}
}

if (fInlineAnnotationColorKey!=null && fInlineAnnotationColorKey.equals(p) && fAnnotationPainter!=null) {
ColorRegistry registry = JFaceResources.getColorRegistry();
if (registry != null) {
Color color = registry.get(fInlineAnnotationColorKey);
fAnnotationPainter.setInlineAnnotationColor(color);
fAnnotationPainter.setAnnotationTypeColor(AbstractInlinedAnnotation.TYPE, color);
fAnnotationPainter.paint(IPainter.CONFIGURATION);
}
}
}

/**
Expand Down Expand Up @@ -863,6 +889,14 @@ protected AnnotationPainter createAnnotationPainter() {
painter.addTextStyleStrategy(AnnotationPreference.STYLE_DASHED_BOX, fgDashedBoxStrategy);
painter.addTextStyleStrategy(AnnotationPreference.STYLE_UNDERLINE, fgUnderlineStrategy);

ColorRegistry registry = JFaceResources.getColorRegistry();
if (registry != null) {
Color color = registry.get(fInlineAnnotationColorKey);
painter.setInlineAnnotationColor(color);
if (fPropertyChangeListener != null) {
registry.addListener(fPropertyChangeListener);
}
}
return painter;
}

Expand Down
Loading