Skip to content

Commit

Permalink
[Themes] Use theme method to store theme font
Browse files Browse the repository at this point in the history
- We have to use this method of creating the font preference key for fonts
  • Loading branch information
Phillipus committed Oct 22, 2024
1 parent 74cd30c commit f9f4d30
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 9 deletions.
6 changes: 6 additions & 0 deletions com.archimatetool.editor.themes/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@
refid="org.eclipse.e4.ui.css.theme.e4_classic">
</themeid>
</stylesheet>
<stylesheet
uri="themes/eclipse/css/archi-high-contrast.css">
<themeid
refid="org.eclipse.e4.ui.css.theme.high-contrast">
</themeid>
</stylesheet>
<stylesheet
uri="themes/eclipse/css/dark/archi-dark-styling.css">
<themeid
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*******************************************************************************
* Styling for Archi that over-rides some Eclipse stylings
*******************************************************************************/

@import url("platform:/plugin/com.archimatetool.editor.themes/themes/archi/css/common/archi-globalstyle.css");

/* Theme colors */

ColorDefinition#com-archimatetool-editor-VIEW_BACKGROUND {
color: '#COLOR_WIDGET_BACKGROUND';
}

ColorDefinition#com-archimatetool-editor-VISUALISER_BACKGROUND {
color: '#COLOR_WIDGET_BACKGROUND';
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;

import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.jface.layout.GridDataFactory;
Expand Down Expand Up @@ -99,13 +98,7 @@ FontData getDefaultFontData() {
}

void performOK() {
// Our font definitions are global to all themes so just write directly to the store
if(Objects.equals(getFontData(), getSystemFontData())) {
getPreferenceStore().setToDefault(fontDefinitionId);
}
else {
getPreferenceStore().setValue(fontDefinitionId, getFontData().toString());
}
ThemeUtils.setCurrentThemeFont(fontDefinitionId, getFontData());
}

FontData getSystemFontData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.eclipse.e4.ui.css.swt.internal.theme.ThemeEngine;
import org.eclipse.e4.ui.css.swt.theme.IThemeEngine;
import org.eclipse.jface.resource.FontRegistry;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.resource.StringConverter;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.swt.graphics.Color;
Expand All @@ -23,6 +24,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;
Expand Down Expand Up @@ -251,6 +253,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) {
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, JFaceResources.getDefaultFont().getFontData()[0])) { // If it's the system 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
*/
Expand Down Expand Up @@ -284,7 +312,7 @@ public static void setFontIfCssThemingDisabled(Control control, String fontDefin
}
});
}

// ===============================================
// Utils
// ===============================================
Expand Down

0 comments on commit f9f4d30

Please sign in to comment.