From 9df04184b411d3925bf21b05afbb9f87f4620ce7 Mon Sep 17 00:00:00 2001 From: Lars Vogel Date: Thu, 2 Apr 2026 14:41:38 +0200 Subject: [PATCH] Style workspace selection dialog with default theme setting --- .../ide/application/IDEApplication.java | 51 +++++++++++++++++++ .../internal/ide/ChooseWorkspaceDialog.java | 3 ++ .../ChooseWorkspaceWithSettingsDialog.java | 1 + 3 files changed, 55 insertions(+) diff --git a/bundles/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/IDEApplication.java b/bundles/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/IDEApplication.java index a4bc366a90fa..1554d7c31cf4 100644 --- a/bundles/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/IDEApplication.java +++ b/bundles/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/IDEApplication.java @@ -42,6 +42,7 @@ import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.preferences.ConfigurationScope; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; import org.eclipse.jface.dialogs.IDialogConstants; @@ -52,6 +53,7 @@ import org.eclipse.osgi.service.datalocation.Location; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; @@ -94,6 +96,8 @@ public class IDEApplication implements IApplication, IExecutableExtension { private static final String USER_NAME = "user.name"; //$NON-NLS-1$ + private boolean isDark; + // Use the branding plug-in of the platform feature since this is most likely // to change on an update of the IDE. private static final String WORKSPACE_CHECK_REFERENCE_BUNDLE_NAME = "org.eclipse.platform"; //$NON-NLS-1$ @@ -145,6 +149,9 @@ public Object start(IApplicationContext appContext) throws Exception { Job.getJobManager().suspend(); Display display = createDisplay(); + + initializeDefaultTheme(display); + // processor must be created before we start event loop DelayedEventsProcessor processor = new DelayedEventsProcessor(display); @@ -587,6 +594,14 @@ protected Shell getParentShell() { return null; } + @Override + protected Control createContents(Composite parent) { + Control contents = super.createContents(parent); + if (isDark) { + applyDarkStyles(getShell()); + } + return contents; + } }.prompt(force); } @@ -852,6 +867,42 @@ protected static Version toMajorMinorVersion(Version version) { return new Version(version.getMajor(), version.getMinor(), 0); } + protected void initializeDefaultTheme(Display display) { + IEclipsePreferences configurationScopeNode = ConfigurationScope.INSTANCE + .getNode("org.eclipse.e4.ui.css.swt.theme"); //$NON-NLS-1$ + String defaultThemeId = configurationScopeNode.get("themeid", null); //$NON-NLS-1$ + isDark = defaultThemeId != null && defaultThemeId.contains("dark"); //$NON-NLS-1$ + if (isDark) { + display.addListener(SWT.Show, event -> { + if (event.widget instanceof Shell shell) { + applyDarkStyles(shell); + } + }); + } + } + + private void applyDarkStyles(Shell shell) { + Color bg = new Color(shell.getDisplay(), 72, 72, 76); // #48484c + Color fg = new Color(shell.getDisplay(), 238, 238, 238); // #eeeeee + shell.setBackground(bg); + shell.setForeground(fg); + applyStylesRecursive(shell, bg, fg); + shell.addDisposeListener(e -> { + bg.dispose(); + fg.dispose(); + }); + } + + private void applyStylesRecursive(Control control, Color bg, Color fg) { + control.setBackground(bg); + control.setForeground(fg); + if (control instanceof Composite composite) { + for (Control child : composite.getChildren()) { + applyStylesRecursive(child, bg, fg); + } + } + } + @Override public void stop() { final IWorkbench workbench = PlatformUI.getWorkbench(); diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceDialog.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceDialog.java index 78701c3ece16..bd6b988a0cdf 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceDialog.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceDialog.java @@ -39,6 +39,7 @@ import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.jface.resource.JFaceColors; import org.eclipse.jface.util.Geometry; import org.eclipse.jface.window.Window; import org.eclipse.osgi.util.NLS; @@ -319,6 +320,7 @@ private void createRecentWorkspacesComposite(final Composite composite) { recentWorkspacesForm.getBody().setLayout(new GridLayout()); ExpandableComposite recentWorkspacesExpandable = toolkit.createExpandableComposite(recentWorkspacesForm.getBody(), ExpandableComposite.TWISTIE); + recentWorkspacesExpandable.setTitleBarForeground(composite.getForeground()); recentWorkspacesForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); recentWorkspacesExpandable.setBackground(composite.getBackground()); recentWorkspacesExpandable.setText(IDEWorkbenchMessages.ChooseWorkspaceDialog_recentWorkspaces); @@ -352,6 +354,7 @@ public void expansionStateChanged(ExpansionEvent e) { final String recentWorkspace = uniqueWorkspaceEntry.getValue(); Link link = new Link(panel, SWT.WRAP); + link.setForeground(JFaceColors.getHyperlink(composite.getDisplay())); link.setLayoutData(new RowData(SWT.DEFAULT, SWT.DEFAULT)); link.setText("" + uniqueWorkspaceEntry.getKey() + ""); //$NON-NLS-1$ //$NON-NLS-2$ link.setToolTipText(recentWorkspace); diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceWithSettingsDialog.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceWithSettingsDialog.java index 0955fae4425e..e3d5211ecc05 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceWithSettingsDialog.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceWithSettingsDialog.java @@ -128,6 +128,7 @@ private void createSettingsControls(Composite workArea) { copySettingsExpandable.setText(IDEWorkbenchMessages.ChooseWorkspaceWithSettingsDialog_SettingsGroupName); copySettingsExpandable.setBackground(workArea.getBackground()); + copySettingsExpandable.setTitleBarForeground(workArea.getForeground()); copySettingsExpandable.setLayout(new GridLayout()); copySettingsExpandable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); copySettingsExpandable.addExpansionListener(new IExpansionListener() {