Skip to content

Commit 8edb938

Browse files
Christoph Läubrichlaeubi
authored andcommitted
Add support for easily configure colors of gherking editor
1 parent ba96bf2 commit 8edb938

File tree

5 files changed

+41
-64
lines changed

5 files changed

+41
-64
lines changed

io.cucumber.eclipse.editor/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ Export-Package: io.cucumber.eclipse.editor,
4747
io.cucumber.eclipse.editor.hyperlinks,
4848
io.cucumber.eclipse.editor.launching,
4949
io.cucumber.eclipse.editor.marker,
50-
io.cucumber.eclipse.editor.steps
50+
io.cucumber.eclipse.editor.steps,
51+
io.cucumber.eclipse.editor.syntaxhighlight
5152
Import-Package: org.apache.commons.io;version="[2.16.0,3.0.0)",
5253
org.apache.commons.text.similarity;version="[1.14.0,2.0.0)",
5354
org.osgi.service.component.annotations;version="1.3.0"

io.cucumber.eclipse.editor/src/io/cucumber/eclipse/editor/syntaxhighlight/ColorManager.java

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
11
package io.cucumber.eclipse.editor.syntaxhighlight;
22

3+
import org.eclipse.jface.resource.ColorRegistry;
4+
import org.eclipse.swt.graphics.Color;
5+
import org.eclipse.swt.graphics.RGB;
6+
import org.eclipse.ui.PlatformUI;
37

48
public enum GherkinColors {
5-
COMMENT ("cucumber.eclipse.editor.presentation.gherkin_comment_colour"),
6-
KEYWORD ("cucumber.eclipse.editor.presentation.gherkin_keyword_colour"),
7-
PLACEHOLDER ("cucumber.eclipse.editor.presentation.gherkin_placeholder_colour"),
8-
STRING ("cucumber.eclipse.editor.presentation.gherkin_string_colour"),
9-
NUMERIC ("cucumber.eclipse.editor.presentation.gherkin_numeric_literal_colour"),
10-
STEP ("cucumber.eclipse.editor.presentation.gherkin_step_colour"),
11-
TAG ("cucumber.eclipse.editor.presentation.gherkin_tag_colour"),
12-
DEFAULT ("cucumber.eclipse.editor.presentation.gherkin_text_colour");
13-
14-
public final String COLOR_PREFERENCE_ID;
9+
COMMENT("cucumber.eclipse.editor.presentation.gherkin_comment_colour"),
10+
KEYWORD("cucumber.eclipse.editor.presentation.gherkin_keyword_colour"),
11+
PLACEHOLDER("cucumber.eclipse.editor.presentation.gherkin_placeholder_colour"),
12+
STRING("cucumber.eclipse.editor.presentation.gherkin_string_colour"),
13+
NUMERIC("cucumber.eclipse.editor.presentation.gherkin_numeric_literal_colour"),
14+
STEP("cucumber.eclipse.editor.presentation.gherkin_step_colour"),
15+
TAG("cucumber.eclipse.editor.presentation.gherkin_tag_colour"),
16+
DEFAULT("cucumber.eclipse.editor.presentation.gherkin_text_colour");
17+
18+
private final String id;
19+
1520
private GherkinColors(String id) {
16-
COLOR_PREFERENCE_ID = id;
21+
this.id = id;
1722
}
23+
24+
public void setColor(RGB rgb) {
25+
getColorRegistry().put(id, rgb);
26+
}
27+
28+
public Color getColor() {
29+
return getColorRegistry().get(id);
30+
}
31+
32+
private ColorRegistry getColorRegistry() {
33+
return PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
34+
}
35+
1836
}

io.cucumber.eclipse.editor/src/io/cucumber/eclipse/editor/syntaxhighlight/GherkinKeywordScanner.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,18 @@
1818

1919
public class GherkinKeywordScanner extends RuleBasedScanner {
2020

21-
private ColorManager manager;
22-
23-
public GherkinKeywordScanner(ColorManager manager) {
24-
this.manager = manager;
21+
public GherkinKeywordScanner() {
2522
}
2623

2724
public void configureRules(GherkinEditorDocument document) {
28-
IToken keyword= new Token(new TextAttribute(manager.getColor(GherkinColors.KEYWORD)));
29-
IToken step= new Token(new TextAttribute(manager.getColor(GherkinColors.STEP)));
30-
IToken tag= new Token(new TextAttribute(manager.getColor(GherkinColors.TAG)));
31-
IToken string= new Token(new TextAttribute(manager.getColor(GherkinColors.STRING)));
32-
IToken comment= new Token(new TextAttribute(manager.getColor(GherkinColors.COMMENT)));
33-
IToken other= new Token(new TextAttribute(manager.getColor(GherkinColors.DEFAULT)));
34-
IToken numeric= new Token(new TextAttribute(manager.getColor(GherkinColors.NUMERIC)));
35-
IToken placeholder= new Token(new TextAttribute(manager.getColor(GherkinColors.PLACEHOLDER)));
25+
IToken keyword = new Token(new TextAttribute(GherkinColors.KEYWORD.getColor()));
26+
IToken step = new Token(new TextAttribute(GherkinColors.STEP.getColor()));
27+
IToken tag = new Token(new TextAttribute(GherkinColors.TAG.getColor()));
28+
IToken string = new Token(new TextAttribute(GherkinColors.STRING.getColor()));
29+
IToken comment = new Token(new TextAttribute(GherkinColors.COMMENT.getColor()));
30+
IToken other = new Token(new TextAttribute(GherkinColors.DEFAULT.getColor()));
31+
IToken numeric = new Token(new TextAttribute(GherkinColors.NUMERIC.getColor()));
32+
IToken placeholder = new Token(new TextAttribute(GherkinColors.PLACEHOLDER.getColor()));
3633

3734

3835
List<IRule> rules= new ArrayList<IRule>();

io.cucumber.eclipse.editor/src/io/cucumber/eclipse/editor/syntaxhighlight/GherkinPresentationReconciler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
public class GherkinPresentationReconciler extends PresentationReconciler implements IPresentationReconciler {
1515

1616
public GherkinPresentationReconciler() {
17-
DefaultDamagerRepairer dr = new GherkinDamagerRepairer(new GherkinKeywordScanner(new ColorManager()));
17+
DefaultDamagerRepairer dr = new GherkinDamagerRepairer(new GherkinKeywordScanner());
1818
this.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
1919
this.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
2020
}

0 commit comments

Comments
 (0)