diff --git a/org.nodeclipse.debug/src/org/nodeclipse/debug/launch/LaunchConfigurationDelegate.java b/org.nodeclipse.debug/src/org/nodeclipse/debug/launch/LaunchConfigurationDelegate.java index 7d6fc133..eb94e931 100644 --- a/org.nodeclipse.debug/src/org/nodeclipse/debug/launch/LaunchConfigurationDelegate.java +++ b/org.nodeclipse.debug/src/org/nodeclipse/debug/launch/LaunchConfigurationDelegate.java @@ -50,7 +50,7 @@ public void launch(ILaunchConfiguration configuration, String mode, // Using configuration to build command line - String nodePath = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.NODE_PATH); + String nodePath = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.KEY_NODE_PATH); // Check if the node location is correctly configured File nodeFile = new File(nodePath); diff --git a/org.nodeclipse.ui/src/org/nodeclipse/ui/highlight/EditorColors.java b/org.nodeclipse.ui/src/org/nodeclipse/ui/highlight/EditorColors.java index 49c01b2d..0e86373f 100644 --- a/org.nodeclipse.ui/src/org/nodeclipse/ui/highlight/EditorColors.java +++ b/org.nodeclipse.ui/src/org/nodeclipse/ui/highlight/EditorColors.java @@ -7,9 +7,11 @@ import java.util.HashMap; import java.util.Map; +import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Display; +import org.nodeclipse.ui.Activator; /** * Converts RGB to Color, reuses the existing Color instances. A singleton. @@ -28,6 +30,10 @@ public static Color getColor(RGB rgb) { return color; } + public static Color getColor(String preference) { + return getColor(PreferenceConverter.getColor(Activator.getDefault().getPreferenceStore(), preference)); + } + private static Integer rgbToInteger(RGB rgb) { return ((rgb.red & 0xFF) << 16) + ((rgb.green & 0xFF) << 8) + (rgb.blue & 0xFF); } diff --git a/org.nodeclipse.ui/src/org/nodeclipse/ui/highlight/NodeCodeScanner.java b/org.nodeclipse.ui/src/org/nodeclipse/ui/highlight/NodeCodeScanner.java index 5f923d5c..8f472b7f 100644 --- a/org.nodeclipse.ui/src/org/nodeclipse/ui/highlight/NodeCodeScanner.java +++ b/org.nodeclipse.ui/src/org/nodeclipse/ui/highlight/NodeCodeScanner.java @@ -13,20 +13,20 @@ import org.eclipse.jface.text.rules.WhitespaceRule; import org.eclipse.jface.text.rules.WordRule; import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.RGB; +import org.nodeclipse.ui.Activator; +import org.nodeclipse.ui.preferences.PreferenceConstants; /** * JavaScript code scanner for source code highlighting. */ public class NodeCodeScanner extends RuleBasedScanner { - // TODO Preferences - private TextAttribute commentAttribute = new TextAttribute(EditorColors.getColor(new RGB(63, 127, 95)), null, SWT.NORMAL); - private TextAttribute docAttribute = new TextAttribute(EditorColors.getColor(new RGB(127, 127, 159)), null, SWT.NORMAL); - private TextAttribute keywordAttribute = new TextAttribute(EditorColors.getColor(new RGB(127, 0, 85)), null, SWT.BOLD); - private TextAttribute stringAttribute = new TextAttribute(EditorColors.getColor(new RGB(42, 0, 255)), null, SWT.NORMAL); - private TextAttribute numberAttribute = new TextAttribute(EditorColors.getColor(new RGB(0, 0, 0)), null, SWT.NORMAL); - private TextAttribute normalAttribute = new TextAttribute(EditorColors.getColor(new RGB(0, 0, 0)), null, SWT.NORMAL); + private TextAttribute commentAttribute = new TextAttribute(EditorColors.getColor(PreferenceConstants.KEY_COLOR_COMMENT), null, SWT.NORMAL); + private TextAttribute docAttribute = new TextAttribute(EditorColors.getColor(PreferenceConstants.KEY_COLOR_DOC), null, SWT.NORMAL); + private TextAttribute keywordAttribute = new TextAttribute(EditorColors.getColor(PreferenceConstants.KEY_COLOR_KEYWORD), null, Activator.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.KEY_BOLD_KEYWORD) ? SWT.BOLD : SWT.NORMAL); + private TextAttribute stringAttribute = new TextAttribute(EditorColors.getColor(PreferenceConstants.KEY_COLOR_STRING), null, SWT.NORMAL); + private TextAttribute numberAttribute = new TextAttribute(EditorColors.getColor(PreferenceConstants.KEY_COLOR_NUMBER), null, SWT.NORMAL); + private TextAttribute normalAttribute = new TextAttribute(EditorColors.getColor(PreferenceConstants.KEY_COLOR_NORMAL), null, SWT.NORMAL); public NodeCodeScanner() { createRules(); diff --git a/org.nodeclipse.ui/src/org/nodeclipse/ui/npm/LaunchConfigurationDelegate.java b/org.nodeclipse.ui/src/org/nodeclipse/ui/npm/LaunchConfigurationDelegate.java index d7b95b85..0ff5b911 100644 --- a/org.nodeclipse.ui/src/org/nodeclipse/ui/npm/LaunchConfigurationDelegate.java +++ b/org.nodeclipse.ui/src/org/nodeclipse/ui/npm/LaunchConfigurationDelegate.java @@ -31,7 +31,7 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun // Using configuration to build command line List cmdLine = new ArrayList(); // Application path should be stored in preference. - String nodePath = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.NODE_PATH); + String nodePath = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.KEY_NODE_PATH); String npmPath = nodePath.substring(0, nodePath.lastIndexOf(File.separator) + 1); if (OSUtils.isWindows()) { cmdLine.add(npmPath + Constants.NPM_CMD); diff --git a/org.nodeclipse.ui/src/org/nodeclipse/ui/preferences/NodePreferencePage.java b/org.nodeclipse.ui/src/org/nodeclipse/ui/preferences/NodePreferencePage.java index 048f7428..93372781 100644 --- a/org.nodeclipse.ui/src/org/nodeclipse/ui/preferences/NodePreferencePage.java +++ b/org.nodeclipse.ui/src/org/nodeclipse/ui/preferences/NodePreferencePage.java @@ -1,7 +1,11 @@ package org.nodeclipse.ui.preferences; +import org.eclipse.jface.preference.BooleanFieldEditor; +import org.eclipse.jface.preference.ColorFieldEditor; import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.jface.preference.FileFieldEditor; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.nodeclipse.ui.Activator; @@ -15,10 +19,18 @@ public class NodePreferencePage extends FieldEditorPreferencePage implements IWo private FileFieldEditor fileFieldEditor; private FileFieldEditor expressPath; private FileFieldEditor completionsPath; + private ColorFieldEditor colorComment; + private ColorFieldEditor colorDoc; + private ColorFieldEditor colorKeyword; + private ColorFieldEditor colorString; + private ColorFieldEditor colorNumber; + private ColorFieldEditor colorNormal; + private BooleanFieldEditor boldAttributeKeyword; public NodePreferencePage() { super(GRID); - setPreferenceStore(Activator.getDefault().getPreferenceStore()); + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + setPreferenceStore(store); setDescription("Node Settings"); } @@ -29,14 +41,46 @@ public void init(IWorkbench workbench) { @Override protected void createFieldEditors() { - fileFieldEditor = new FileFieldEditor(PreferenceConstants.NODE_PATH, "Node Path:", getFieldEditorParent()); + Composite parent = getFieldEditorParent(); + + fileFieldEditor = new FileFieldEditor(PreferenceConstants.KEY_NODE_PATH, "Node Path:", parent); addField(fileFieldEditor); - expressPath = new FileFieldEditor(PreferenceConstants.EXPRESS_PATH, "Express Path:", getFieldEditorParent()); + expressPath = new FileFieldEditor(PreferenceConstants.KEY_EXPRESS_PATH, "Express Path:", parent); addField(expressPath); - completionsPath = new FileFieldEditor(PreferenceConstants.COMPLETIONS_JSON_PATH, "Completions.json Path:", getFieldEditorParent()); + completionsPath = new FileFieldEditor(PreferenceConstants.KEY_COMPLETIONS_JSON_PATH, "Completions.json Path:", parent); addField(completionsPath); + + colorComment = new ColorFieldEditor(PreferenceConstants.KEY_COLOR_COMMENT, "Comment color:", parent); + addField(colorComment); + + colorDoc = new ColorFieldEditor(PreferenceConstants.KEY_COLOR_DOC, "Doc color:", parent); + addField(colorDoc); + + colorKeyword = new ColorFieldEditor(PreferenceConstants.KEY_COLOR_KEYWORD, "Keyword color:", parent); + addField(colorKeyword); + + boldAttributeKeyword = new BooleanFieldEditor(PreferenceConstants.KEY_BOLD_KEYWORD, "Bold keywords", parent); + addField(boldAttributeKeyword); + + colorString = new ColorFieldEditor(PreferenceConstants.KEY_COLOR_STRING, "String color:", parent); + addField(colorString); + + colorNumber = new ColorFieldEditor(PreferenceConstants.KEY_COLOR_NUMBER, "Number color:", parent); + addField(colorNumber); + + colorNormal = new ColorFieldEditor(PreferenceConstants.KEY_COLOR_NORMAL, "Normal text color:", parent); + addField(colorNormal); + } + + public boolean performOk() { + boolean result = super.performOk(); + if(result) { + + } + + return result; } @Override diff --git a/org.nodeclipse.ui/src/org/nodeclipse/ui/preferences/PreferenceConstants.java b/org.nodeclipse.ui/src/org/nodeclipse/ui/preferences/PreferenceConstants.java index 4f9aa28f..14fb9420 100644 --- a/org.nodeclipse.ui/src/org/nodeclipse/ui/preferences/PreferenceConstants.java +++ b/org.nodeclipse.ui/src/org/nodeclipse/ui/preferences/PreferenceConstants.java @@ -1,5 +1,7 @@ package org.nodeclipse.ui.preferences; +import org.eclipse.swt.graphics.RGB; + /** * Constant definitions for plug-in preferences * @@ -8,11 +10,26 @@ */ public class PreferenceConstants { - public static final String NODE_PATH = "node_path"; - public static final String EXPRESS_PATH = "express_pass"; - public static final String EXPRESS_VERSION = "express_version"; - public static final String COMPLETIONS_JSON_PATH = "completionsjson_path"; public static final String PREFERENCES_PAGE = "org.nodeclipse.ui.preferences.NodePreferencePage"; - - + + public static final String KEY_NODE_PATH = "node_path"; + public static final String KEY_EXPRESS_PATH = "express_pass"; + public static final String KEY_EXPRESS_VERSION = "express_version"; + public static final String KEY_COMPLETIONS_JSON_PATH = "completionsjson_path"; + + public static final String KEY_COLOR_COMMENT = "color_comment"; + public static final String KEY_COLOR_DOC = "color_doc"; + public static final String KEY_COLOR_KEYWORD = "color_keyword"; + public static final String KEY_COLOR_STRING = "color_string"; + public static final String KEY_COLOR_NUMBER = "color_number"; + public static final String KEY_COLOR_NORMAL = "color_normal"; + + public static final String KEY_BOLD_KEYWORD = "bold_keyword"; + + public static final RGB DEFAULT_COLOR_COMMENT = new RGB(63, 127, 95); + public static final RGB DEFAULT_COLOR_DOC = new RGB(127, 127, 159); + public static final RGB DEFAULT_COLOR_KEYWORD = new RGB(127, 0, 85); + public static final RGB DEFAULT_COLOR_STRING = new RGB(42, 0, 255); + public static final RGB DEFAULT_COLOR_NUMBER = new RGB(0, 0, 0); + public static final RGB DEFAULT_COLOR_NORMAL = new RGB(0, 0, 0); } diff --git a/org.nodeclipse.ui/src/org/nodeclipse/ui/preferences/PreferenceInitializer.java b/org.nodeclipse.ui/src/org/nodeclipse/ui/preferences/PreferenceInitializer.java index 2abd99fc..406a2a6f 100644 --- a/org.nodeclipse.ui/src/org/nodeclipse/ui/preferences/PreferenceInitializer.java +++ b/org.nodeclipse.ui/src/org/nodeclipse/ui/preferences/PreferenceInitializer.java @@ -7,6 +7,7 @@ import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferenceConverter; import org.nodeclipse.ui.Activator; import org.nodeclipse.ui.util.Constants; import org.nodeclipse.ui.util.OSUtils; @@ -53,14 +54,21 @@ public void initializeDefaultPreferences() { } file = new File(path); if (file.exists()) { - store.setDefault(PreferenceConstants.NODE_PATH, path); + store.setDefault(PreferenceConstants.KEY_NODE_PATH, path); } file = new File(express_path); if (file.exists()) { - store.setDefault(PreferenceConstants.EXPRESS_PATH, express_path); - store.setDefault(PreferenceConstants.EXPRESS_VERSION, + store.setDefault(PreferenceConstants.KEY_EXPRESS_PATH, express_path); + store.setDefault(PreferenceConstants.KEY_EXPRESS_VERSION, getExpressVersion(express_path)); } + PreferenceConverter.setDefault(store, PreferenceConstants.KEY_COLOR_COMMENT, PreferenceConstants.DEFAULT_COLOR_COMMENT); + PreferenceConverter.setDefault(store, PreferenceConstants.KEY_COLOR_DOC, PreferenceConstants.DEFAULT_COLOR_DOC); + PreferenceConverter.setDefault(store, PreferenceConstants.KEY_COLOR_KEYWORD, PreferenceConstants.DEFAULT_COLOR_KEYWORD); + PreferenceConverter.setDefault(store, PreferenceConstants.KEY_COLOR_STRING, PreferenceConstants.DEFAULT_COLOR_STRING); + PreferenceConverter.setDefault(store, PreferenceConstants.KEY_COLOR_NUMBER, PreferenceConstants.DEFAULT_COLOR_NUMBER); + PreferenceConverter.setDefault(store, PreferenceConstants.KEY_COLOR_NORMAL, PreferenceConstants.DEFAULT_COLOR_NORMAL); + store.setDefault(PreferenceConstants.KEY_BOLD_KEYWORD, true); } private String getExpressVersion(String express) { diff --git a/org.nodeclipse.ui/src/org/nodeclipse/ui/util/ProcessUtils.java b/org.nodeclipse.ui/src/org/nodeclipse/ui/util/ProcessUtils.java index 09f82e33..4bf671a8 100644 --- a/org.nodeclipse.ui/src/org/nodeclipse/ui/util/ProcessUtils.java +++ b/org.nodeclipse.ui/src/org/nodeclipse/ui/util/ProcessUtils.java @@ -18,7 +18,7 @@ public class ProcessUtils { public static String getNodePath() { return Activator.getDefault().getPreferenceStore() - .getString(PreferenceConstants.NODE_PATH); + .getString(PreferenceConstants.KEY_NODE_PATH); } public static String getNodeFolder() { @@ -28,7 +28,7 @@ public static String getNodeFolder() { public static String getNpmPath() { String nodePath = Activator.getDefault().getPreferenceStore() - .getString(PreferenceConstants.NODE_PATH); + .getString(PreferenceConstants.KEY_NODE_PATH); String npmPath = nodePath.substring(0, nodePath.lastIndexOf(File.separator) + 1); if (OSUtils.isWindows()) { @@ -40,17 +40,17 @@ public static String getNpmPath() { public static String getExpressPath() { return Activator.getDefault().getPreferenceStore() - .getString(PreferenceConstants.EXPRESS_PATH); + .getString(PreferenceConstants.KEY_EXPRESS_PATH); } public static String getExpressVersion() { return Activator.getDefault().getPreferenceStore() - .getString(PreferenceConstants.EXPRESS_VERSION); + .getString(PreferenceConstants.KEY_EXPRESS_VERSION); } public static String getCompletionsJsonPath() { return Activator.getDefault().getPreferenceStore() - .getString(PreferenceConstants.COMPLETIONS_JSON_PATH); + .getString(PreferenceConstants.KEY_COMPLETIONS_JSON_PATH); } diff --git a/org.nodeclipse.ui/src/org/nodeclipse/ui/wizards/ExpressProjectWizardPage.java b/org.nodeclipse.ui/src/org/nodeclipse/ui/wizards/ExpressProjectWizardPage.java index cbeba471..a85cec9d 100644 --- a/org.nodeclipse.ui/src/org/nodeclipse/ui/wizards/ExpressProjectWizardPage.java +++ b/org.nodeclipse.ui/src/org/nodeclipse/ui/wizards/ExpressProjectWizardPage.java @@ -107,7 +107,7 @@ public void createControl(Composite parent) { } private boolean isExpressInstalled() { - String path = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.EXPRESS_PATH); + String path = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.KEY_EXPRESS_PATH); if (path == null || path.equals("")) { return false; }