Adapt preferences and text attributes from "asm" to "lng"

This commit is contained in:
Peter Dell 2022-09-10 16:56:58 +02:00
parent 6fc93c6cee
commit d91abbf3e1
13 changed files with 251 additions and 136 deletions

View File

@ -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<TextAttributeDefinition> textAttributeDefinitions = LanguagePreferencesConstants
.getTextAttributeDefinitions(language);
Set<String> changedPropertyNames = new TreeSet<String>();
for (TextAttributeDefinition textAttributeDefinition : textAttributeDefinitions) {
changedPropertyNames.add(textAttributeDefinition.getPreferencesKey());
}
firePreferencesChangeEvent(language, changedPropertyNames);
}
}

View File

@ -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<CompilerSourceParserTreeObject> 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");
}

View File

@ -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
}
/*

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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) {

View File

@ -19,10 +19,12 @@ R * Copyright (C) 2009 - 2021 <a href="https://www.wudsn.com" target="_top">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<String> 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<String>();
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<TextAttributeDefinition> getTextAttributeDefinitions(Language language) {
if (language == null) {
throw new IllegalArgumentException("Parameter 'language' must not be null.");
}
List<TextAttributeDefinition> result = new ArrayList<TextAttributeDefinition>();
// 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;
}
/**

View File

@ -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<CompilerDefinition> compilerDefinitions = compilerRegistry.getCompilerDefinitions(language);
for (CompilerDefinition compilerDefinition : compilerDefinitions) {
String compilerId;
String name;
compilerId = compilerDefinition.getId();
List<CompilerDefinition> 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);
}
}
}
}

View File

@ -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<String>();
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<TextAttributeListItem>(textAttributeListItemKeys.length);
List<TextAttributeDefinition> textAttributeDefinitions = LanguagePreferencesConstants
.getTextAttributeDefinitions(language);
textAttributeListItems = new ArrayList<TextAttributeListItem>(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);
}

View File

@ -114,11 +114,13 @@ public final class LanguagesPreferences {
* {@link LanguagePreferencesConstants}.
*
* @return The text attribute, not <code>null</code>.
*
*/
TextAttribute getEditorTextAttribute(String name) {
if (name == null) {
throw new IllegalArgumentException("Parameter 'name' must not be null.");
}
return TextAttributeConverter.fromString(preferenceStore.getString(name));
}

View File

@ -0,0 +1,65 @@
/**
* Copyright (C) 2009 - 2021 <a href="https://www.wudsn.com" target="_top">Peter Dell</a>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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 <code>null</code>.
*/
public String getPreferencesKey() {
return preferencesKey;
}
/**
* Gets the display name.
*
* @return The display name, not empty and not <code>null</code>.
*/
public String getDisplayName() {
return displayName;
}
}

View File

@ -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 <code>null</code>.
*/
public String getPreferencesKey() {
return preferencesKey;
}
/**
* Gets the display name.
*
* @return The display name, not empty and not <code>null</code>.
*/
public String getDisplayName() {
return displayName;
public TextAttributeDefinition getDefinition() {
return definition;
}
/**

View File

@ -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();
}
/**