mirror of
https://github.com/peterdell/wudsn-ide.git
synced 2025-08-09 00:25:12 +00:00
Fix preferences for text attributes and rule/source scanner refresh for them
This commit is contained in:
@@ -26,6 +26,7 @@ import org.eclipse.jface.text.rules.RuleBasedScanner;
|
|||||||
import org.eclipse.jface.text.rules.Token;
|
import org.eclipse.jface.text.rules.Token;
|
||||||
|
|
||||||
import com.wudsn.ide.lng.preferences.LanguagePreferences;
|
import com.wudsn.ide.lng.preferences.LanguagePreferences;
|
||||||
|
import com.wudsn.ide.lng.preferences.LanguagePreferencesConstants;
|
||||||
import com.wudsn.ide.lng.preferences.TextAttributeConverter;
|
import com.wudsn.ide.lng.preferences.TextAttributeConverter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,7 +38,6 @@ import com.wudsn.ide.lng.preferences.TextAttributeConverter;
|
|||||||
final class LanguageRuleBasedScanner extends RuleBasedScanner {
|
final class LanguageRuleBasedScanner extends RuleBasedScanner {
|
||||||
|
|
||||||
// Key for preference store
|
// Key for preference store
|
||||||
private LanguagePreferences languagePreferences;
|
|
||||||
private String preferencesKey;
|
private String preferencesKey;
|
||||||
|
|
||||||
// Default Token for the text attributes
|
// Default Token for the text attributes
|
||||||
@@ -47,21 +47,22 @@ final class LanguageRuleBasedScanner extends RuleBasedScanner {
|
|||||||
* Creates a new instance. Called by {@link LanguageSourceViewerConfiguration}.
|
* Creates a new instance. Called by {@link LanguageSourceViewerConfiguration}.
|
||||||
*
|
*
|
||||||
* @param languagePreferences The language preferences, not <code>null</code>.
|
* @param languagePreferences The language preferences, not <code>null</code>.
|
||||||
* @param preferencesKey The preference key to listen to for text attribute
|
* @param textAttributeName The text attribute name to listen to for text
|
||||||
* changes, not <code>null</code>.
|
* attribute changes, not <code>null</code>. See
|
||||||
|
* {@link LanguagePreferencesConstants}
|
||||||
*/
|
*/
|
||||||
LanguageRuleBasedScanner(LanguagePreferences languagePreferences, String preferencesKey) {
|
LanguageRuleBasedScanner(LanguagePreferences languagePreferences, String textAttributeName) {
|
||||||
|
|
||||||
if (languagePreferences == null) {
|
if (languagePreferences == null) {
|
||||||
throw new IllegalArgumentException("Parameter 'language' must not be null.");
|
throw new IllegalArgumentException("Parameter 'language' must not be null.");
|
||||||
}
|
}
|
||||||
if (preferencesKey == null) {
|
if (textAttributeName == null) {
|
||||||
throw new IllegalArgumentException("Parameter 'preferencesKey' must not be null.");
|
throw new IllegalArgumentException("Parameter 'textAttributeName' must not be null.");
|
||||||
}
|
}
|
||||||
this.languagePreferences = languagePreferences;
|
this.preferencesKey = LanguagePreferencesConstants.getPreferencesKey(languagePreferences.getLanguage(),
|
||||||
this.preferencesKey = preferencesKey;
|
textAttributeName);
|
||||||
|
|
||||||
defaultToken = new Token(languagePreferences.getEditorTextAttribute(preferencesKey));
|
defaultToken = new Token(languagePreferences.getEditorTextAttribute(textAttributeName));
|
||||||
|
|
||||||
super.setDefaultReturnToken(defaultToken);
|
super.setDefaultReturnToken(defaultToken);
|
||||||
}
|
}
|
||||||
@@ -91,10 +92,9 @@ final class LanguageRuleBasedScanner extends RuleBasedScanner {
|
|||||||
throw new IllegalArgumentException("Parameter 'changedPropertyNames' must not be null.");
|
throw new IllegalArgumentException("Parameter 'changedPropertyNames' must not be null.");
|
||||||
}
|
}
|
||||||
boolean refresh = false;
|
boolean refresh = false;
|
||||||
if (preferences.getLanguage().equals(languagePreferences.getLanguage())
|
if (changedPropertyNames.contains(preferencesKey)) {
|
||||||
&& changedPropertyNames.contains(preferencesKey)) {
|
|
||||||
TextAttributeConverter.dispose((TextAttribute) defaultToken.getData());
|
TextAttributeConverter.dispose((TextAttribute) defaultToken.getData());
|
||||||
defaultToken.setData(preferences.getEditorTextAttribute(preferencesKey));
|
defaultToken.setData(preferences.getLanguagesPreferences().getEditorTextAttribute(preferencesKey));
|
||||||
refresh = true;
|
refresh = true;
|
||||||
}
|
}
|
||||||
return refresh;
|
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) {
|
if (textAttributeName == null) {
|
||||||
throw new IllegalArgumentException("Parameter 'textAttributeName' must not be null.");
|
throw new IllegalArgumentException("Parameter 'textAttributeName' must not be null.");
|
||||||
}
|
}
|
||||||
LanguagePreferences preferences;
|
LanguagePreferences preferences = editor.getLanguagePreferences();
|
||||||
Token token;
|
String preferencesKey = LanguagePreferencesConstants.getPreferencesKey(preferences.getLanguage(),
|
||||||
preferences = editor.getLanguagePreferences();
|
textAttributeName);
|
||||||
token = new Token(preferences.getEditorTextAttribute(textAttributeName));
|
Token token = new Token(preferences.getEditorTextAttribute(textAttributeName));
|
||||||
tokens.put(textAttributeName, token);
|
tokens.put(preferencesKey, token);
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -498,7 +499,7 @@ final class LanguageSourceScanner extends RuleBasedScanner {
|
|||||||
Token token = tokens.get(propertyName);
|
Token token = tokens.get(propertyName);
|
||||||
if (token != null) {
|
if (token != null) {
|
||||||
TextAttributeConverter.dispose((TextAttribute) token.getData());
|
TextAttributeConverter.dispose((TextAttribute) token.getData());
|
||||||
token.setData(preferences.getEditorTextAttribute(propertyName));
|
token.setData(preferences.getLanguagesPreferences().getEditorTextAttribute(propertyName));
|
||||||
refresh = true;
|
refresh = true;
|
||||||
|
|
||||||
} else if (LanguagePreferencesConstants.isCompilerTargetName(propertyName)) {
|
} else if (LanguagePreferencesConstants.isCompilerTargetName(propertyName)) {
|
||||||
|
@@ -40,7 +40,6 @@ public final class LanguagePreferences {
|
|||||||
*/
|
*/
|
||||||
private LanguagesPreferences languagesPreferences;
|
private LanguagesPreferences languagesPreferences;
|
||||||
private Language language;
|
private Language language;
|
||||||
private String languagePrefix;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by {@link AbstractIDEPlugin} only.
|
* Created by {@link AbstractIDEPlugin} only.
|
||||||
@@ -56,7 +55,10 @@ public final class LanguagePreferences {
|
|||||||
}
|
}
|
||||||
this.languagesPreferences = languagesPreferences;
|
this.languagesPreferences = languagesPreferences;
|
||||||
this.language = language;
|
this.language = language;
|
||||||
this.languagePrefix=language.name().toLowerCase()+".";
|
}
|
||||||
|
|
||||||
|
public LanguagesPreferences getLanguagesPreferences() {
|
||||||
|
return languagesPreferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Language getLanguage() {
|
public Language getLanguage() {
|
||||||
@@ -111,14 +113,16 @@ public final class LanguagePreferences {
|
|||||||
* the default value <code>false</code> if there is no preference with the given
|
* 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.
|
* 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.
|
* @return The preference value.
|
||||||
*/
|
*/
|
||||||
boolean getBoolean(String name) {
|
boolean getBoolean(String preferencesKeySuffix) {
|
||||||
if (name == null) {
|
if (preferencesKeySuffix == null) {
|
||||||
throw new IllegalArgumentException("Parameter 'name' must not be 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
|
* there is no preference with the given name, or if the current value cannot be
|
||||||
* treated as a string.
|
* 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>.
|
* @return The preference value, may be empty, not <code>null</code>.
|
||||||
*/
|
*/
|
||||||
String getString(String name) {
|
String getString(String preferencesKeySuffix) {
|
||||||
if (name == null) {
|
if (preferencesKeySuffix == null) {
|
||||||
throw new IllegalArgumentException("Parameter 'name' must not be 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.
|
* Gets the text attribute for a token type.
|
||||||
*
|
*
|
||||||
* @param name The name of the preferences for the token type, see
|
* @param textAttributeName The suffix of the preferences for the token type,
|
||||||
* {@link LanguagePreferencesConstants}.
|
* see {@link LanguagePreferencesConstants}.
|
||||||
*
|
*
|
||||||
* @return The text attribute, not <code>null</code>.
|
* @return The text attribute, not <code>null</code>.
|
||||||
*/
|
*/
|
||||||
public TextAttribute getEditorTextAttribute(String name) {
|
public TextAttribute getEditorTextAttribute(String textAttributeName) {
|
||||||
if (name == null) {
|
if (textAttributeName == null) {
|
||||||
throw new IllegalArgumentException("Parameter 'name' must not be 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;
|
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
|
* @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$
|
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
|
* Get list of all preferences keys that depend on the global JFact text font
|
||||||
* setting.
|
* setting.
|
||||||
@@ -133,40 +146,45 @@ public final class LanguagePreferencesConstants {
|
|||||||
List<TextAttributeDefinition> result = new ArrayList<TextAttributeDefinition>();
|
List<TextAttributeDefinition> result = new ArrayList<TextAttributeDefinition>();
|
||||||
|
|
||||||
// Comments and literals
|
// 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));
|
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));
|
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));
|
Texts.PREFERENCES_TEXT_ATTRIBUTE_STRING_NAME));
|
||||||
|
|
||||||
switch (language) {
|
switch (language) {
|
||||||
case ASM: {
|
case ASM: {
|
||||||
|
|
||||||
// Built-in
|
// 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));
|
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));
|
Texts.PREFERENCES_TEXT_ATTRIBUTE_OPCODE_LEGAL_NAME));
|
||||||
result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_OPCODE_LEGAL,
|
result.add(new TextAttributeDefinition(getPreferencesKey(language, EDITOR_TEXT_ATTRIBUTE_OPCODE_PSEUDO),
|
||||||
Texts.PREFERENCES_TEXT_ATTRIBUTE_OPCODE_LEGAL_NAME));
|
|
||||||
result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_OPCODE_PSEUDO,
|
|
||||||
Texts.PREFERENCES_TEXT_ATTRIBUTE_OPCODE_PSEUDO_NAME));
|
Texts.PREFERENCES_TEXT_ATTRIBUTE_OPCODE_PSEUDO_NAME));
|
||||||
|
|
||||||
// Identifiers
|
// 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));
|
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));
|
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));
|
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));
|
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));
|
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));
|
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));
|
Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_STRUCTURE_DEFINITION_SECTION));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -175,15 +193,18 @@ public final class LanguagePreferencesConstants {
|
|||||||
case PAS: {
|
case PAS: {
|
||||||
|
|
||||||
// Built-in
|
// 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));
|
Texts.PREFERENCES_TEXT_ATTRIBUTE_DIRECTIVE));
|
||||||
|
|
||||||
// Identifiers
|
// 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));
|
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));
|
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));
|
Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_STRUCTURE_DEFINITION_SECTION));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@@ -58,8 +58,8 @@ import org.eclipse.ui.model.WorkbenchViewerComparator;
|
|||||||
|
|
||||||
import com.wudsn.ide.base.common.ProcessWithLogs;
|
import com.wudsn.ide.base.common.ProcessWithLogs;
|
||||||
import com.wudsn.ide.base.gui.SWTFactory;
|
import com.wudsn.ide.base.gui.SWTFactory;
|
||||||
import com.wudsn.ide.lng.LanguagePlugin;
|
|
||||||
import com.wudsn.ide.lng.Language;
|
import com.wudsn.ide.lng.Language;
|
||||||
|
import com.wudsn.ide.lng.LanguagePlugin;
|
||||||
import com.wudsn.ide.lng.Texts;
|
import com.wudsn.ide.lng.Texts;
|
||||||
import com.wudsn.ide.lng.compiler.CompilerDefinition;
|
import com.wudsn.ide.lng.compiler.CompilerDefinition;
|
||||||
import com.wudsn.ide.lng.compiler.CompilerRegistry;
|
import com.wudsn.ide.lng.compiler.CompilerRegistry;
|
||||||
@@ -121,11 +121,6 @@ public abstract class LanguagePreferencesPage extends FieldEditorPreferencePage
|
|||||||
*/
|
*/
|
||||||
private String activeCompilerId;
|
private String activeCompilerId;
|
||||||
|
|
||||||
/**
|
|
||||||
* The list of all text attributes and the corresponding preferences keys.
|
|
||||||
*/
|
|
||||||
private String[][] textAttributeListItemKeys;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List for text attribute items.
|
* List for text attribute items.
|
||||||
*/
|
*/
|
||||||
@@ -163,37 +158,6 @@ public abstract class LanguagePreferencesPage extends FieldEditorPreferencePage
|
|||||||
plugin = LanguagePlugin.getInstance();
|
plugin = LanguagePlugin.getInstance();
|
||||||
setPreferenceStore(plugin.getPreferenceStore());
|
setPreferenceStore(plugin.getPreferenceStore());
|
||||||
changedPropertyNames = new TreeSet<String>();
|
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
|
@Override
|
||||||
@@ -396,14 +360,10 @@ public abstract class LanguagePreferencesPage extends FieldEditorPreferencePage
|
|||||||
textAttributeListItems = new ArrayList<TextAttributeListItem>(textAttributeDefinitions.size());
|
textAttributeListItems = new ArrayList<TextAttributeListItem>(textAttributeDefinitions.size());
|
||||||
|
|
||||||
for (TextAttributeDefinition textAttributeDefinition : textAttributeDefinitions) {
|
for (TextAttributeDefinition textAttributeDefinition : textAttributeDefinitions) {
|
||||||
String data;
|
String data = getPreferenceStore().getString(textAttributeDefinition.getPreferencesKey());
|
||||||
TextAttribute textAttribute;
|
TextAttribute textAttribute = TextAttributeConverter.fromString(data);
|
||||||
TextAttributeListItem item;
|
|
||||||
|
|
||||||
data = getPreferenceStore().getString(textAttributeDefinition.getPreferencesKey());
|
TextAttributeListItem item = new TextAttributeListItem(textAttributeDefinition);
|
||||||
textAttribute = TextAttributeConverter.fromString(data);
|
|
||||||
|
|
||||||
item = new TextAttributeListItem(textAttributeDefinition);
|
|
||||||
item.setTextAttribute(textAttribute);
|
item.setTextAttribute(textAttribute);
|
||||||
textAttributeListItems.add(item);
|
textAttributeListItems.add(item);
|
||||||
}
|
}
|
||||||
@@ -510,7 +470,10 @@ public abstract class LanguagePreferencesPage extends FieldEditorPreferencePage
|
|||||||
public boolean performOk() {
|
public boolean performOk() {
|
||||||
if (super.performOk()) {
|
if (super.performOk()) {
|
||||||
saveChanges();
|
saveChanges();
|
||||||
|
plugin.log("Language preferences changed for language '{0}': {1}",
|
||||||
|
new Object[] { language, String.join(",", changedPropertyNames) });
|
||||||
plugin.firePreferencesChangeEvent(language, changedPropertyNames);
|
plugin.firePreferencesChangeEvent(language, changedPropertyNames);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -527,8 +490,9 @@ public abstract class LanguagePreferencesPage extends FieldEditorPreferencePage
|
|||||||
super.performDefaults();
|
super.performDefaults();
|
||||||
|
|
||||||
IPreferenceStore preferencesStore = getPreferenceStore();
|
IPreferenceStore preferencesStore = getPreferenceStore();
|
||||||
for (int i = 0, n = textAttributeListItemKeys.length; i < n; i++) {
|
for (TextAttributeListItem listItem : textAttributeListItems) {
|
||||||
String key = textAttributeListItemKeys[i][1];
|
|
||||||
|
String key = listItem.getDefinition().getPreferencesKey();
|
||||||
preferencesStore.setValue(key, preferencesStore.getDefaultString(key));
|
preferencesStore.setValue(key, preferencesStore.getDefaultString(key));
|
||||||
addChangedProperty(key);
|
addChangedProperty(key);
|
||||||
}
|
}
|
||||||
|
@@ -24,6 +24,7 @@ import org.eclipse.jface.text.TextAttribute;
|
|||||||
|
|
||||||
import com.wudsn.ide.base.common.AbstractIDEPlugin;
|
import com.wudsn.ide.base.common.AbstractIDEPlugin;
|
||||||
import com.wudsn.ide.lng.Language;
|
import com.wudsn.ide.lng.Language;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Facade class for typed access to the plugin preferences.
|
* Facade class for typed access to the plugin preferences.
|
||||||
*
|
*
|
||||||
@@ -48,8 +49,6 @@ public final class LanguagesPreferences {
|
|||||||
this.preferenceStore = preferenceStore;
|
this.preferenceStore = preferenceStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the preferences for a language.
|
* Gets the preferences for a language.
|
||||||
*
|
*
|
||||||
@@ -62,25 +61,23 @@ public final class LanguagesPreferences {
|
|||||||
throw new IllegalArgumentException("Parameter 'language' must not be null.");
|
throw new IllegalArgumentException("Parameter 'language' must not be null.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return new LanguagePreferences(this, language);
|
return new LanguagePreferences(this, language);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the current value of the boolean preference with the given name. Returns
|
* 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 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.
|
* 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.
|
* @return The preference value.
|
||||||
*/
|
*/
|
||||||
boolean getBoolean(String name) {
|
boolean getBoolean(String preferencesKey) {
|
||||||
if (name == null) {
|
if (preferencesKey == null) {
|
||||||
throw new IllegalArgumentException("Parameter 'key' must not be 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
|
* there is no preference with the given name, or if the current value cannot be
|
||||||
* treated as a string.
|
* 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>.
|
* @return The preference value, may be empty, not <code>null</code>.
|
||||||
*/
|
*/
|
||||||
String getString(String name) {
|
String getString(String preferencesKey) {
|
||||||
if (name == null) {
|
if (preferencesKey == null) {
|
||||||
throw new IllegalArgumentException("Parameter 'key' must not be null.");
|
throw new IllegalArgumentException("Parameter 'preferencesKey' must not be null.");
|
||||||
}
|
}
|
||||||
String result;
|
String result;
|
||||||
result = preferenceStore.getString(name);
|
result = preferenceStore.getString(preferencesKey);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
result = "";
|
result = "";
|
||||||
} else {
|
} else {
|
||||||
@@ -110,18 +107,17 @@ public final class LanguagesPreferences {
|
|||||||
/**
|
/**
|
||||||
* Gets the text attribute for a token type.
|
* Gets the text attribute for a token type.
|
||||||
*
|
*
|
||||||
* @param name The name of the preferences for the token type, see
|
* @param preferencesKey The key of the preference, not <code>null</code>.
|
||||||
* {@link LanguagePreferencesConstants}.
|
|
||||||
*
|
*
|
||||||
* @return The text attribute, not <code>null</code>.
|
* @return The text attribute, not <code>null</code>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
TextAttribute getEditorTextAttribute(String name) {
|
public TextAttribute getEditorTextAttribute(String preferencesKey) {
|
||||||
if (name == null) {
|
if (preferencesKey == null) {
|
||||||
throw new IllegalArgumentException("Parameter 'name' must not be null.");
|
throw new IllegalArgumentException("Parameter 'preferencesKey' must not be null.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return TextAttributeConverter.fromString(preferenceStore.getString(name));
|
return TextAttributeConverter.fromString(preferenceStore.getString(preferencesKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user