|
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; |
|
52 | 53 | import org.eclipse.osgi.service.datalocation.Location; |
53 | 54 | import org.eclipse.osgi.util.NLS; |
54 | 55 | import org.eclipse.swt.SWT; |
| 56 | +import org.eclipse.swt.graphics.Color; |
55 | 57 | import org.eclipse.swt.layout.FillLayout; |
56 | 58 | import org.eclipse.swt.widgets.Composite; |
57 | 59 | import org.eclipse.swt.widgets.Control; |
@@ -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 isDark; |
| 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,9 @@ public Object start(IApplicationContext appContext) throws Exception { |
145 | 149 | Job.getJobManager().suspend(); |
146 | 150 |
|
147 | 151 | Display display = createDisplay(); |
| 152 | + |
| 153 | + initializeDefaultTheme(display); |
| 154 | + |
148 | 155 | // processor must be created before we start event loop |
149 | 156 | DelayedEventsProcessor processor = new DelayedEventsProcessor(display); |
150 | 157 |
|
@@ -587,6 +594,14 @@ protected Shell getParentShell() { |
587 | 594 | return null; |
588 | 595 | } |
589 | 596 |
|
| 597 | + @Override |
| 598 | + protected Control createContents(Composite parent) { |
| 599 | + Control contents = super.createContents(parent); |
| 600 | + if (isDark) { |
| 601 | + applyDarkStyles(getShell()); |
| 602 | + } |
| 603 | + return contents; |
| 604 | + } |
590 | 605 | }.prompt(force); |
591 | 606 | } |
592 | 607 |
|
@@ -852,6 +867,42 @@ protected static Version toMajorMinorVersion(Version version) { |
852 | 867 | return new Version(version.getMajor(), version.getMinor(), 0); |
853 | 868 | } |
854 | 869 |
|
| 870 | + protected void initializeDefaultTheme(Display display) { |
| 871 | + IEclipsePreferences configurationScopeNode = ConfigurationScope.INSTANCE |
| 872 | + .getNode("org.eclipse.e4.ui.css.swt.theme"); //$NON-NLS-1$ |
| 873 | + String defaultThemeId = configurationScopeNode.get("themeid", null); //$NON-NLS-1$ |
| 874 | + isDark = defaultThemeId != null && defaultThemeId.contains("dark"); //$NON-NLS-1$ |
| 875 | + if (isDark) { |
| 876 | + display.addListener(SWT.Show, event -> { |
| 877 | + if (event.widget instanceof Shell shell) { |
| 878 | + applyDarkStyles(shell); |
| 879 | + } |
| 880 | + }); |
| 881 | + } |
| 882 | + } |
| 883 | + |
| 884 | + private void applyDarkStyles(Shell shell) { |
| 885 | + Color bg = new Color(shell.getDisplay(), 72, 72, 76); // #48484c |
| 886 | + Color fg = new Color(shell.getDisplay(), 238, 238, 238); // #eeeeee |
| 887 | + shell.setBackground(bg); |
| 888 | + shell.setForeground(fg); |
| 889 | + applyStylesRecursive(shell, bg, fg); |
| 890 | + shell.addDisposeListener(e -> { |
| 891 | + bg.dispose(); |
| 892 | + fg.dispose(); |
| 893 | + }); |
| 894 | + } |
| 895 | + |
| 896 | + private void applyStylesRecursive(Control control, Color bg, Color fg) { |
| 897 | + control.setBackground(bg); |
| 898 | + control.setForeground(fg); |
| 899 | + if (control instanceof Composite composite) { |
| 900 | + for (Control child : composite.getChildren()) { |
| 901 | + applyStylesRecursive(child, bg, fg); |
| 902 | + } |
| 903 | + } |
| 904 | + } |
| 905 | + |
855 | 906 | @Override |
856 | 907 | public void stop() { |
857 | 908 | final IWorkbench workbench = PlatformUI.getWorkbench(); |
|
0 commit comments