Skip to content

Commit

Permalink
Merge pull request #19 from Krzmbrzl/plugin
Browse files Browse the repository at this point in the history
"Preference-Update"
  • Loading branch information
Krzmbrzl committed Jan 22, 2016
2 parents 5775fd4 + 7e84c52 commit b521ee6
Show file tree
Hide file tree
Showing 87 changed files with 3,160 additions and 58 deletions.
3 changes: 2 additions & 1 deletion plugin/Raven.SQDev.Editors/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Editors
Bundle-SymbolicName: raven.sqdev.editors;singleton:=true
Bundle-Version: 0.1.0
Bundle-Version: 0.1.1
Bundle-Activator: raven.sqdev.editors.activator.Activator
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
Expand All @@ -15,3 +15,4 @@ Bundle-ActivationPolicy: lazy
Export-Package: raven.sqdev.editors,
raven.sqdev.editors.exceptions
Bundle-Vendor: Raven
Import-Package: raven.sqdev.preferences.util
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package raven.sqdev.editors;

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.IDocumentExtension3;
import org.eclipse.jface.text.ITextViewerExtension;
import org.eclipse.jface.text.source.DefaultCharacterPairMatcher;
Expand All @@ -11,14 +10,11 @@
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;

import raven.sqdev.preferences.util.SQDevPreferenceConstants;
import raven.sqdev.preferences.util.SQDevPreferenceUtil;

public class BasicTextEditor extends TextEditor {

public static final String EDITOR_MATCHING_BRACKETS_KEY = "matchingBrackets";
public static final String EDITOR_MATCHING_BRACKETS_COLOR_KEY = "matchingBracketsColor";
public static final String EDITOR_HIGHLIGHT_CURRENTLINE_KEY = "highlightCurrentLine";
public static final String EDITOR_HIGHLIGHT_CURRENTLINE_COLOR_KEY = "highlighCurrentLineColor";


private ColorManager colorManager;
private EditorKeyEventQueue editorKeyEventQueue;

Expand Down Expand Up @@ -69,26 +65,19 @@ protected void configureSourceViewerDecorationSupport(SourceViewerDecorationSupp
char[] matchChars = { '(', ')', '[', ']', '{', '}' }; // which brackets
// to match
ICharacterPairMatcher matcher = new DefaultCharacterPairMatcher(matchChars,
IDocumentExtension3.DEFAULT_PARTITIONING);
IDocumentExtension3.DEFAULT_PARTITIONING, true);

// character pair matching
support.setCharacterPairMatcher(matcher);
support.setMatchingCharacterPainterPreferenceKeys(EDITOR_MATCHING_BRACKETS_KEY,
EDITOR_MATCHING_BRACKETS_COLOR_KEY);

support.setMatchingCharacterPainterPreferenceKeys(
SQDevPreferenceConstants.SQDEV_EDITOR_MATCHING_BRACKETS_KEY,
SQDevPreferenceConstants.SQDEV_EDITOR_MATCHING_BRACKETS_COLOR_KEY);

// newLine highlighting
support.setCursorLinePainterPreferenceKeys(EDITOR_HIGHLIGHT_CURRENTLINE_KEY,
EDITOR_HIGHLIGHT_CURRENTLINE_COLOR_KEY);
support.setCursorLinePainterPreferenceKeys(
SQDevPreferenceConstants.SQDEV_EDITOR_HIGHLIGHT_CURRENTLINE_KEY,
SQDevPreferenceConstants.SQDEV_EDITOR_HIGHLIGHT_CURRENTLINE_COLOR_KEY);

// Enable bracket highlighting in the preference store
IPreferenceStore store = getPreferenceStore();
store.setDefault(EDITOR_MATCHING_BRACKETS_KEY, true);
store.setDefault(EDITOR_MATCHING_BRACKETS_COLOR_KEY,
ISQDevColorConstants.getRGBValuesAsString(ISQDevColorConstants.BRACKETMATCH));

//enable currentLine highlighting
store.setDefault(EDITOR_HIGHLIGHT_CURRENTLINE_KEY, true);
store.setDefault(EDITOR_HIGHLIGHT_CURRENTLINE_COLOR_KEY,
ISQDevColorConstants.getRGBValuesAsString(ISQDevColorConstants.CURRENTLINE));
}

