Skip to content
Closed
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 @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
// Using configuration to build command line
List<String> cmdLine = new ArrayList<String>();
// 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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");
}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.nodeclipse.ui.preferences;

import org.eclipse.swt.graphics.RGB;

/**
* Constant definitions for plug-in preferences
*
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions org.nodeclipse.ui/src/org/nodeclipse/ui/util/ProcessUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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()) {
Expand All @@ -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);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down