diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/preferences/PrefUtils.java b/com.archimatetool.editor/src/com/archimatetool/editor/preferences/PrefUtils.java index 4bba1e870..fbe0602d1 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/preferences/PrefUtils.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/preferences/PrefUtils.java @@ -5,13 +5,9 @@ */ package com.archimatetool.editor.preferences; -import java.util.HashMap; -import java.util.Map; - import org.eclipse.core.runtime.preferences.DefaultScope; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.InstanceScope; -import org.osgi.service.prefs.BackingStoreException; import com.archimatetool.editor.utils.PlatformUtils; @@ -24,43 +20,18 @@ @SuppressWarnings("nls") public class PrefUtils { - // Store default preferences before they are mangled by the Workbench Theme helper - private static Map defaultPrefs = new HashMap<>(); - /** * Initialise this now before the workbench starts */ public static void init() { - processDefaultWorkBenchUIPrefss(); - processOtherPrefs(); - } - - /** - * Process any default preferences in the "org.eclipse.ui.workbench" DefaultScope - */ - private static void processDefaultWorkBenchUIPrefss() { IEclipsePreferences defaultWorkBenchUIPrefs = getDefaultUIWorkBenchPrefs(); - if(defaultWorkBenchUIPrefs != null) { - // Store workbench UI prefs before the workbench starts - // Once it's started default font setttings in a preference initialiser are over-written by the Theme manager - try { - for(String key : defaultWorkBenchUIPrefs.keys()) { - defaultPrefs.put(key, defaultWorkBenchUIPrefs.get(key, null)); - } - } - catch(BackingStoreException ex) { - ex.printStackTrace(); - } - // We use Eclipse's org.eclipse.ui.internal.handlers.FullScreenHandler which shows // a popup with a message to tell you this and a "do not show again" checkbox. // This is hard to see and unnecessary, so set the default preference to true now so it doesn't show. defaultWorkBenchUIPrefs.putBoolean("org.eclipse.ui.window.fullscreenmode.donotshowinfoagain", true); } - } - - private static void processOtherPrefs() { + // Mac item heights. // Read the preference setting and set it as a System Property before the workbench Display is created. // We access it via the InstanceScope as that doesn't trigger Archi's PreferenceInitializer. @@ -79,13 +50,6 @@ private static void processOtherPrefs() { preferences.putBoolean("themeEnabled", true); } - /** - * @return a possible value or null from the "org.eclipse.ui.workbench" DefaultScope - */ - public static String getDefaultUIWorkBenchPreference(String key) { - return defaultPrefs.get(key); - } - public static IEclipsePreferences getDefaultUIWorkBenchPrefs() { return DefaultScope.INSTANCE.getNode("org.eclipse.ui.workbench"); } diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/ui/ThemeUtils.java b/com.archimatetool.editor/src/com/archimatetool/editor/ui/ThemeUtils.java index 317044454..c54fd2e45 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/ui/ThemeUtils.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/ui/ThemeUtils.java @@ -31,7 +31,6 @@ import org.eclipse.ui.internal.util.PrefUtil; import org.eclipse.ui.themes.IThemeManager; -import com.archimatetool.editor.preferences.PrefUtils; import com.archimatetool.editor.utils.StringUtils; @@ -271,11 +270,17 @@ public static void setCurrentThemeFont(String fontDefinitionId, FontData fontDat } String preferenceKey = createPreferenceKey(fontDef); + + // Also write a ".default" preference key so that if the user exports Archi's preferences + // They can get both keys to add to their custom preferences file + if(Objects.equals(fontData, defaultFontData)) { // If it's the default, remove it PrefUtil.getInternalPreferenceStore().setToDefault(preferenceKey); + PrefUtil.getInternalPreferenceStore().setToDefault("default." + preferenceKey); } else { PrefUtil.getInternalPreferenceStore().setValue(preferenceKey, fontData.toString()); + PrefUtil.getInternalPreferenceStore().setValue("default." + preferenceKey, fontData.toString()); } } @@ -305,9 +310,9 @@ private static FontRegistry getCurrentThemeFontRegistry() { * Get the default FontData value for a font definition or null */ public static FontData getDefaultThemeFontData(String fontDefinitionId) { - // Check if this was set in a custom preference initialiser - String value = PrefUtils.getDefaultUIWorkBenchPreference(fontDefinitionId); - if(value != null) { + //Check if there is a default setting in custom preferences or plugin_customization.ini + String value = PrefUtil.getInternalPreferenceStore().getDefaultString("default." + fontDefinitionId); + if(StringUtils.isSet(value)) { try { return new FontData(value); }