diff --git a/com.archimatetool.editor.themes/plugin.xml b/com.archimatetool.editor.themes/plugin.xml index 6d259afc8..ad31e16a8 100644 --- a/com.archimatetool.editor.themes/plugin.xml +++ b/com.archimatetool.editor.themes/plugin.xml @@ -84,6 +84,12 @@ refid="org.eclipse.e4.ui.css.theme.e4_classic"> + + + + { @@ -468,7 +461,7 @@ private FontData openFontDialog(FontInfo fontInfo) { @Override public void performDefaults() { if(fScaleFontsButton != null) { - fScaleFontsButton.setSelection(ArchiPlugin.PREFERENCES.getDefaultBoolean(FONT_SCALING)); + fScaleFontsButton.setSelection(getPreferenceStore().getDefaultBoolean(FONT_SCALING)); } for(FontInfo info : fontInfos) { @@ -488,7 +481,7 @@ public void performDefaults() { @Override public boolean performOk() { if(fScaleFontsButton != null) { - ArchiPlugin.PREFERENCES.setValue(FONT_SCALING, fScaleFontsButton.getSelection()); + getPreferenceStore().setValue(FONT_SCALING, fScaleFontsButton.getSelection()); } for(FontInfo info : fontInfos) { 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 0699697a7..777fce4b6 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/ui/ThemeUtils.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/ui/ThemeUtils.java @@ -23,6 +23,7 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.internal.WorkbenchPlugin; import org.eclipse.ui.internal.themes.ColorDefinition; +import org.eclipse.ui.internal.themes.FontDefinition; import org.eclipse.ui.internal.themes.IThemeRegistry; import org.eclipse.ui.internal.themes.ThemeElementDefinition; import org.eclipse.ui.internal.themes.ThemeElementHelper; @@ -251,6 +252,32 @@ public static void setBackgroundColorIfCssThemingDisabled(Control control, Strin // Font Definitions // =============================================== + + /** + * Set theme font definition value for current theme. + * Some of this code inspired by {@link org.eclipse.ui.internal.themes.ColorsAndFontsPreferencePage} + */ + public static void setCurrentThemeFont(String fontDefinitionId, FontData fontData, FontData defaultFontData) { + if(!PlatformUI.isWorkbenchRunning() || fontData == null) { + return; + } + + // Get the font definition from the registry + FontDefinition fontDef = getThemeRegistry().findFont(fontDefinitionId); + if(fontDef == null) { + return; + } + + // Write FontData to workbench preference file at .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.workbench.prefs + String preferenceKey = createPreferenceKey(fontDef); + if(Objects.equals(fontData, defaultFontData)) { // If it's the default, remove it + PrefUtil.getInternalPreferenceStore().setToDefault(preferenceKey); + } + else { + PrefUtil.getInternalPreferenceStore().setValue(preferenceKey, fontData.toString()); + } + } + /** * Get the FontData in the current theme for a font definition or null */