From d91abbf3e1403038231016c4fe55d1a48583a366 Mon Sep 17 00:00:00 2001 From: Peter Dell Date: Sat, 10 Sep 2022 16:56:58 +0200 Subject: [PATCH] Adapt preferences and text attributes from "asm" to "lng" --- .../src/com/wudsn/ide/lng/LanguagePlugin.java | 10 +- .../wudsn/ide/lng/editor/LanguageEditor.java | 13 +- .../ide/lng/editor/LanguageSourceScanner.java | 4 +- .../LanguageSourceViewerConfiguration.java | 2 +- .../lng/preferences/LanguagePreferences.java | 8 +- .../LanguagePreferencesCompilersPage.java | 11 +- .../LanguagePreferencesConstants.java | 99 ++++++++++---- .../LanguagePreferencesInitializer.java | 124 +++++++++--------- .../preferences/LanguagePreferencesPage.java | 15 ++- .../lng/preferences/LanguagesPreferences.java | 2 + .../preferences/TextAttributeDefinition.java | 65 +++++++++ .../preferences/TextAttributeListItem.java | 32 ++--- .../TextAttributeListItemProvider.java | 2 +- 13 files changed, 251 insertions(+), 136 deletions(-) create mode 100644 com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/TextAttributeDefinition.java diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/LanguagePlugin.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/LanguagePlugin.java index 743b7eac..69c8b20a 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/LanguagePlugin.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/LanguagePlugin.java @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.TreeSet; import org.eclipse.core.runtime.ListenerList; import org.eclipse.core.runtime.QualifiedName; @@ -41,6 +42,7 @@ import com.wudsn.ide.lng.preferences.LanguagePreferences; import com.wudsn.ide.lng.preferences.LanguagePreferencesChangeListener; import com.wudsn.ide.lng.preferences.LanguagePreferencesConstants; import com.wudsn.ide.lng.preferences.LanguagesPreferences; +import com.wudsn.ide.lng.preferences.TextAttributeDefinition; import com.wudsn.ide.lng.runner.RunnerRegistry; /** @@ -143,7 +145,13 @@ public final class LanguagePlugin extends AbstractIDEPlugin { if (event.getProperty().equals(JFaceResources.TEXT_FONT) || event.getProperty().equals(BLOCK_SELECTION_MODE_FONT)) { for (Language language : languages) { - firePreferencesChangeEvent(language, LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTES); + List textAttributeDefinitions = LanguagePreferencesConstants + .getTextAttributeDefinitions(language); + Set changedPropertyNames = new TreeSet(); + for (TextAttributeDefinition textAttributeDefinition : textAttributeDefinitions) { + changedPropertyNames.add(textAttributeDefinition.getPreferencesKey()); + } + firePreferencesChangeEvent(language, changedPropertyNames); } } diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditor.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditor.java index 32797745..e06069b3 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditor.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageEditor.java @@ -413,21 +413,22 @@ public abstract class LanguageEditor extends TextEditor { public final void updateIdentifiers(CompilerSourceFile compilerSourceFile) { Profiler profiler = new Profiler(this.getClass()); - LanguageSourceViewerConfiguration asvc; - LanguageSourceScanner ais; - asvc = (LanguageSourceViewerConfiguration) getSourceViewerConfiguration(); - ais = asvc.getInstructionScanner(); - List newIdentifiers; if (compilerSourceFile == null) { newIdentifiers = Collections.emptyList(); } else { newIdentifiers = compilerSourceFile.getIdentifiers(); } + + LanguageSourceViewerConfiguration asvc; + LanguageSourceScanner ais; + asvc = (LanguageSourceViewerConfiguration) getSourceViewerConfiguration(); + ais = asvc.getInstructionScanner(); + ais.setIdentifiers(newIdentifiers); profiler.begin("refreshSourceViewer"); - // refreshSourceViewer(); + // refreshSourceViewer(); TODO Required? profiler.end("refreshSourceViewer"); } diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageSourceScanner.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageSourceScanner.java index 13fa5633..7909755b 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageSourceScanner.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageSourceScanner.java @@ -203,7 +203,7 @@ final class LanguageSourceScanner extends RuleBasedScanner { throw new RuntimeException("Unexpected identifier element type " + element.getType() + " - " + element.getTreePath() + "."); } - if (element.getDescription().startsWith("@style=(")) { + if (element.getDescription().startsWith("@style=(")) { // TODO: Test and document @style annotation String value = element.getDescription().substring(8); int index = value.indexOf(")"); if (index > 0) { @@ -220,7 +220,7 @@ final class LanguageSourceScanner extends RuleBasedScanner { } } } - System.out.println("" + this + ":" + state.identifierWordTokens.size()); + System.out.println("" + this + ":" + state.identifierWordTokens.size() + " identifier word tokens set: "+ state.identifierWordTokens); // TODO } /* diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageSourceViewerConfiguration.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageSourceViewerConfiguration.java index 5c3f786a..db7309bd 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageSourceViewerConfiguration.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/editor/LanguageSourceViewerConfiguration.java @@ -208,7 +208,7 @@ final class LanguageSourceViewerConfiguration extends TextSourceViewerConfigurat MonoReconciler reconciler = new MonoReconciler(reconcilingStrategy, false); reconciler.setProgressMonitor(new NullProgressMonitor()); - reconciler.setDelay(500); + reconciler.setDelay(500); // TODO Compute delay based on size of content on the source viewer (sourceViewer.getDocument().getLength()) or the fact that the parser is still parsing return reconciler; } diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagePreferences.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagePreferences.java index 8455bf0b..0a9e0add 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagePreferences.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagePreferences.java @@ -40,6 +40,7 @@ public final class LanguagePreferences { */ private LanguagesPreferences languagesPreferences; private Language language; + private String languagePrefix; /** * Created by {@link AbstractIDEPlugin} only. @@ -55,6 +56,7 @@ public final class LanguagePreferences { } this.languagesPreferences = languagesPreferences; this.language = language; + this.languagePrefix=language.name().toLowerCase()+"."; } public Language getLanguage() { @@ -116,7 +118,7 @@ public final class LanguagePreferences { if (name == null) { throw new IllegalArgumentException("Parameter 'name' must not be null."); } - return languagesPreferences.getBoolean(language.name() + "." + name); + return languagesPreferences.getBoolean(languagePrefix+ name); } /** @@ -132,7 +134,7 @@ public final class LanguagePreferences { if (name == null) { throw new IllegalArgumentException("Parameter 'name' must not be null."); } - return languagesPreferences.getString(language.name() + "." + name); + return languagesPreferences.getString(languagePrefix + name); } /** @@ -147,7 +149,7 @@ public final class LanguagePreferences { if (name == null) { throw new IllegalArgumentException("Parameter 'name' must not be null."); } - return languagesPreferences.getEditorTextAttribute(language.name() + "." + name); + return languagesPreferences.getEditorTextAttribute(languagePrefix+ name); } diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagePreferencesCompilersPage.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagePreferencesCompilersPage.java index 5b973c47..e2371752 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagePreferencesCompilersPage.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagePreferencesCompilersPage.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import java.util.TreeMap; +import org.eclipse.core.resources.IMarker; import org.eclipse.jface.fieldassist.ControlDecoration; import org.eclipse.jface.preference.BooleanFieldEditor; import org.eclipse.jface.preference.ComboFieldEditor; @@ -56,6 +57,7 @@ import com.wudsn.ide.base.common.TextUtility; import com.wudsn.ide.base.gui.SWTFactory; import com.wudsn.ide.base.hardware.Hardware; import com.wudsn.ide.lng.LanguagePlugin; +import com.wudsn.ide.lng.LanguageUtility; import com.wudsn.ide.lng.Target; import com.wudsn.ide.lng.Texts; import com.wudsn.ide.lng.compiler.CompilerDefinition; @@ -437,7 +439,12 @@ public abstract class LanguagePreferencesCompilersPage extends FieldEditorPrefer Composite disabledControl = SWTFactory.createComposite(tabFolder, 1, 1, GridData.FILL_BOTH); label = new Label(disabledControl, SWT.NONE); - label.setText(TextUtility.format(Texts.MESSAGE_E100, compilerDefinition.getName())); + + // ERROR: Path to {0} '{1}' executable is not set in the '{2}' preferences. + String compilerDefinitionText = LanguageUtility.getCompilerTextLower(compilerDefinition.getLanguage()); + String compilerPreferencesText = LanguageUtility.getCompilerPreferencesText(compilerDefinition.getLanguage()); + label.setText(TextUtility.format(Texts.MESSAGE_E100, compilerDefinitionText, compilerDefinition.getName(), + compilerPreferencesText)); Tab tab = new Tab(compilerDefinition, tabs.size(), tabItem, tabContent, disabledControl, controlDecorations); tabs.put(compilerId, tab); @@ -448,8 +455,6 @@ public abstract class LanguagePreferencesCompilersPage extends FieldEditorPrefer setTabStatus(tab); } - // tabFolder.layout(); - // tabFolder.getParent().getParent().redraw(); } private void setTabStatus(Tab tab) { diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagePreferencesConstants.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagePreferencesConstants.java index e1c4b312..f51c4e31 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagePreferencesConstants.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagePreferencesConstants.java @@ -19,10 +19,12 @@ R * Copyright (C) 2009 - 2021 Pete package com.wudsn.ide.lng.preferences; -import java.util.HashSet; -import java.util.Set; +import java.util.ArrayList; +import java.util.List; import com.wudsn.ide.base.hardware.Hardware; +import com.wudsn.ide.lng.Language; +import com.wudsn.ide.lng.Texts; /** * Constants for preferences. @@ -107,12 +109,6 @@ public final class LanguagePreferencesConstants { */ public static final String EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_PROCEDURE_DEFINITION_SECTION = "editor.text.attribute.identifier.procedure"; //$NON-NLS-1$ - /** - * Set of all preferences keys that depend on the global JFact text font - * setting. - */ - public static final Set EDITOR_TEXT_ATTRIBUTES; - /** * Preference key for default case for content assist. */ @@ -126,24 +122,77 @@ public final class LanguagePreferencesConstants { static final String EDITOR_COMPILE_COMMAND_POSITIONING_MODE = "editor.compile.command.positioning.mode"; //$NON-NLS-1$ /** - * Static initialization. + * Get list of all preferences keys that depend on the global JFact text font + * setting. */ - static { - EDITOR_TEXT_ATTRIBUTES = new HashSet(); - EDITOR_TEXT_ATTRIBUTES.add(EDITOR_TEXT_ATTRIBUTE_DIRECTVE); - EDITOR_TEXT_ATTRIBUTES.add(EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_ENUM_DEFINITION_SECTION); - EDITOR_TEXT_ATTRIBUTES.add(EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_EQUATE); - EDITOR_TEXT_ATTRIBUTES.add(EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_LABEL); - EDITOR_TEXT_ATTRIBUTES.add(EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_LOCAL_SECTION); - EDITOR_TEXT_ATTRIBUTES.add(EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_MACRO_DEFINITION_SECTION); - EDITOR_TEXT_ATTRIBUTES.add(EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_PROCEDURE_DEFINITION_SECTION); - EDITOR_TEXT_ATTRIBUTES.add(EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_STRUCTURE_DEFINITION_SECTION); - EDITOR_TEXT_ATTRIBUTES.add(EDITOR_TEXT_ATTRIBUTE_NUMBER); - EDITOR_TEXT_ATTRIBUTES.add(EDITOR_TEXT_ATTRIBUTE_OPCODE_ILLEGAL); - EDITOR_TEXT_ATTRIBUTES.add(EDITOR_TEXT_ATTRIBUTE_OPCODE_LEGAL); - EDITOR_TEXT_ATTRIBUTES.add(EDITOR_TEXT_ATTRIBUTE_OPCODE_PSEUDO); - EDITOR_TEXT_ATTRIBUTES.add(EDITOR_TEXT_ATTRIBUTE_STRING); - EDITOR_TEXT_ATTRIBUTES.add(EDITOR_TEXT_ATTRIBUTE_COMMENT); + public static List getTextAttributeDefinitions(Language language) { + if (language == null) { + throw new IllegalArgumentException("Parameter 'language' must not be null."); + } + + List result = new ArrayList(); + + // Comments and literals + result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_COMMENT, + Texts.PREFERENCES_TEXT_ATTRIBUTE_COMMENT_NAME)); + result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_NUMBER, + Texts.PREFERENCES_TEXT_ATTRIBUTE_NUMBER_NAME)); + result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_STRING, + Texts.PREFERENCES_TEXT_ATTRIBUTE_STRING_NAME)); + + switch (language) { + case ASM: { + + // Built-in + result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_DIRECTVE, + Texts.PREFERENCES_TEXT_ATTRIBUTE_DIRECTIVE)); + result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_OPCODE_ILLEGAL, + 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, + Texts.PREFERENCES_TEXT_ATTRIBUTE_OPCODE_PSEUDO_NAME)); + + // Identifiers + result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_ENUM_DEFINITION_SECTION, + Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_ENUM_DEFINITION_SECTION)); + result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_EQUATE, + Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_EQUATE)); + result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_LABEL, + Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_LABEL)); + result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_LOCAL_SECTION, + Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_LOCAL_SECTION)); + result.add(new TextAttributeDefinition(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, + Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_PROCEDURE_DEFINITION_SECTION)); + result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_STRUCTURE_DEFINITION_SECTION, + Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_STRUCTURE_DEFINITION_SECTION)); + break; + + } + + case PAS: { + + // Built-in + result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_DIRECTVE, + Texts.PREFERENCES_TEXT_ATTRIBUTE_DIRECTIVE)); + + // Identifiers + result.add(new TextAttributeDefinition(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, + Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_PROCEDURE_DEFINITION_SECTION)); + result.add(new TextAttributeDefinition(EDITOR_TEXT_ATTRIBUTE_IDENTIFIER_STRUCTURE_DEFINITION_SECTION, + Texts.PREFERENCES_TEXT_ATTRIBUTE_IDENTIFIER_STRUCTURE_DEFINITION_SECTION)); + break; + + } + default: + throw new IllegalArgumentException("Unsupported language " + language + "."); + } + + return result; } /** diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagePreferencesInitializer.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagePreferencesInitializer.java index 76d448ec..dc3902e5 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagePreferencesInitializer.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagePreferencesInitializer.java @@ -46,100 +46,96 @@ import com.wudsn.ide.lng.runner.RunnerId; */ public final class LanguagePreferencesInitializer extends AbstractPreferenceInitializer { + private IPreferenceStore store; + /** * Creation must be public default. */ public LanguagePreferencesInitializer() { + store = LanguagePlugin.getInstance().getPreferenceStore(); + + } + + private void setDefault(Language language, String key, String value) { + store.setDefault(language.name().toLowerCase() + "." + key, value); + } + + private void setDefault(Language language, String key, int r, int g, int b, int style) { + // Editor. + Display display = Display.getCurrent(); + TextAttribute textAttribute = new TextAttribute(new Color(display, r, g, b), null, style); + store.setDefault(language.name().toLowerCase() + "." + key, TextAttributeConverter.toString(textAttribute)); } @Override public void initializeDefaultPreferences() { - IPreferenceStore store = LanguagePlugin.getInstance().getPreferenceStore(); - initializeEditorPreferences(store); - - initializeCompilerPreferences(store); + initializeLanguage(Language.ASM); + initializeLanguage(Language.PAS); LanguagePlugin.getInstance().savePreferences(); } - private void initializeEditorPreferences(IPreferenceStore store) { - if (store == null) { - throw new IllegalArgumentException("Parameter 'store' must not be null."); + private void initializeLanguage(Language language) { + + if (language == null) { + throw new IllegalArgumentException("Parameter 'language' must not be null."); } - // Editor. - Display display = Display.getCurrent(); + initializeEditorPreferences(language); + initializeCompilerPreferences(language); + } - TextAttribute textAttribute = new TextAttribute(new Color(display, 0, 128, 0), null, SWT.ITALIC); - store.setDefault(LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_COMMENT, - TextAttributeConverter.toString(textAttribute)); - - textAttribute = new TextAttribute(new Color(display, 0, 0, 255), null, SWT.NORMAL); - store.setDefault(LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_STRING, - TextAttributeConverter.toString(textAttribute)); - - textAttribute = new TextAttribute(new Color(display, 0, 0, 255), null, SWT.BOLD); - store.setDefault(LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_NUMBER, - TextAttributeConverter.toString(textAttribute)); - - textAttribute = new TextAttribute(new Color(display, 128, 64, 0), null, SWT.BOLD); - store.setDefault(LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_DIRECTVE, - TextAttributeConverter.toString(textAttribute)); - - textAttribute = new TextAttribute(new Color(display, 0, 0, 128), null, SWT.BOLD); - store.setDefault(LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_OPCODE_LEGAL, - TextAttributeConverter.toString(textAttribute)); - - textAttribute = new TextAttribute(new Color(display, 255, 32, 32), null, SWT.BOLD); - store.setDefault(LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_OPCODE_ILLEGAL, - TextAttributeConverter.toString(textAttribute)); - - textAttribute = new TextAttribute(new Color(display, 32, 128, 32), null, SWT.BOLD); - store.setDefault(LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_OPCODE_PSEUDO, - TextAttributeConverter.toString(textAttribute)); + private void initializeEditorPreferences(Language language) { + if (language == null) { + throw new IllegalArgumentException("Parameter 'language' must not be null."); + } + setDefault(language, LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_COMMENT, 0, 128, 0, SWT.ITALIC); + setDefault(language, LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_DIRECTVE, 128, 64, 0, SWT.BOLD); + setDefault(language, LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_NUMBER, 0, 0, 255, SWT.BOLD); + setDefault(language, LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_OPCODE_LEGAL, 0, 0, 128, SWT.BOLD); + setDefault(language, LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_OPCODE_ILLEGAL, 255, 32, 32, SWT.BOLD); + setDefault(language, LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_OPCODE_PSEUDO, 32, 128, 32, SWT.BOLD); + setDefault(language, LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_STRING, 0, 0, 255, SWT.NORMAL); // Content assist. - store.setDefault(LanguagePreferencesConstants.EDITOR_CONTENT_ASSIST_PROCESSOR_DEFAULT_CASE, + setDefault(language, LanguagePreferencesConstants.EDITOR_CONTENT_ASSIST_PROCESSOR_DEFAULT_CASE, LanguageContentAssistProcessorDefaultCase.LOWER_CASE); // Compiling. - store.setDefault(LanguagePreferencesConstants.EDITOR_COMPILE_COMMAND_POSITIONING_MODE, + setDefault(language, + LanguagePreferencesConstants.EDITOR_COMPILE_COMMAND_POSITIONING_MODE, LanguageEditorCompileCommandPositioningMode.FIRST_ERROR_OR_WARNING); } - private void initializeCompilerPreferences(IPreferenceStore store) { - if (store == null) { - throw new IllegalArgumentException("Parameter 'store' must not be null."); + private void initializeCompilerPreferences(Language language) { + if (language == null) { + throw new IllegalArgumentException("Parameter 'language' must not be null."); } - LanguagePlugin languagePlugin = LanguagePlugin.getInstance(); CompilerRegistry compilerRegistry = languagePlugin.getCompilerRegistry(); - for (Language language : languagePlugin.getLanguages()) { + List compilerDefinitions = compilerRegistry.getCompilerDefinitions(language); + for (CompilerDefinition compilerDefinition : compilerDefinitions) { + String compilerId; + String name; + compilerId = compilerDefinition.getId(); - List compilerDefinitions = compilerRegistry.getCompilerDefinitions(language); - for (CompilerDefinition compilerDefinition : compilerDefinitions) { - String compilerId; - String name; - compilerId = compilerDefinition.getId(); - - for (Hardware hardware : Hardware.values()) { - if (hardware.equals(Hardware.GENERIC)) { - continue; - } - store.setDefault(LanguagePreferencesConstants.getCompilerTargetName(compilerId, hardware), - compilerDefinition.getSupportedTargets().get(0).toString()); - - name = LanguagePreferencesConstants.getCompilerParametersName(compilerId, hardware); - store.setDefault(name, compilerDefinition.getDefaultParameters()); - name = LanguagePreferencesConstants.getCompilerOutputFolderModeName(compilerId, hardware); - store.setDefault(name, CompilerOutputFolderMode.TEMP_FOLDER); - name = LanguagePreferencesConstants.getCompilerOutputFileExtensionName(compilerId, hardware); - store.setDefault(name, HardwareUtility.getDefaultFileExtension(hardware)); - name = LanguagePreferencesConstants.getCompilerRunnerIdName(compilerId, hardware); - store.setDefault(name, RunnerId.DEFAULT_APPLICATION); + for (Hardware hardware : Hardware.values()) { + if (hardware.equals(Hardware.GENERIC)) { + continue; } + store.setDefault(LanguagePreferencesConstants.getCompilerTargetName(compilerId, hardware), + compilerDefinition.getSupportedTargets().get(0).toString()); + name = LanguagePreferencesConstants.getCompilerParametersName(compilerId, hardware); + store.setDefault(name, compilerDefinition.getDefaultParameters()); + name = LanguagePreferencesConstants.getCompilerOutputFolderModeName(compilerId, hardware); + store.setDefault(name, CompilerOutputFolderMode.TEMP_FOLDER); + name = LanguagePreferencesConstants.getCompilerOutputFileExtensionName(compilerId, hardware); + store.setDefault(name, HardwareUtility.getDefaultFileExtension(hardware)); + name = LanguagePreferencesConstants.getCompilerRunnerIdName(compilerId, hardware); + store.setDefault(name, RunnerId.DEFAULT_APPLICATION); } + } } } diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagePreferencesPage.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagePreferencesPage.java index 31363353..75e89275 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagePreferencesPage.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagePreferencesPage.java @@ -94,7 +94,7 @@ public abstract class LanguagePreferencesPage extends FieldEditorPreferencePage } updateItem(item); textAttributeListItemsViewer.refresh(); - addChangedProperty(item.getPreferencesKey()); + addChangedProperty(item.getDefinition().getPreferencesKey()); } abstract protected void updateItem(TextAttributeListItem item); @@ -163,6 +163,7 @@ public abstract class LanguagePreferencesPage extends FieldEditorPreferencePage plugin = LanguagePlugin.getInstance(); setPreferenceStore(plugin.getPreferenceStore()); changedPropertyNames = new TreeSet(); + textAttributeListItemKeys = new String[][] { { Texts.PREFERENCES_TEXT_ATTRIBUTE_COMMENT_NAME, LanguagePreferencesConstants.EDITOR_TEXT_ATTRIBUTE_COMMENT }, @@ -390,17 +391,19 @@ public abstract class LanguagePreferencesPage extends FieldEditorPreferencePage if (textAttributeListItems != null) { throw new IllegalStateException("Attribute 'textAttributeListItems' must be null."); } - textAttributeListItems = new ArrayList(textAttributeListItemKeys.length); + List textAttributeDefinitions = LanguagePreferencesConstants + .getTextAttributeDefinitions(language); + textAttributeListItems = new ArrayList(textAttributeDefinitions.size()); - for (int i = 0, n = textAttributeListItemKeys.length; i < n; i++) { + for (TextAttributeDefinition textAttributeDefinition: textAttributeDefinitions) { String data; TextAttribute textAttribute; TextAttributeListItem item; - data = getPreferenceStore().getString(textAttributeListItemKeys[i][1]); + data = getPreferenceStore().getString(textAttributeDefinition.getPreferencesKey()); textAttribute = TextAttributeConverter.fromString(data); - item = new TextAttributeListItem(textAttributeListItemKeys[i][0], textAttributeListItemKeys[i][1]); + item = new TextAttributeListItem(textAttributeDefinition); item.setTextAttribute(textAttribute); textAttributeListItems.add(item); } @@ -544,7 +547,7 @@ public abstract class LanguagePreferencesPage extends FieldEditorPreferencePage for (TextAttributeListItem listItem : textAttributeListItems) { data = TextAttributeConverter.toString(listItem.getTextAttribute()); - store.setValue(listItem.getPreferencesKey(), data); + store.setValue(listItem.getDefinition().getPreferencesKey(), data); } diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagesPreferences.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagesPreferences.java index 790cdc0e..60397ba6 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagesPreferences.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/LanguagesPreferences.java @@ -114,11 +114,13 @@ public final class LanguagesPreferences { * {@link LanguagePreferencesConstants}. * * @return The text attribute, not null. + * */ TextAttribute getEditorTextAttribute(String name) { if (name == null) { throw new IllegalArgumentException("Parameter 'name' must not be null."); } + return TextAttributeConverter.fromString(preferenceStore.getString(name)); } diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/TextAttributeDefinition.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/TextAttributeDefinition.java new file mode 100644 index 00000000..120f1825 --- /dev/null +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/TextAttributeDefinition.java @@ -0,0 +1,65 @@ +/** + * Copyright (C) 2009 - 2021 Peter Dell + * + * This file is part of WUDSN IDE. + * + * WUDSN IDE is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * WUDSN IDE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WUDSN IDE. If not, see . + */ + +package com.wudsn.ide.lng.preferences; + +/** + * A property key with it's label + * + * @author Peter Dell + */ +public class TextAttributeDefinition { + + /** Color preference key */ + private String preferencesKey; + + /** Display name */ + private String displayName; + + TextAttributeDefinition(String preferencesKey, String displayName) { + if (preferencesKey == null) { + throw new IllegalArgumentException("Parameter 'preferencesKey' must not be null."); + } + if (displayName == null) { + throw new IllegalArgumentException("Parameter 'displayName' must not be null."); + } + + this.displayName = displayName; + this.preferencesKey = preferencesKey; + } + + /** + * Gets the preferences key. + * + * @return The preferences key, not empty and not null. + */ + public String getPreferencesKey() { + return preferencesKey; + } + + /** + * Gets the display name. + * + * @return The display name, not empty and not null. + */ + public String getDisplayName() { + return displayName; + } + +} \ No newline at end of file diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/TextAttributeListItem.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/TextAttributeListItem.java index 7c67fb73..e1aa1f06 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/TextAttributeListItem.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/TextAttributeListItem.java @@ -29,23 +29,16 @@ import org.eclipse.jface.text.TextAttribute; final class TextAttributeListItem { /** Display name */ - private String displayName; - - /** Color preference key */ - private String preferencesKey; - + private TextAttributeDefinition definition; + /** Text attribute */ private TextAttribute textAttribute; - TextAttributeListItem(String displayName, String preferencesKey) { - if (displayName == null) { - throw new IllegalArgumentException("Parameter 'displayName' must not be null."); + TextAttributeListItem(TextAttributeDefinition definition) { + if (definition == null) { + throw new IllegalArgumentException("Parameter 'definition' must not be null."); } - if (preferencesKey == null) { - throw new IllegalArgumentException("Parameter 'preferencesKey' must not be null."); - } - this.displayName = displayName; - this.preferencesKey = preferencesKey; + this.definition = definition; } /** @@ -53,17 +46,8 @@ final class TextAttributeListItem { * * @return The preferences key, not empty and not null. */ - public String getPreferencesKey() { - return preferencesKey; - } - - /** - * Gets the display name. - * - * @return The display name, not empty and not null. - */ - public String getDisplayName() { - return displayName; + public TextAttributeDefinition getDefinition() { + return definition; } /** diff --git a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/TextAttributeListItemProvider.java b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/TextAttributeListItemProvider.java index f1e6978d..eb5ab65c 100644 --- a/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/TextAttributeListItemProvider.java +++ b/com.wudsn.ide.lng/src/com/wudsn/ide/lng/preferences/TextAttributeListItemProvider.java @@ -38,7 +38,7 @@ final class TextAttributeListItemProvider extends LabelProvider implements IColo @Override public String getText(Object element) { - return ((TextAttributeListItem) element).getDisplayName(); + return ((TextAttributeListItem) element).getDefinition().getDisplayName(); } /**