diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java index ae478696d50..e544e7744b9 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java @@ -317,12 +317,20 @@ private void setCSSContextVariables(IApplicationContext applicationContext, IEcl : getArgValue(E4Application.THEME_ID, applicationContext, false); if (!themeId.isPresent() && !cssURI.isPresent()) { - IEclipsePreferences userScopeNode = UserScope.INSTANCE - .getNode("org.eclipse.e4.ui.css.swt.theme"); - String defaultThemeId = userScopeNode.get("themeid", DEFAULT_THEME_ID); - context.set(E4Application.THEME_ID, defaultThemeId); + String defaultThemeId = getProductScopedThemeId(); + if (defaultThemeId != null) { + context.set(E4Application.THEME_ID, defaultThemeId); + } else { + context.set(E4Application.THEME_ID, DEFAULT_THEME_ID); + } } else { - context.set(E4Application.THEME_ID, themeId.orElseGet(() -> null)); + // Check if user has overridden the branding/command-line theme + String userThemeId = getProductScopedThemeId(); + if (userThemeId != null) { + context.set(E4Application.THEME_ID, userThemeId); + } else { + context.set(E4Application.THEME_ID, themeId.orElseGet(() -> null)); + } } @@ -403,6 +411,33 @@ private URI determineApplicationModelURI(IApplicationContext appContext) { } + /** + * Returns the product ID if a product is configured, otherwise falls back to + * the application ID from the system property. Returns {@code null} if + * neither is available. + */ + private static String getProductOrApplicationId() { + IProduct product = Platform.getProduct(); + if (product != null) { + return product.getId(); + } + return System.getProperty("eclipse.application"); //$NON-NLS-1$ + } + + /** + * Returns the user's product-scoped theme preference, or {@code null} if + * none is set. + */ + private static String getProductScopedThemeId() { + String productOrAppId = getProductOrApplicationId(); + if (productOrAppId != null) { + IEclipsePreferences themeNode = UserScope.INSTANCE + .getNode("org.eclipse.e4.ui.css.swt.theme"); + return themeNode.node(productOrAppId).get("themeid", null); + } + return null; + } + /** * Finds an argument's value in the app's command line arguments, branding, * and system properties diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchMessages.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchMessages.java index 42cfe5c445a..474ec54624e 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchMessages.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchMessages.java @@ -55,7 +55,9 @@ public class WorkbenchMessages extends NLS { public static String ThemeDefault_dialogTitle; public static String ThemeDefault_description; public static String ThemeDefault_currentDefault; + public static String ThemeDefault_currentDefaultUnscoped; public static String ThemeDefault_noDefault; + public static String ThemeDefault_noDefaultUnscoped; public static String ThemeDefault_setDefault; public static String ThemeDefault_removeDefault; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java index 2194cc629bd..4e9fd9e12f4 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java @@ -35,6 +35,7 @@ import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.IProduct; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform.OS; import org.eclipse.core.runtime.RegistryFactory; @@ -339,8 +340,11 @@ private ITheme getSelectedTheme() { } private void openManageDefaultThemeDialog() { - IEclipsePreferences configNode = ConfigurationScope.INSTANCE.getNode(E4_THEME_EXTENSION_POINT); - String currentDefaultId = configNode.get("themeid", null); //$NON-NLS-1$ + String productOrAppId = getProductOrApplicationId(); + IEclipsePreferences baseNode = UserScope.INSTANCE.getNode(E4_THEME_EXTENSION_POINT); + IEclipsePreferences scopedNode = productOrAppId != null ? (IEclipsePreferences) baseNode.node(productOrAppId) + : baseNode; + String currentDefaultId = scopedNode.get("themeid", null); //$NON-NLS-1$ String currentDefaultLabel = null; if (currentDefaultId != null) { @@ -355,11 +359,24 @@ private void openManageDefaultThemeDialog() { } } + String productDisplayName = getProductDisplayName(); + String message; if (currentDefaultLabel != null) { - message = NLS.bind(WorkbenchMessages.ThemeDefault_currentDefault, currentDefaultLabel); + if (productOrAppId != null) { + String displayName = productDisplayName != null ? productDisplayName : productOrAppId; + message = NLS.bind(WorkbenchMessages.ThemeDefault_currentDefault, new Object[] { currentDefaultLabel, + displayName, productOrAppId }); + } else { + message = NLS.bind(WorkbenchMessages.ThemeDefault_currentDefaultUnscoped, currentDefaultLabel); + } } else { - message = WorkbenchMessages.ThemeDefault_noDefault; + if (productOrAppId != null) { + String displayName = productDisplayName != null ? productDisplayName : productOrAppId; + message = NLS.bind(WorkbenchMessages.ThemeDefault_noDefault, displayName, productOrAppId); + } else { + message = WorkbenchMessages.ThemeDefault_noDefaultUnscoped; + } } message = WorkbenchMessages.ThemeDefault_description + "\n\n" + message; //$NON-NLS-1$ @@ -377,23 +394,48 @@ private void openManageDefaultThemeDialog() { int result = dialog.open(); if (result == 0 && selectedTheme != null) { // Set as default - configNode.put("themeid", selectedTheme.getId()); //$NON-NLS-1$ + scopedNode.put("themeid", selectedTheme.getId()); //$NON-NLS-1$ try { - configNode.flush(); + scopedNode.flush(); } catch (BackingStoreException e) { - WorkbenchPlugin.log("Failed to set default theme in configuration scope", e); //$NON-NLS-1$ + WorkbenchPlugin.log("Failed to set default theme in user scope", e); //$NON-NLS-1$ } } else if (currentDefaultId != null && result == 1) { // Remove default - configNode.remove("themeid"); //$NON-NLS-1$ + scopedNode.remove("themeid"); //$NON-NLS-1$ try { - configNode.flush(); + scopedNode.flush(); } catch (BackingStoreException e) { - WorkbenchPlugin.log("Failed to remove default theme from configuration scope", e); //$NON-NLS-1$ + WorkbenchPlugin.log("Failed to remove default theme from user scope", e); //$NON-NLS-1$ } } } + /** + * Returns the product ID if a product is configured, otherwise falls back to + * the application ID from the system property. Returns {@code null} if + * neither is available. + */ + private static String getProductOrApplicationId() { + IProduct product = Platform.getProduct(); + if (product != null) { + return product.getId(); + } + return System.getProperty("eclipse.application"); //$NON-NLS-1$ + } + + /** + * Returns the product name if a product is configured, or {@code null} + * otherwise. + */ + private static String getProductDisplayName() { + IProduct product = Platform.getProduct(); + if (product != null) { + return product.getName(); + } + return null; + } + @Override public void init(IWorkbench workbench) { MApplication application = workbench.getService(MApplication.class); @@ -521,11 +563,15 @@ protected Control createCustomArea(Composite parent) { int result = dialog.open(); if (result == 0 || result == 1) { // 0: Restart, 1: Don't Restart if (themeId != null && useAsDefault[0]) { - IEclipsePreferences userScopeNode = UserScope.INSTANCE + IEclipsePreferences baseNode = UserScope.INSTANCE .getNode(E4_THEME_EXTENSION_POINT); - userScopeNode.put("themeid", themeId); //$NON-NLS-1$ + String productOrAppId = getProductOrApplicationId(); + IEclipsePreferences scopedNode = productOrAppId != null + ? (IEclipsePreferences) baseNode.node(productOrAppId) + : baseNode; + scopedNode.put("themeid", themeId); //$NON-NLS-1$ try { - userScopeNode.flush(); + scopedNode.flush(); } catch (BackingStoreException e) { WorkbenchPlugin.log("Failed to set default theme in user scope", e); //$NON-NLS-1$ } diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/messages.properties b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/messages.properties index 8f9bf3483dc..ea70986c041 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/messages.properties +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/messages.properties @@ -503,8 +503,10 @@ ThemeChangeWarningTitle = Theme Changed ThemeDefault_manageButton = Manage &default... ThemeDefault_dialogTitle = Manage Default Theme ThemeDefault_description = The default theme is used for new workspaces and workspaces in which no explicit theme has been set. -ThemeDefault_currentDefault = Current default theme: {0} -ThemeDefault_noDefault = No default theme configured. The product default will be used. +ThemeDefault_currentDefault = Current default theme for {1} ({2}): {0} +ThemeDefault_currentDefaultUnscoped = Current default theme: {0} +ThemeDefault_noDefault = No default theme configured for {0} ({1}). The product default will be used. +ThemeDefault_noDefaultUnscoped = No default theme configured. The product default will be used. ThemeDefault_setDefault = &Set current theme as default ThemeDefault_removeDefault = &Remove default RescaleAtRuntimeSettingChangeWarningTitle = DPI Setting Changed