Skip to content

Commit ef95078

Browse files
committed
Scope default theme preference by product or application
The default theme preference is now stored under a product-specific (or application-specific) sub-node in user scope. This allows different Eclipse-based products sharing the same user preferences location to maintain independent theme defaults. When reading the preference, the product ID (from Platform.getProduct()) is used as the sub-node key. If no product is configured, the application ID (eclipse.application system property) is used as fallback. If neither is available, the preference is stored at the base node level. This also migrates the 'Manage default theme' dialog from ConfigurationScope to UserScope to be consistent with the rest of the theme preference handling.
1 parent 1375cd4 commit ef95078

File tree

2 files changed

+54
-13
lines changed

2 files changed

+54
-13
lines changed

bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,16 @@ private void setCSSContextVariables(IApplicationContext applicationContext, IEcl
317317
: getArgValue(E4Application.THEME_ID, applicationContext, false);
318318

319319
if (!themeId.isPresent() && !cssURI.isPresent()) {
320-
IEclipsePreferences userScopeNode = UserScope.INSTANCE
320+
IEclipsePreferences themeNode = UserScope.INSTANCE
321321
.getNode("org.eclipse.e4.ui.css.swt.theme");
322-
String defaultThemeId = userScopeNode.get("themeid", DEFAULT_THEME_ID);
322+
String productOrAppId = getProductOrApplicationId();
323+
String defaultThemeId = null;
324+
if (productOrAppId != null) {
325+
defaultThemeId = themeNode.node(productOrAppId).get("themeid", null);
326+
}
327+
if (defaultThemeId == null) {
328+
defaultThemeId = DEFAULT_THEME_ID;
329+
}
323330
context.set(E4Application.THEME_ID, defaultThemeId);
324331
} else {
325332
context.set(E4Application.THEME_ID, themeId.orElseGet(() -> null));
@@ -403,6 +410,19 @@ private URI determineApplicationModelURI(IApplicationContext appContext) {
403410

404411
}
405412

413+
/**
414+
* Returns the product ID if a product is configured, otherwise falls back to
415+
* the application ID from the system property. Returns {@code null} if
416+
* neither is available.
417+
*/
418+
private static String getProductOrApplicationId() {
419+
IProduct product = Platform.getProduct();
420+
if (product != null) {
421+
return product.getId();
422+
}
423+
return System.getProperty("eclipse.application"); //$NON-NLS-1$
424+
}
425+
406426
/**
407427
* Finds an argument's value in the app's command line arguments, branding,
408428
* and system properties

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.eclipse.core.runtime.IExtension;
3636
import org.eclipse.core.runtime.IExtensionPoint;
3737
import org.eclipse.core.runtime.IExtensionRegistry;
38+
import org.eclipse.core.runtime.IProduct;
3839
import org.eclipse.core.runtime.Platform;
3940
import org.eclipse.core.runtime.Platform.OS;
4041
import org.eclipse.core.runtime.RegistryFactory;
@@ -339,8 +340,11 @@ private ITheme getSelectedTheme() {
339340
}
340341

341342
private void openManageDefaultThemeDialog() {
342-
IEclipsePreferences configNode = ConfigurationScope.INSTANCE.getNode(E4_THEME_EXTENSION_POINT);
343-
String currentDefaultId = configNode.get("themeid", null); //$NON-NLS-1$
343+
String productOrAppId = getProductOrApplicationId();
344+
IEclipsePreferences baseNode = UserScope.INSTANCE.getNode(E4_THEME_EXTENSION_POINT);
345+
IEclipsePreferences scopedNode = productOrAppId != null ? (IEclipsePreferences) baseNode.node(productOrAppId)
346+
: baseNode;
347+
String currentDefaultId = scopedNode.get("themeid", null); //$NON-NLS-1$
344348

345349
String currentDefaultLabel = null;
346350
if (currentDefaultId != null) {
@@ -377,23 +381,36 @@ private void openManageDefaultThemeDialog() {
377381
int result = dialog.open();
378382
if (result == 0 && selectedTheme != null) {
379383
// Set as default
380-
configNode.put("themeid", selectedTheme.getId()); //$NON-NLS-1$
384+
scopedNode.put("themeid", selectedTheme.getId()); //$NON-NLS-1$
381385
try {
382-
configNode.flush();
386+
scopedNode.flush();
383387
} catch (BackingStoreException e) {
384-
WorkbenchPlugin.log("Failed to set default theme in configuration scope", e); //$NON-NLS-1$
388+
WorkbenchPlugin.log("Failed to set default theme in user scope", e); //$NON-NLS-1$
385389
}
386390
} else if (currentDefaultId != null && result == 1) {
387391
// Remove default
388-
configNode.remove("themeid"); //$NON-NLS-1$
392+
scopedNode.remove("themeid"); //$NON-NLS-1$
389393
try {
390-
configNode.flush();
394+
scopedNode.flush();
391395
} catch (BackingStoreException e) {
392-
WorkbenchPlugin.log("Failed to remove default theme from configuration scope", e); //$NON-NLS-1$
396+
WorkbenchPlugin.log("Failed to remove default theme from user scope", e); //$NON-NLS-1$
393397
}
394398
}
395399
}
396400

401+
/**
402+
* Returns the product ID if a product is configured, otherwise falls back to
403+
* the application ID from the system property. Returns {@code null} if
404+
* neither is available.
405+
*/
406+
private static String getProductOrApplicationId() {
407+
IProduct product = Platform.getProduct();
408+
if (product != null) {
409+
return product.getId();
410+
}
411+
return System.getProperty("eclipse.application"); //$NON-NLS-1$
412+
}
413+
397414
@Override
398415
public void init(IWorkbench workbench) {
399416
MApplication application = workbench.getService(MApplication.class);
@@ -521,11 +538,15 @@ protected Control createCustomArea(Composite parent) {
521538
int result = dialog.open();
522539
if (result == 0 || result == 1) { // 0: Restart, 1: Don't Restart
523540
if (themeId != null && useAsDefault[0]) {
524-
IEclipsePreferences userScopeNode = UserScope.INSTANCE
541+
IEclipsePreferences baseNode = UserScope.INSTANCE
525542
.getNode(E4_THEME_EXTENSION_POINT);
526-
userScopeNode.put("themeid", themeId); //$NON-NLS-1$
543+
String productOrAppId = getProductOrApplicationId();
544+
IEclipsePreferences scopedNode = productOrAppId != null
545+
? (IEclipsePreferences) baseNode.node(productOrAppId)
546+
: baseNode;
547+
scopedNode.put("themeid", themeId); //$NON-NLS-1$
527548
try {
528-
userScopeNode.flush();
549+
scopedNode.flush();
529550
} catch (BackingStoreException e) {
530551
WorkbenchPlugin.log("Failed to set default theme in user scope", e); //$NON-NLS-1$
531552
}

0 commit comments

Comments
 (0)