mirror of
https://github.com/peterdell/wudsn-ide.git
synced 2025-01-30 23:33:21 +00:00
Fix preferences for text attributes and rule/source scanner refresh for them
This commit is contained in:
parent
1f65ef6c74
commit
744d8addda
@ -26,6 +26,7 @@ import org.eclipse.jface.text.rules.RuleBasedScanner;
|
||||
import org.eclipse.jface.text.rules.Token;
|
||||
|
||||
import com.wudsn.ide.lng.preferences.LanguagePreferences;
|
||||
import com.wudsn.ide.lng.preferences.LanguagePreferencesConstants;
|
||||
import com.wudsn.ide.lng.preferences.TextAttributeConverter;
|
||||
|
||||
/**
|
||||
@ -37,7 +38,6 @@ import com.wudsn.ide.lng.preferences.TextAttributeConverter;
|
||||
final class LanguageRuleBasedScanner extends RuleBasedScanner {
|
||||
|
||||
// Key for preference store
|
||||
private LanguagePreferences languagePreferences;
|
||||
private String preferencesKey;
|
||||
|
||||
// Default Token for the text attributes
|
||||
@ -47,21 +47,22 @@ final class LanguageRuleBasedScanner extends RuleBasedScanner {
|
||||
* Creates a new instance. Called by {@link LanguageSourceViewerConfiguration}.
|
||||
*
|
||||
* @param languagePreferences The language preferences, not <code>null</code>.
|
||||
* @param preferencesKey The preference key to listen to for text attribute
|
||||
* changes, not <code>null</code>.
|
||||
* @param textAttributeName The text attribute name to listen to for text
|
||||
* attribute changes, not <code>null</code>. See
|
||||
* {@link LanguagePreferencesConstants}
|
||||
*/
|
||||
LanguageRuleBasedScanner(LanguagePreferences languagePreferences, String preferencesKey) {
|
||||
LanguageRuleBasedScanner(LanguagePreferences languagePreferences, String textAttributeName) {
|
||||
|
||||
if (languagePreferences == null) {
|
||||
throw new IllegalArgumentException("Parameter 'language' must not be null.");
|
||||
}
|
||||
if (preferencesKey == null) {
|
||||
throw new IllegalArgumentException("Parameter 'preferencesKey' must not be null.");
|
||||
if (textAttributeName == null) {
|
||||
throw new IllegalArgumentException("Parameter 'textAttributeName' must not be null.");
|
||||
}
|
||||
this.languagePreferences = languagePreferences;
|
||||
this.preferencesKey = preferencesKey;
|
||||
this.preferencesKey = LanguagePreferencesConstants.getPreferencesKey(languagePreferences.getLanguage(),
|
||||
textAttributeName);
|
||||
|
||||
defaultToken = new Token(languagePreferences.getEditorTextAttribute(preferencesKey));
|
||||
defaultToken = new Token(languagePreferences.getEditorTextAttribute(textAttributeName));
|
||||
|
||||
super.setDefaultReturnToken(defaultToken);
|
||||
}
|
||||
@ -91,10 +92,9 @@ final class LanguageRuleBasedScanner extends RuleBasedScanner {
|
||||
throw new IllegalArgumentException("Parameter 'changedPropertyNames' must not be null.");
|
||||
}
|
||||
boolean refresh = false;
|
||||
if (preferences.getLanguage().equals(languagePreferences.getLanguage())
|
||||
&& changedPropertyNames.contains(preferencesKey)) {
|
||||
if (changedPropertyNames.contains(preferencesKey)) {
|
||||
TextAttributeConverter.dispose((TextAttribute) defaultToken.getData());
|
||||
defaultToken.setData(preferences.getEditorTextAttribute(preferencesKey));
|
||||
defaultToken.setData(preferences.getLanguagesPreferences().getEditorTextAttribute(preferencesKey));
|
||||
refresh = true;
|
||||
}
|
||||
return refresh;
|
||||
|
@ -220,7 +220,8 @@ final class LanguageSourceScanner extends RuleBasedScanner {
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("" + this + ":" + state.identifierWordTokens.size() + " identifier word tokens set: "+ state.identifierWordTokens); // TODO
|
||||
System.out.println("" + this + ":" + state.identifierWordTokens.size() + " identifier word tokens set: "
|
||||
+ state.identifierWordTokens); // TODO
|
||||
}
|
||||
|
||||
/*
|
||||
@ -431,11 +432,11 @@ final class LanguageSourceScanner extends RuleBasedScanner {
|
||||
if (textAttributeName == null) {
|
||||
throw new IllegalArgumentException("Parameter 'textAttributeName' must not be null.");
|
||||
}
|
||||
LanguagePreferences preferences;
|
||||
Token token;
|
||||
preferences = editor.getLanguagePreferences();
|
||||
token = new Token(preferences.getEditorTextAttribute(textAttributeName));
|
||||
tokens.put(textAttributeName, token);
|
||||
LanguagePreferences preferences = editor.getLanguagePreferences();
|
||||
String preferencesKey = LanguagePreferencesConstants.getPreferencesKey(preferences.getLanguage(),
|
||||
textAttributeName);
|
||||
Token token = new Token(preferences.getEditorTextAttribute(textAttributeName));
|
||||
tokens.put(preferencesKey, token);
|
||||
return token;
|
||||
}
|
||||
|
||||
@ -498,7 +499,7 @@ final class LanguageSourceScanner extends RuleBasedScanner {
|
||||
Token token = tokens.get(propertyName);
|
||||
if (token != null) {
|
||||
TextAttributeConverter.dispose((TextAttribute) token.getData());
|
||||
token.setData(preferences.getEditorTextAttribute(propertyName));
|
||||
token.setData(preferences.getLanguagesPreferences().getEditorTextAttribute(propertyName));
|
||||
refresh = true;
|
||||
|
||||
} else if (LanguagePreferencesConstants.isCompilerTargetName(propertyName)) {
|
||||
|
@ -40,7 +40,6 @@ public final class LanguagePreferences {
|
||||
*/
|
||||
private LanguagesPreferences languagesPreferences;
|
||||
private Language language;
|
||||
private String languagePrefix;
|
||||
|
||||
/**
|
||||
* Created by {@link AbstractIDEPlugin} only.
|
||||
@ -56,13 +55,16 @@ public final class LanguagePreferences {
|
||||
}
|
||||
this.languagesPreferences = languagesPreferences;
|
||||
this.language = language;
|
||||
this.languagePrefix=language.name().toLowerCase()+".";
|
||||
}
|
||||
|
||||
public LanguagesPreferences getLanguagesPreferences() {
|
||||
return languagesPreferences;
|
||||
}
|
||||
|
||||
public Language getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the default case content assist.
|
||||
*
|
||||
@ -111,14 +113,16 @@ public final class LanguagePreferences {
|
||||
* the default value <code>false</code> if there is no preference with the given
|
||||
* name, or if the current value cannot be treated as a boolean.
|
||||
*
|
||||
* @param name The name of the preference, not <code>null</code>.
|
||||
* @param preferencesKeySuffix The he preferences key suffix of the preference,
|
||||
* not <code>null</code>.
|
||||
* @return The preference value.
|
||||
*/
|
||||
boolean getBoolean(String name) {
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("Parameter 'name' must not be null.");
|
||||
boolean getBoolean(String preferencesKeySuffix) {
|
||||
if (preferencesKeySuffix == null) {
|
||||
throw new IllegalArgumentException("Parameter 'preferencesKeySuffix' must not be null.");
|
||||
}
|
||||
return languagesPreferences.getBoolean(languagePrefix+ name);
|
||||
return languagesPreferences
|
||||
.getBoolean(LanguagePreferencesConstants.getPreferencesKey(language, preferencesKeySuffix));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -127,29 +131,32 @@ public final class LanguagePreferences {
|
||||
* there is no preference with the given name, or if the current value cannot be
|
||||
* treated as a string.
|
||||
*
|
||||
* @param name The name of the preference, not <code>null</code>.
|
||||
* @param preferencesKeySuffix The preferences key suffix of the preference, not
|
||||
* <code>null</code>.
|
||||
* @return The preference value, may be empty, not <code>null</code>.
|
||||
*/
|
||||
String getString(String name) {
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("Parameter 'name' must not be null.");
|
||||
String getString(String preferencesKeySuffix) {
|
||||
if (preferencesKeySuffix == null) {
|
||||
throw new IllegalArgumentException("Parameter 'preferencesKeySuffix' must not be null.");
|
||||
}
|
||||
return languagesPreferences.getString(languagePrefix + name);
|
||||
return languagesPreferences
|
||||
.getString(LanguagePreferencesConstants.getPreferencesKey(language, preferencesKeySuffix));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the text attribute for a token type.
|
||||
*
|
||||
* @param name The name of the preferences for the token type, see
|
||||
* {@link LanguagePreferencesConstants}.
|
||||
* @param textAttributeName The suffix of the preferences for the token type,
|
||||
* see {@link LanguagePreferencesConstants}.
|
||||
*
|
||||
* @return The text attribute, not <code>null</code>.
|
||||
*/
|
||||
public TextAttribute getEditorTextAttribute(String name) {
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("Parameter 'name' must not be null.");
|
||||
public TextAttribute getEditorTextAttribute(String textAttributeName) {
|
||||
if (textAttributeName == null) {
|
||||
throw new IllegalArgumentException("Parameter 'textAttributeName' must not be null.");
|
||||
}
|
||||
return languagesPreferences.getEditorTextAttribute(languagePrefix+ name);
|
||||
return languagesPreferences
|
||||
.getEditorTextAttribute(LanguagePreferencesConstants.getPreferencesKey(language, textAttributeName));
|
||||
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,8 @@ import com.wudsn.ide.lng.Language;
|
||||
import com.wudsn.ide.lng.Texts;
|
||||
|
||||
/**
|
||||
* Constants for preferences.
|
||||
* Constants for preferences. The string constants are preferences key suffix
|
||||
* that are not used directly but prefixes with the language.
|
||||
*
|
||||
* @author Peter Dell
|
||||
*/
|
||||
@ -121,6 +122,18 @@ public final class LanguagePreferencesConstants {
|
||||
*/
|
||||
static final String EDITOR_COMPILE_COMMAND_POSITIONING_MODE = "editor.compile.command.positioning.mode"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Create the preferences key for a property of a given language.
|
||||
*
|
||||
* @param language The language, not <code>null</code>
|
||||
* @param preferencesKeySuffix The suffix as defined by the constants of this
|
||||
* class, not empty, not <code>null</code>
|
||||
* @return
|
||||
*/
|
||||
public static String getPreferencesKey(Language language, String preferencesKeySuffix) {
|
||||
return language.name().toLowerCase() + "." + preferencesKeySuffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of all preferences keys that depend on the global JFact text font
|
||||
* setting.
|
||||
@ -133,40 +146,45 @@ public final class LanguagePreferencesConstants {
|
||||
List<TextAttributeDefinition> result = new ArrayList<TextAttributeDefinition>();
|
||||
|
||||
// Comments and literals
|
||||
result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_COMMENT,
|
||||
result.add(new TextAttributeDefinition(getPreferencesKey(language, EDITOR_TEXT_ATTRIBUTE_COMMENT),
|
||||
Texts.PREFERENCES_TEXT_ATTRIBUTE_COMMENT_NAME));
|
||||
result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_NUMBER,
|
||||
result.add(new TextAttributeDefinition(getPreferencesKey(language, EDITOR_TEXT_ATTRIBUTE_NUMBER),
|
||||
Texts.PREFERENCES_TEXT_ATTRIBUTE_NUMBER_NAME));
|
||||
result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_STRING,
|
||||
result.add(new TextAttributeDefinition(getPreferencesKey(language, EDITOR_TEXT_ATTRIBUTE_STRING),
|
||||
Texts.PREFERENCES_TEXT_ATTRIBUTE_STRING_NAME));
|
||||
|
||||
switch (language) {
|
||||
case ASM: {
|
||||
|
||||
// Built-in
|
||||
result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_DIRECTVE,
|
||||
result.add(new TextAttributeDefinition(getPreferencesKey(language, EDITOR_TEXT_ATTRIBUTE_DIRECTVE),
|
||||
Texts.PREFERENCES_TEXT_ATTRIBUTE_DIRECTIVE));
|
||||
result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_OPCODE_ILLEGAL,
|
||||
result.add(new TextAttributeDefinition(getPreferencesKey(language, EDITOR_TEXT_ATTRIBUTE_OPCODE_ILLEGAL),
|
||||
Texts.PREFERENCES_TEXT_ATTRIBUTE_OPCODE_ILLEGAL_NAME));
|
||||
result.add(new TextAttributeDefinition(getPreferencesKey(language, EDITOR_TEXT_ATTRIBUTE_OPCODE_LEGAL),
|
||||
Texts.PREFERENCES_TEXT_ATTRIBUTE_OPCODE_LEGAL_NAME));
|
||||
result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_OPCODE_LEGAL,
|
||||
Texts.PREFERENCES_TEXT_ATTRIBUTE_OPCODE_LEGAL_NAME));
|
||||
result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_OPCODE_PSEUDO,
|
||||
result.add(new TextAttributeDefinition(getPreferencesKey(language, EDITOR_TEXT_ATTRIBUTE_OPCODE_PSEUDO),
|
||||
Texts.PREFERENCES_TEXT_ATTRIBUTE_OPCODE_PSEUDO_NAME));
|
||||
|
||||
// Identifiers
|
||||
result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_ENUM_DEFINITION_SECTION,
|
||||
result.add(new TextAttributeDefinition(
|
||||
getPreferencesKey(language, EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_ENUM_DEFINITION_SECTION),
|
||||
Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_ENUM_DEFINITION_SECTION));
|
||||
result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_EQUATE,
|
||||
result.add(new TextAttributeDefinition(getPreferencesKey(language, EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_EQUATE),
|
||||
Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_EQUATE));
|
||||
result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_LABEL,
|
||||
result.add(new TextAttributeDefinition(getPreferencesKey(language, EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_LABEL),
|
||||
Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_LABEL));
|
||||
result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_LOCAL_SECTION,
|
||||
result.add(new TextAttributeDefinition(
|
||||
getPreferencesKey(language, EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_LOCAL_SECTION),
|
||||
Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_LOCAL_SECTION));
|
||||
result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_MACRO_DEFINITION_SECTION,
|
||||
result.add(new TextAttributeDefinition(
|
||||
getPreferencesKey(language, EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_MACRO_DEFINITION_SECTION),
|
||||
Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_MACRO_DEFINITION_SECTION));
|
||||
result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_PROCEDURE_DEFINITION_SECTION,
|
||||
result.add(new TextAttributeDefinition(
|
||||
getPreferencesKey(language, EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_PROCEDURE_DEFINITION_SECTION),
|
||||
Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_PROCEDURE_DEFINITION_SECTION));
|
||||
result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_STRUCTURE_DEFINITION_SECTION,
|
||||
result.add(new TextAttributeDefinition(
|
||||
getPreferencesKey(language, EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_STRUCTURE_DEFINITION_SECTION),
|
||||
Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_STRUCTURE_DEFINITION_SECTION));
|
||||
break;
|
||||
|
||||
@ -175,15 +193,18 @@ public final class LanguagePreferencesConstants {
|
||||
case PAS: {
|
||||
|
||||
// Built-in
|
||||
result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_DIRECTVE,
|
||||
result.add(new TextAttributeDefinition(getPreferencesKey(language, EDITOR_TEXT_ATTRIBUTE_DIRECTVE),
|
||||
Texts.PREFERENCES_TEXT_ATTRIBUTE_DIRECTIVE));
|
||||
|
||||
// Identifiers
|
||||
result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_ENUM_DEFINITION_SECTION,
|
||||
result.add(new TextAttributeDefinition(
|
||||
getPreferencesKey(language, EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_ENUM_DEFINITION_SECTION),
|
||||
Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_ENUM_DEFINITION_SECTION));
|
||||
result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_PROCEDURE_DEFINITION_SECTION,
|
||||
result.add(new TextAttributeDefinition(
|
||||
getPreferencesKey(language, EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_PROCEDURE_DEFINITION_SECTION),
|
||||
Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_PROCEDURE_DEFINITION_SECTION));
|
||||
result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_STRUCTURE_DEFINITION_SECTION,
|
||||
result.add(new TextAttributeDefinition(
|
||||
getPreferencesKey(language, EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_STRUCTURE_DEFINITION_SECTION),
|
||||
Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_STRUCTURE_DEFINITION_SECTION));
|
||||
break;
|
||||
|
||||
|
@ -58,8 +58,8 @@ import org.eclipse.ui.model.WorkbenchViewerComparator;
|
||||
|
||||
import com.wudsn.ide.base.common.ProcessWithLogs;
|
||||
import com.wudsn.ide.base.gui.SWTFactory;
|
||||
import com.wudsn.ide.lng.LanguagePlugin;
|
||||
import com.wudsn.ide.lng.Language;
|
||||
import com.wudsn.ide.lng.LanguagePlugin;
|
||||
import com.wudsn.ide.lng.Texts;
|
||||
import com.wudsn.ide.lng.compiler.CompilerDefinition;
|
||||
import com.wudsn.ide.lng.compiler.CompilerRegistry;
|
||||
@ -104,7 +104,7 @@ public abstract class LanguagePreferencesPage extends FieldEditorPreferencePage
|
||||
* The language.
|
||||
*/
|
||||
private Language language;
|
||||
|
||||
|
||||
/**
|
||||
* The owning plugin.
|
||||
*/
|
||||
@ -121,11 +121,6 @@ public abstract class LanguagePreferencesPage extends FieldEditorPreferencePage
|
||||
*/
|
||||
private String activeCompilerId;
|
||||
|
||||
/**
|
||||
* The list of all text attributes and the corresponding preferences keys.
|
||||
*/
|
||||
private String[][] textAttributeListItemKeys;
|
||||
|
||||
/**
|
||||
* List for text attribute items.
|
||||
*/
|
||||
@ -163,37 +158,6 @@ public abstract class LanguagePreferencesPage extends FieldEditorPreferencePage
|
||||
plugin = LanguagePlugin.getInstance();
|
||||
setPreferenceStore(plugin.getPreferenceStore());
|
||||
changedPropertyNames = new TreeSet<String>();
|
||||
|
||||
textAttributeListItemKeys = new String[][] {
|
||||
{ Texts.PREFERENCES_TEXT_ATTRIBUTE_COMMENT_NAME,
|
||||
LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_COMMENT },
|
||||
{ Texts.PREFERENCES_TEXT_ATTRIBUTE_NUMBER_NAME,
|
||||
LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_NUMBER },
|
||||
{ Texts.PREFERENCES_TEXT_ATTRIBUTE_STRING_NAME,
|
||||
LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_STRING },
|
||||
{ Texts.PREFERENCES_TEXT_ATTRIBUTE_DIRECTIVE,
|
||||
LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_DIRECTVE },
|
||||
{ Texts.PREFERENCES_TEXT_ATTRIBUTE_OPCODE_LEGAL_NAME,
|
||||
LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_OPCODE_LEGAL },
|
||||
{ Texts.PREFERENCES_TEXT_ATTRIBUTE_OPCODE_ILLEGAL_NAME,
|
||||
LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_OPCODE_ILLEGAL },
|
||||
{ Texts.PREFERENCES_TEXT_ATTRIBUTE_OPCODE_PSEUDO_NAME,
|
||||
LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_OPCODE_PSEUDO },
|
||||
|
||||
{ Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_EQUATE,
|
||||
LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_EQUATE },
|
||||
{ Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_LABEL,
|
||||
LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_LABEL },
|
||||
{ Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_ENUM_DEFINITION_SECTION,
|
||||
LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_ENUM_DEFINITION_SECTION },
|
||||
{ Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_STRUCTURE_DEFINITION_SECTION,
|
||||
LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_STRUCTURE_DEFINITION_SECTION },
|
||||
{ Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_LOCAL_SECTION,
|
||||
LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_LOCAL_SECTION },
|
||||
{ Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_MACRO_DEFINITION_SECTION,
|
||||
LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_MACRO_DEFINITION_SECTION },
|
||||
{ Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_PROCEDURE_DEFINITION_SECTION,
|
||||
LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_PROCEDURE_DEFINITION_SECTION } };
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -395,15 +359,11 @@ public abstract class LanguagePreferencesPage extends FieldEditorPreferencePage
|
||||
.getTextAttributeDefinitions(language);
|
||||
textAttributeListItems = new ArrayList<TextAttributeListItem>(textAttributeDefinitions.size());
|
||||
|
||||
for (TextAttributeDefinition textAttributeDefinition: textAttributeDefinitions) {
|
||||
String data;
|
||||
TextAttribute textAttribute;
|
||||
TextAttributeListItem item;
|
||||
for (TextAttributeDefinition textAttributeDefinition : textAttributeDefinitions) {
|
||||
String data = getPreferenceStore().getString(textAttributeDefinition.getPreferencesKey());
|
||||
TextAttribute textAttribute = TextAttributeConverter.fromString(data);
|
||||
|
||||
data = getPreferenceStore().getString(textAttributeDefinition.getPreferencesKey());
|
||||
textAttribute = TextAttributeConverter.fromString(data);
|
||||
|
||||
item = new TextAttributeListItem(textAttributeDefinition);
|
||||
TextAttributeListItem item = new TextAttributeListItem(textAttributeDefinition);
|
||||
item.setTextAttribute(textAttribute);
|
||||
textAttributeListItems.add(item);
|
||||
}
|
||||
@ -510,7 +470,10 @@ public abstract class LanguagePreferencesPage extends FieldEditorPreferencePage
|
||||
public boolean performOk() {
|
||||
if (super.performOk()) {
|
||||
saveChanges();
|
||||
plugin.log("Language preferences changed for language '{0}': {1}",
|
||||
new Object[] { language, String.join(",", changedPropertyNames) });
|
||||
plugin.firePreferencesChangeEvent(language, changedPropertyNames);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -527,8 +490,9 @@ public abstract class LanguagePreferencesPage extends FieldEditorPreferencePage
|
||||
super.performDefaults();
|
||||
|
||||
IPreferenceStore preferencesStore = getPreferenceStore();
|
||||
for (int i = 0, n = textAttributeListItemKeys.length; i < n; i++) {
|
||||
String key = textAttributeListItemKeys[i][1];
|
||||
for (TextAttributeListItem listItem : textAttributeListItems) {
|
||||
|
||||
String key = listItem.getDefinition().getPreferencesKey();
|
||||
preferencesStore.setValue(key, preferencesStore.getDefaultString(key));
|
||||
addChangedProperty(key);
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import org.eclipse.jface.text.TextAttribute;
|
||||
|
||||
import com.wudsn.ide.base.common.AbstractIDEPlugin;
|
||||
import com.wudsn.ide.lng.Language;
|
||||
|
||||
/**
|
||||
* Facade class for typed access to the plugin preferences.
|
||||
*
|
||||
@ -48,8 +49,6 @@ public final class LanguagesPreferences {
|
||||
this.preferenceStore = preferenceStore;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the preferences for a language.
|
||||
*
|
||||
@ -62,25 +61,23 @@ public final class LanguagesPreferences {
|
||||
throw new IllegalArgumentException("Parameter 'language' must not be null.");
|
||||
}
|
||||
|
||||
|
||||
return new LanguagePreferences(this, language);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the current value of the boolean preference with the given name. Returns
|
||||
* the default-default value <code>false</code> if there is no preference with
|
||||
* the given name, or if the current value cannot be treated as a boolean.
|
||||
*
|
||||
* @param name The name of the preference, not <code>null</code>.
|
||||
* @param preferencesKey The key of the preference, not <code>null</code>.
|
||||
* @return The preference value.
|
||||
*/
|
||||
boolean getBoolean(String name) {
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("Parameter 'key' must not be null.");
|
||||
boolean getBoolean(String preferencesKey) {
|
||||
if (preferencesKey == null) {
|
||||
throw new IllegalArgumentException("Parameter 'preferencesKey' must not be null.");
|
||||
}
|
||||
return preferenceStore.getBoolean(name);
|
||||
return preferenceStore.getBoolean(preferencesKey);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,15 +86,15 @@ public final class LanguagesPreferences {
|
||||
* there is no preference with the given name, or if the current value cannot be
|
||||
* treated as a string.
|
||||
*
|
||||
* @param name The name of the preference, not <code>null</code>.
|
||||
* @param preferencesKey The key of the preference, not <code>null</code>.
|
||||
* @return The preference value, may be empty, not <code>null</code>.
|
||||
*/
|
||||
String getString(String name) {
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("Parameter 'key' must not be null.");
|
||||
String getString(String preferencesKey) {
|
||||
if (preferencesKey == null) {
|
||||
throw new IllegalArgumentException("Parameter 'preferencesKey' must not be null.");
|
||||
}
|
||||
String result;
|
||||
result = preferenceStore.getString(name);
|
||||
result = preferenceStore.getString(preferencesKey);
|
||||
if (result == null) {
|
||||
result = "";
|
||||
} else {
|
||||
@ -106,22 +103,21 @@ public final class LanguagesPreferences {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the text attribute for a token type.
|
||||
*
|
||||
* @param name The name of the preferences for the token type, see
|
||||
* {@link LanguagePreferencesConstants}.
|
||||
* @param preferencesKey The key of the preference, not <code>null</code>.
|
||||
*
|
||||
* @return The text attribute, not <code>null</code>.
|
||||
*
|
||||
*/
|
||||
TextAttribute getEditorTextAttribute(String name) {
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("Parameter 'name' must not be null.");
|
||||
public TextAttribute getEditorTextAttribute(String preferencesKey) {
|
||||
if (preferencesKey == null) {
|
||||
throw new IllegalArgumentException("Parameter 'preferencesKey' must not be null.");
|
||||
}
|
||||
|
||||
return TextAttributeConverter.fromString(preferenceStore.getString(name));
|
||||
|
||||
return TextAttributeConverter.fromString(preferenceStore.getString(preferencesKey));
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user