Skip to content

Commit 222a82a

Browse files
committed
#39 Jade Editor color preferences
1 parent cfeaa7d commit 222a82a

File tree

6 files changed

+137
-12
lines changed

6 files changed

+137
-12
lines changed

org.nodeclipse.enide.editors.jade/plugin.xml

+17
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,21 @@
1212
name="Minimalist Jade Editor">
1313
</editor>
1414
</extension>
15+
16+
<extension
17+
point="org.eclipse.core.runtime.preferences">
18+
<initializer
19+
class="org.nodeclipse.enide.editors.jade.preferences.JadePreferenceInitializer">
20+
</initializer>
21+
</extension>
22+
<extension
23+
point="org.eclipse.ui.preferencePages">
24+
<page
25+
category="org.nodeclipse.ui.preferences.NodePreferencePage"
26+
class="org.nodeclipse.enide.editors.jade.preferences.JadePreferencePage"
27+
id="org.nodeclipse.enide.editors.jade.preferences.JadePreferencePage"
28+
name="Jade Editor">
29+
</page>
30+
</extension>
31+
1532
</plugin>
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
package org.nodeclipse.enide.editors.jade;
22

3+
import org.eclipse.swt.graphics.RGB;
4+
35
public class JadeEditorConstants {
46

57
public static final String PLUGIN_ID = "org.nodeclipse.enide.editors.jade";
68

9+
public static final String KEY_COLOR_COMMENT = "color_comment";
10+
public static final String KEY_COLOR_DOC = "color_doc";
11+
public static final String KEY_COLOR_KEYWORD = "color_keyword";
12+
public static final String KEY_COLOR_STRING = "color_string";
13+
public static final String KEY_COLOR_NUMBER = "color_number";
14+
public static final String KEY_COLOR_NORMAL = "color_normal";
15+
16+
public static final String KEY_BOLD_KEYWORD = "bold_keyword";
17+
18+
public static final RGB DEFAULT_COLOR_COMMENT = new RGB(63, 127, 95);
19+
public static final RGB DEFAULT_COLOR_DOC = new RGB(127, 127, 159);
20+
public static final RGB DEFAULT_COLOR_KEYWORD = new RGB(127, 0, 85);
21+
public static final RGB DEFAULT_COLOR_STRING = new RGB(42, 0, 255);
22+
public static final RGB DEFAULT_COLOR_NUMBER = new RGB(0, 0, 0);
23+
public static final RGB DEFAULT_COLOR_NORMAL = new RGB(0, 0, 0);
24+
725
}

org.nodeclipse.enide.editors.jade/src/org/nodeclipse/enide/editors/jade/highlight/EditorColors.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
2-
// Use of this source code is governed by a BSD-style license that can be
3-
// found in the LICENSE file.
4-
51
package org.nodeclipse.enide.editors.jade.highlight;
62

73
import java.util.HashMap;
84
import java.util.Map;
95

6+
import org.eclipse.jface.preference.PreferenceConverter;
107
import org.eclipse.swt.graphics.Color;
118
import org.eclipse.swt.graphics.RGB;
129
import org.eclipse.swt.widgets.Display;
10+
import org.nodeclipse.enide.editors.jade.Activator;
1311

