Commit 10ea9295 authored by Miklos Magyari's avatar Miklos Magyari Committed by Adam Knapp
Browse files

Syntax highlighting preview: update on enabling/disabling semantic highlighting

parent e50fbf58
......@@ -230,8 +230,8 @@ public final class SyntaxHighlightPage extends PreferencePage implements IWorkbe
public void init(final IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
tempstore = new PreferenceStore();
final TempPreferenceInitializer inittializer = new TempPreferenceInitializer();
inittializer.initializeDefaultPreferences();
final TempPreferenceInitializer initializer = new TempPreferenceInitializer();
initializer.initializeDefaultPreferences();
}
@Override
......@@ -519,7 +519,18 @@ public final class SyntaxHighlightPage extends PreferencePage implements IWorkbe
addTemplateText(PreferenceConstants.COLOR_TTCN3_KEYWORDS, "charstring", " ");
addTemplateText(PreferenceConstants.COLOR_AST_VARIABLE, "c2", "\n");
addTemplateText(PreferenceConstants.COLOR_NORMAL_TEXT, "}", "\n");
updateStyleRanges();
final IPreferenceStore defaultStore = Activator.getDefault().getPreferenceStore();
for (Map.Entry<String,List<StyleRange>> entry : rangeMap.entrySet()) {
final String key = entry.getKey();
tempstore.setValue(key + PreferenceConstants.FOREGROUND, defaultStore.getString(key + PreferenceConstants.FOREGROUND));
tempstore.setValue(key + PreferenceConstants.BACKGROUND, defaultStore.getString(key + PreferenceConstants.BACKGROUND));
tempstore.setValue(key + PreferenceConstants.USEBACKGROUNDCOLOR, defaultStore.getBoolean(key + PreferenceConstants.USEBACKGROUNDCOLOR));
tempstore.setValue(key + PreferenceConstants.BOLD, defaultStore.getBoolean(key + PreferenceConstants.BOLD));
tempstore.setValue(key + PreferenceConstants.ITALIC, defaultStore.getBoolean(key + PreferenceConstants.ITALIC));
tempstore.setValue(key + PreferenceConstants.STRIKETHROUGH, defaultStore.getBoolean(key + PreferenceConstants.STRIKETHROUGH));
tempstore.setValue(key + PreferenceConstants.UNDERLINE, defaultStore.getBoolean(key + PreferenceConstants.UNDERLINE));
}
}
private void createSemanticHighlightingCheckbox(final Composite parent) {
......@@ -539,6 +550,7 @@ public final class SyntaxHighlightPage extends PreferencePage implements IWorkbe
ttcn3SemanticGroup.setEnabled(enableSemanticHighlighting.getBooleanValue());
treeViewer.refresh();
}
updateStyleRanges();
}
});
}
......@@ -575,6 +587,8 @@ public final class SyntaxHighlightPage extends PreferencePage implements IWorkbe
createSemanticHighlightingCheckbox(pageComposite);
createUpperHalf(pageComposite);
//updateStyleRanges();
return pageComposite;
}
......@@ -680,7 +694,8 @@ public final class SyntaxHighlightPage extends PreferencePage implements IWorkbe
private void addTemplateText(String key, String text, String optWhiteSpace) {
int start = textViewer.getText().length();
textViewer.append(text);
final StyleRange range = colorManager.createStyleRangeFromPreference(key, Activator.getDefault().getPreferenceStore(), start, text.length());
final StyleRange range = colorManager.createStyleRangeFromPreference(key, Activator.getDefault().getPreferenceStore(), start, text.length());
textViewer.setStyleRange(range);
List<StyleRange> list = rangeMap.containsKey(key) ? rangeMap.get(key) : new ArrayList<StyleRange>();
list.add(range);
......@@ -693,17 +708,27 @@ public final class SyntaxHighlightPage extends PreferencePage implements IWorkbe
private void updateStyleRanges() {
try {
final boolean isSemantic = enableSemanticHighlighting.getBooleanValue();
for (Map.Entry<String,List<StyleRange>> entry : rangeMap.entrySet()) {
if (entry.getKey().equals(element.getBasePreferenceKey())) {
final List<StyleRange> list = entry.getValue();
for (StyleRange oldRange : list) {
textViewer.setStyleRange(colorManager.createStyleRangeFromPreference(
element.getBasePreferenceKey(), tempstore, oldRange.start, oldRange.length));
String base = entry.getKey();
if (! isSemantic) {
switch(entry.getKey()) {
case PreferenceConstants.COLOR_AST_CONSTANT:
case PreferenceConstants.COLOR_AST_VARIABLE:
case PreferenceConstants.COLOR_AST_DEFTYPE:
case PreferenceConstants.COLOR_AST_DEPRECATED:
base = PreferenceConstants.COLOR_NORMAL_TEXT;
break;
default:
}
}
for (StyleRange oldRange : entry.getValue()) {
textViewer.setStyleRange(colorManager.createStyleRangeFromPreference(
base, tempstore, oldRange.start, oldRange.length));
}
}
} catch (Exception e) {
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment