Skip to content

Commit aa8df91

Browse files
committed
Style workspace selection dialog with default theme setting
1 parent bff29fd commit aa8df91

File tree

1 file changed

+40
-0
lines changed
  • bundles/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application

1 file changed

+40
-0
lines changed

bundles/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/IDEApplication.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.eclipse.core.runtime.Status;
4343
import org.eclipse.core.runtime.jobs.Job;
4444
import org.eclipse.core.runtime.preferences.ConfigurationScope;
45+
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
4546
import org.eclipse.equinox.app.IApplication;
4647
import org.eclipse.equinox.app.IApplicationContext;
4748
import org.eclipse.jface.dialogs.IDialogConstants;
@@ -53,6 +54,7 @@
5354
import org.eclipse.osgi.util.NLS;
5455
import org.eclipse.swt.SWT;
5556
import org.eclipse.swt.layout.FillLayout;
57+
import org.eclipse.swt.graphics.Color;
5658
import org.eclipse.swt.widgets.Composite;
5759
import org.eclipse.swt.widgets.Control;
5860
import org.eclipse.swt.widgets.Display;
@@ -94,6 +96,8 @@ public class IDEApplication implements IApplication, IExecutableExtension {
9496

9597
private static final String USER_NAME = "user.name"; //$NON-NLS-1$
9698

99+
private boolean isDarkTheme;
100+
97101
// Use the branding plug-in of the platform feature since this is most likely
98102
// to change on an update of the IDE.
99103
private static final String WORKSPACE_CHECK_REFERENCE_BUNDLE_NAME = "org.eclipse.platform"; //$NON-NLS-1$
@@ -145,6 +149,12 @@ public Object start(IApplicationContext appContext) throws Exception {
145149
Job.getJobManager().suspend();
146150

147151
Display display = createDisplay();
152+
153+
IEclipsePreferences configurationScopeNode = ConfigurationScope.INSTANCE
154+
.getNode("org.eclipse.e4.ui.css.swt.theme"); //$NON-NLS-1$
155+
String defaultThemeId = configurationScopeNode.get("themeid", null); //$NON-NLS-1$
156+
isDarkTheme = defaultThemeId != null && defaultThemeId.toLowerCase().contains("dark"); //$NON-NLS-1$
157+
148158
// processor must be created before we start event loop
149159
DelayedEventsProcessor processor = new DelayedEventsProcessor(display);
150160

@@ -587,9 +597,39 @@ protected Shell getParentShell() {
587597
return null;
588598
}
589599

600+
@Override
601+
protected Control createContents(Composite parent) {
602+
Control contents = super.createContents(parent);
603+
if (isDarkTheme) {
604+
applyDarkColors(getShell());
605+
}
606+
return contents;
607+
}
590608
}.prompt(force);
591609
}
592610

611+
private static void applyDarkColors(Shell shell) {
612+
Display display = shell.getDisplay();
613+
// Colors matching org-eclipse-ui-workbench-DARK_BACKGROUND / DARK_FOREGROUND
614+
Color background = new Color(display, 0x48, 0x48, 0x4c);
615+
Color foreground = new Color(display, 0xee, 0xee, 0xee);
616+
shell.addDisposeListener(e -> {
617+
background.dispose();
618+
foreground.dispose();
619+
});
620+
applyColorsRecursively(shell, background, foreground);
621+
}
622+
623+
private static void applyColorsRecursively(Control control, Color background, Color foreground) {
624+
control.setBackground(background);
625+
control.setForeground(foreground);
626+
if (control instanceof Composite composite) {
627+
for (Control child : composite.getChildren()) {
628+
applyColorsRecursively(child, background, foreground);
629+
}
630+
}
631+
}
632+
593633
/**
594634
* Result of the {@link IDEApplication#checkValidWorkspace(Shell, URL)}
595635
* operation

0 commit comments

Comments
 (0)