Skip to content

Commit

Permalink
2
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillipus committed Dec 21, 2024
1 parent 7c7be97 commit 5757fb5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -24,43 +20,18 @@
@SuppressWarnings("nls")
public class PrefUtils {

// Store default preferences before they are mangled by the Workbench Theme helper
private static Map<String, String> 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.
Expand All @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down Expand Up @@ -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());
}
}

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

0 comments on commit 5757fb5

Please sign in to comment.