1412
/**
1513
* Converts RGB to Color, reuses the existing Color instances. A singleton.
@@ -28,6 +26,10 @@ public static Color getColor(RGB rgb) {
2826
return color;
2927
}
3028

29+
public static Color getColor(String preference) {
30+
return getColor(PreferenceConverter.getColor(Activator.getDefault().getPreferenceStore(), preference));
31+
}
32+
3133
private static Integer rgbToInteger(RGB rgb) {
3234
return ((rgb.red & 0xFF) << 16) + ((rgb.green & 0xFF) << 8) + (rgb.blue & 0xFF);
3335
}

org.nodeclipse.enide.editors.jade/src/org/nodeclipse/enide/editors/jade/highlight/JadeCodeScanner.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@
1313
import org.eclipse.jface.text.rules.WhitespaceRule;
1414
import org.eclipse.jface.text.rules.WordRule;
1515
import org.eclipse.swt.SWT;
16-
import org.eclipse.swt.graphics.RGB;
16+
import org.nodeclipse.enide.editors.jade.Activator;
17+
import org.nodeclipse.enide.editors.jade.JadeEditorConstants;
1718

1819
/**
1920
* JavaScript code scanner for source code highlighting.
2021
*/
2122
public class JadeCodeScanner extends RuleBasedScanner {
2223

23-
// TODO Preferences
24-
private TextAttribute commentAttribute = new TextAttribute(EditorColors.getColor(new RGB(63, 127, 95)), null, SWT.NORMAL);
25-
private TextAttribute docAttribute = new TextAttribute(EditorColors.getColor(new RGB(127, 127, 159)), null, SWT.NORMAL);
26-
private TextAttribute keywordAttribute = new TextAttribute(EditorColors.getColor(new RGB(127, 0, 85)), null, SWT.BOLD);
27-
private TextAttribute stringAttribute = new TextAttribute(EditorColors.getColor(new RGB(42, 0, 255)), null, SWT.NORMAL);
28-
private TextAttribute numberAttribute = new TextAttribute(EditorColors.getColor(new RGB(0, 0, 0)), null, SWT.NORMAL);
29-
private TextAttribute normalAttribute = new TextAttribute(EditorColors.getColor(new RGB(0, 0, 0)), null, SWT.NORMAL);
24+
private TextAttribute commentAttribute = new TextAttribute(EditorColors.getColor(JadeEditorConstants.KEY_COLOR_COMMENT), null, SWT.NORMAL);
25+
private TextAttribute docAttribute = new TextAttribute(EditorColors.getColor(JadeEditorConstants.KEY_COLOR_DOC), null, SWT.NORMAL);
26+
private TextAttribute keywordAttribute = new TextAttribute(EditorColors.getColor(JadeEditorConstants.KEY_COLOR_KEYWORD), null,
27+
Activator.getDefault().getPreferenceStore().getBoolean(JadeEditorConstants.KEY_BOLD_KEYWORD) ? SWT.BOLD : SWT.NORMAL);
28+
private TextAttribute stringAttribute = new TextAttribute(EditorColors.getColor(JadeEditorConstants.KEY_COLOR_STRING), null, SWT.NORMAL);
29+
private TextAttribute numberAttribute = new TextAttribute(EditorColors.getColor(JadeEditorConstants.KEY_COLOR_NUMBER), null, SWT.NORMAL);
30+
private TextAttribute normalAttribute = new TextAttribute(EditorColors.getColor(JadeEditorConstants.KEY_COLOR_NORMAL), null, SWT.NORMAL);
3031

3132
public JadeCodeScanner() {
3233
createRules();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.nodeclipse.enide.editors.jade.preferences;
2+
3+
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
4+
import org.eclipse.jface.preference.IPreferenceStore;
5+
import org.eclipse.jface.preference.PreferenceConverter;
6+
import org.nodeclipse.enide.editors.jade.Activator;
7+
import org.nodeclipse.enide.editors.jade.JadeEditorConstants;
8+
9+
public class JadePreferenceInitializer extends AbstractPreferenceInitializer {
10+
11+
@Override
12+
public void initializeDefaultPreferences() {
13+
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
14+
PreferenceConverter.setDefault(store, JadeEditorConstants.KEY_COLOR_COMMENT, JadeEditorConstants.DEFAULT_COLOR_COMMENT);
15+
PreferenceConverter.setDefault(store, JadeEditorConstants.KEY_COLOR_DOC, JadeEditorConstants.DEFAULT_COLOR_DOC);
16+
PreferenceConverter.setDefault(store, JadeEditorConstants.KEY_COLOR_KEYWORD, JadeEditorConstants.DEFAULT_COLOR_KEYWORD);
17+
PreferenceConverter.setDefault(store, JadeEditorConstants.KEY_COLOR_STRING, JadeEditorConstants.DEFAULT_COLOR_STRING);
18+
PreferenceConverter.setDefault(store, JadeEditorConstants.KEY_COLOR_NUMBER, JadeEditorConstants.DEFAULT_COLOR_NUMBER);
19+
PreferenceConverter.setDefault(store, JadeEditorConstants.KEY_COLOR_NORMAL, JadeEditorConstants.DEFAULT_COLOR_NORMAL);
20+
store.setDefault(JadeEditorConstants.KEY_BOLD_KEYWORD, true);
21+
}
22+
23+
}
24+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package org.nodeclipse.enide.editors.jade.preferences;
2+
3+
import org.eclipse.jface.preference.BooleanFieldEditor;
4+
import org.eclipse.jface.preference.ColorFieldEditor;
5+
import org.eclipse.jface.preference.FieldEditorPreferencePage;
6+
import org.eclipse.jface.preference.IPreferenceStore;
7+
import org.eclipse.swt.widgets.Composite;
8+
import org.eclipse.ui.IWorkbench;
9+
import org.eclipse.ui.IWorkbenchPreferencePage;
10+
import org.nodeclipse.enide.editors.jade.Activator;
11+
import org.nodeclipse.enide.editors.jade.JadeEditorConstants;
12+
13+
/**
14+
* @author Paul Verest
15+
* @since 0.11 moved from NodePreferencePage
16+
*/
17+
public class JadePreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
18+
19+
private ColorFieldEditor colorComment;
20+
private ColorFieldEditor colorDoc;
21+
private ColorFieldEditor colorKeyword;
22+
private ColorFieldEditor colorString;
23+
private ColorFieldEditor colorNumber;
24+
private ColorFieldEditor colorNormal;
25+
private BooleanFieldEditor boldAttributeKeyword;
26+
27+
public JadePreferencePage() {
28+
super(GRID);
29+
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
30+
setPreferenceStore(store);
31+
setDescription("Jade Editor Settings");
32+
}
33+
@Override
34+
public void init(IWorkbench workbench) {
35+
}
36+
37+
@Override
38+
protected void createFieldEditors() {
39+
40+
Composite parent = getFieldEditorParent();
41+
42+
colorComment = new ColorFieldEditor(JadeEditorConstants.KEY_COLOR_COMMENT, "Comment color:", parent);
43+
addField(colorComment);
44+
45+
colorDoc = new ColorFieldEditor(JadeEditorConstants.KEY_COLOR_DOC, "Doc color:", parent);
46+
addField(colorDoc);
47+
48+
colorKeyword = new ColorFieldEditor(JadeEditorConstants.KEY_COLOR_KEYWORD, "Keyword color:", parent);
49+
addField(colorKeyword);
50+
51+
boldAttributeKeyword = new BooleanFieldEditor(JadeEditorConstants.KEY_BOLD_KEYWORD, "Bold keywords", parent);
52+
addField(boldAttributeKeyword);
53+
54+
colorString = new ColorFieldEditor(JadeEditorConstants.KEY_COLOR_STRING, "String color:", parent);
55+
addField(colorString);
56+
57+
colorNumber = new ColorFieldEditor(JadeEditorConstants.KEY_COLOR_NUMBER, "Number color:", parent);
58+
addField(colorNumber);
59+
60+
colorNormal = new ColorFieldEditor(JadeEditorConstants.KEY_COLOR_NORMAL, "Normal text color:", parent);
61+
addField(colorNormal);
62+
}
63+
}

0 commit comments

Comments
 (0)