/**
Expand Down Expand Up @@ -128,4 +117,20 @@ public void addCharacterPairHandler() {
getEditorKeyEventQueue().queueEditorKeyHandler(pairHandler);
}

@Override
public void createPartControl(Composite parent) {
super.createPartControl(parent);

if (fSourceViewerDecorationSupport != null) {
// set the plugin's shared preference store instead of the default one
fSourceViewerDecorationSupport.install(SQDevPreferenceUtil.getPreferenceStore());
}
}

/**
* Updates the editor
*/
public void update() {
this.getSourceViewer().invalidateTextPresentation();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,92 @@
import org.eclipse.jface.text.rules.RuleBasedScanner;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.rules.WordRule;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;

import raven.sqdev.preferences.util.SQDevPreferenceUtil;
import raven.sqdev.util.ColorUtils;

/**
* A scanner that scans for keywords and colors them with the
* <code>ISQDevColorConstants.KEYWORD</code> color
*
* @author Raven
*
*
*/
public class KeywordScanner extends RuleBasedScanner {
public class KeywordScanner extends RuleBasedScanner implements IPropertyChangeListener {

protected String preferenceKey;
protected IKeywordProvider provider;
protected BasicTextEditor editor;

/**
* Creates an instance of this scanner
*
* @param provider
* An <code>IKeyowrdProvider</code> that will supply this method
* with keywords
* @param color
* The color in which these keywords should be highlighted (they
* are bold in all cases)
* @param colorPreferenceKey
* The key of the preference describing the color of the
* highlighting of the keywords
*/
public KeywordScanner(IKeywordProvider provider, Color color) {
public KeywordScanner(IKeywordProvider provider, String colorPreferenceKey, BasicTextEditor editor) {
String strColor = SQDevPreferenceUtil.getPreferenceStore().getString(colorPreferenceKey);

if (strColor == null || strColor.isEmpty()) {
throw new IllegalArgumentException(
"Invalid preference key \"" + colorPreferenceKey + "\"");
}

SQDevPreferenceUtil.getPreferenceStore().addPropertyChangeListener(this);

preferenceKey = colorPreferenceKey;
this.provider = provider;
this.editor = editor;

Color color = new Color(Display.getCurrent(), ColorUtils.decodeRGB(strColor));

IToken keyword = new Token(new TextAttribute(color, null, SWT.BOLD));

setToken(keyword);
}

@Override
public void propertyChange(PropertyChangeEvent event) {
if (event.getProperty().equals(preferenceKey)) {
// if the changed property is the one for the color this scanner
// depends on
if(event.getNewValue() != null) {
Color color = new Color(Display.getCurrent(), ColorUtils.decodeRGB((String) event.getNewValue()));
IToken token = new Token(new TextAttribute(color, null, SWT.BOLD));

setToken(token);
}
}
}

/**
* Sets the token for this scanner.<br>
* Will apply the newly created rule immediately
* @param token
*/
protected void setToken(IToken token) {
String[] keywords = provider.getKeywords();

WordRule keywordRule = new WordRule(new WordDetector());

// add keywords
for (String currentKeyword : keywords) {
keywordRule.addWord(currentKeyword, keyword);
keywordRule.addWord(currentKeyword, token);
}

IRule[] rules = { keywordRule };

this.setRules(rules);

editor.update();
}

}
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package raven.sqdev.editors.activator;

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

import raven.sqdev.preferences.util.SQDevPreferenceUtil;

/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {

// The plug-in ID
public static final String PLUGIN_ID = "Raven.SQDev.Editors"; //$NON-NLS-1$

// The shared instance
private static Activator plugin;

Expand All @@ -19,25 +22,29 @@ public class Activator extends AbstractUIPlugin {
*/
public Activator() {
}

/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.
* BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}

/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.
* BundleContext)
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}

/**
* Returns the shared instance
*
Expand All @@ -46,5 +53,15 @@ public void stop(BundleContext context) throws Exception {
public static Activator getDefault() {
return plugin;
}


/**
* This will return the preference store of
* <code>raven.sqdev.preferences</code> as this is where all SQDev
* preference are stored
*/
@Override
public IPreferenceStore getPreferenceStore() {
return SQDevPreferenceUtil.getPreferenceStore();
}

}
7 changes: 4 additions & 3 deletions plugin/Raven.SQDev.SQFEditor/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: SQFEditor
Bundle-SymbolicName: raven.sqdev.editors.sqfeditor;singleton:=true
Bundle-Version: 0.1.0
Bundle-Version: 0.1.1
Bundle-Activator: raven.sqdev.activator.Activator
Bundle-Vendor: Raven
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.ui.editors,
org.eclipse.jface.text;bundle-version="3.9.2",
raven.sqdev.editors;bundle-version="0.1.0",
org.eclipse.osgi,
raven.sqdev.util;bundle-version="0.1.0"
raven.sqdev.util;bundle-version="0.1.0",
raven.sqdev.editors;bundle-version="0.1.1",
raven.sqdev.preferences
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Import-Package: raven.sqdev.exceptions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package raven.sqdev.activator;

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

import raven.sqdev.preferences.util.SQDevPreferenceUtil;

/**
* The activator class controls the plug-in life cycle
*/
Expand Down Expand Up @@ -46,5 +49,15 @@ public void stop(BundleContext context) throws Exception {
public static Activator getDefault() {
return plugin;
}

/**
* This will return the preference store of
* <code>raven.sqdev.preferences</code> as this is where all SQDev
* preference are stored
*/
@Override
public IPreferenceStore getPreferenceStore() {
return SQDevPreferenceUtil.getPreferenceStore();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;

import raven.sqdev.editors.BasicTextEditor;
import raven.sqdev.editors.ColorManager;
import raven.sqdev.editors.ISQDevColorConstants;
import raven.sqdev.editors.KeywordScanner;
import raven.sqdev.editors.NonRuleBasedDamagerRepairer;
import raven.sqdev.preferences.util.ISQDevColorConstants;
import raven.sqdev.preferences.util.SQDevPreferenceConstants;

public final class SQFConfiguration extends SourceViewerConfiguration {

private ColorManager colorManager;
private KeywordScanner keywordScanner;
protected ColorManager colorManager;
protected KeywordScanner keywordScanner;
protected BasicTextEditor editor;

public SQFConfiguration(ColorManager manager) {
public SQFConfiguration(ColorManager manager, BasicTextEditor editor) {
this.setColorManager(manager);
this.editor = editor;
}

@Override
Expand All @@ -45,7 +49,7 @@ public KeywordScanner getKeywordScanner() {

if (this.keywordScanner == null) {
this.keywordScanner = new KeywordScanner(new SQFKeywordProvider(),
this.getColorManager().getColor(ISQDevColorConstants.KEYWORD));
SQDevPreferenceConstants.SQDEV_EDITOR_SYNTAXHIGHLIGHTING_COLOR_KEY, editor);
}

return this.keywordScanner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class SQF_Editor extends BasicTextEditor {

public SQF_Editor() {
super();
this.setSourceViewerConfiguration(new SQFConfiguration(this.getColorManager()));
this.setSourceViewerConfiguration(new SQFConfiguration(this.getColorManager(), this));
this.setDocumentProvider(new SQFDocumentProvider());
}
}
3 changes: 2 additions & 1 deletion plugin/Raven.SQDev.Util/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Util
Bundle-SymbolicName: raven.sqdev.util
Bundle-Version: 0.1.0
Bundle-Version: 0.2.0
Bundle-Activator: raven.sqdev.util.Activator
Bundle-Vendor: Raven
Require-Bundle: org.eclipse.core.runtime
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Export-Package: raven.sqdev.exceptions,
raven.sqdev.util
Import-Package: org.eclipse.swt.graphics
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit b521ee6

Please sign in to comment.