-
-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PrefUtils to set and get Eclipse internal preferences
- Set/Get Eclipse internal preferences before the workbench starts - Move all existing prefs settings to here - This gives us a workaround for a default font's value not retrieved if user has a pluginCustomization setting for a default font - Before this, pressing the "Default" button in Preferences showed the system font instead of the one in the pluginCustomization
- Loading branch information
Showing
6 changed files
with
141 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
com.archimatetool.editor/src/com/archimatetool/editor/preferences/PrefUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/** | ||
* This program and the accompanying materials | ||
* are made available under the terms of the License | ||
* which accompanies this distribution in the file LICENSE.txt | ||
*/ | ||
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; | ||
|
||
/** | ||
* Utils to access internal Eclipse Preferences before the Workbench starts. | ||
* We can set and store preferences before the Workbench starts. | ||
* | ||
* @author Phillip Beauvoir | ||
*/ | ||
@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. | ||
// Archi's PreferenceInitializer triggers the creation of the workbench Display by getting the Device zoom level which in turn creates the default Display | ||
// and then it's too late to set the property. | ||
if(PlatformUtils.isMac()) { | ||
boolean useNativeItemHeights = InstanceScope.INSTANCE.getNode("com.archimatetool.editor") | ||
.getBoolean(IPreferenceConstants.MAC_ITEM_HEIGHT_PROPERTY_KEY, false); | ||
System.setProperty(IPreferenceConstants.MAC_ITEM_HEIGHT_PROPERTY_KEY, Boolean.toString(useNativeItemHeights)); | ||
} | ||
|
||
// Set Eclipse theming default enabled to true to counteract possible future regressions | ||
// See https://github.com/eclipse-platform/eclipse.platform.ui/issues/629 | ||
// See https://github.com/eclipse-platform/eclipse.platform.ui/pull/630 | ||
IEclipsePreferences preferences = DefaultScope.INSTANCE.getNode("org.eclipse.e4.ui.workbench.renderers.swt"); | ||
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"); | ||
} | ||
|
||
public static IEclipsePreferences getInstanceUIWorkBenchPrefs() { | ||
return InstanceScope.INSTANCE.getNode("org.eclipse.ui.workbench"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters