|
42 | 42 | import org.eclipse.core.runtime.Status; |
43 | 43 | import org.eclipse.core.runtime.jobs.Job; |
44 | 44 | import org.eclipse.core.runtime.preferences.ConfigurationScope; |
| 45 | +import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
45 | 46 | import org.eclipse.equinox.app.IApplication; |
46 | 47 | import org.eclipse.equinox.app.IApplicationContext; |
47 | 48 | import org.eclipse.jface.dialogs.IDialogConstants; |
|
53 | 54 | import org.eclipse.osgi.util.NLS; |
54 | 55 | import org.eclipse.swt.SWT; |
55 | 56 | import org.eclipse.swt.layout.FillLayout; |
| 57 | +import org.eclipse.swt.graphics.Color; |
56 | 58 | import org.eclipse.swt.widgets.Composite; |
57 | 59 | import org.eclipse.swt.widgets.Control; |
58 | 60 | import org.eclipse.swt.widgets.Display; |
@@ -94,6 +96,8 @@ public class IDEApplication implements IApplication, IExecutableExtension { |
94 | 96 |
|
95 | 97 | private static final String USER_NAME = "user.name"; //$NON-NLS-1$ |
96 | 98 |
|
| 99 | + private boolean isDarkTheme; |
| 100 | + |
97 | 101 | // Use the branding plug-in of the platform feature since this is most likely |
98 | 102 | // to change on an update of the IDE. |
99 | 103 | 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 { |
145 | 149 | Job.getJobManager().suspend(); |
146 | 150 |
|
147 | 151 | 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 | + |
148 | 158 | // processor must be created before we start event loop |
149 | 159 | DelayedEventsProcessor processor = new DelayedEventsProcessor(display); |
150 | 160 |
|
@@ -587,9 +597,39 @@ protected Shell getParentShell() { |
587 | 597 | return null; |
588 | 598 | } |
589 | 599 |
|
| 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 | + } |
590 | 608 | }.prompt(force); |
591 | 609 | } |
592 | 610 |
|
| 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 | + |
593 | 633 | /** |
594 | 634 | * Result of the {@link IDEApplication#checkValidWorkspace(Shell, URL)} |
595 | 635 | * operation |
|
0 commit comments