Skip to content

Commit 9df0418

Browse files
committed
Style workspace selection dialog with default theme setting
1 parent 06b47e7 commit 9df0418

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

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

Lines changed: 51 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;
@@ -52,6 +53,7 @@
5253
import org.eclipse.osgi.service.datalocation.Location;
5354
import org.eclipse.osgi.util.NLS;
5455
import org.eclipse.swt.SWT;
56+
import org.eclipse.swt.graphics.Color;
5557
import org.eclipse.swt.layout.FillLayout;
5658
import org.eclipse.swt.widgets.Composite;
5759
import org.eclipse.swt.widgets.Control;
@@ -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 isDark;
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,9 @@ public Object start(IApplicationContext appContext) throws Exception {
145149
Job.getJobManager().suspend();
146150

147151
Display display = createDisplay();
152+
153+
initializeDefaultTheme(display);
154+
148155
// processor must be created before we start event loop
149156
DelayedEventsProcessor processor = new DelayedEventsProcessor(display);
150157

@@ -587,6 +594,14 @@ protected Shell getParentShell() {
587594
return null;
588595
}
589596

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+
}
590605
}.prompt(force);
591606
}
592607

@@ -852,6 +867,42 @@ protected static Version toMajorMinorVersion(Version version) {
852867
return new Version(version.getMajor(), version.getMinor(), 0);
853868
}
854869

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+
855906
@Override
856907
public void stop() {
857908
final IWorkbench workbench = PlatformUI.getWorkbench();

bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceDialog.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.eclipse.jface.dialogs.IDialogConstants;
4040
import org.eclipse.jface.dialogs.IDialogSettings;
4141
import org.eclipse.jface.dialogs.TitleAreaDialog;
42+
import org.eclipse.jface.resource.JFaceColors;
4243
import org.eclipse.jface.util.Geometry;
4344
import org.eclipse.jface.window.Window;
4445
import org.eclipse.osgi.util.NLS;
@@ -319,6 +320,7 @@ private void createRecentWorkspacesComposite(final Composite composite) {
319320
recentWorkspacesForm.getBody().setLayout(new GridLayout());
320321
ExpandableComposite recentWorkspacesExpandable = toolkit.createExpandableComposite(recentWorkspacesForm.getBody(),
321322
ExpandableComposite.TWISTIE);
323+
recentWorkspacesExpandable.setTitleBarForeground(composite.getForeground());
322324
recentWorkspacesForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
323325
recentWorkspacesExpandable.setBackground(composite.getBackground());
324326
recentWorkspacesExpandable.setText(IDEWorkbenchMessages.ChooseWorkspaceDialog_recentWorkspaces);
@@ -352,6 +354,7 @@ public void expansionStateChanged(ExpansionEvent e) {
352354
final String recentWorkspace = uniqueWorkspaceEntry.getValue();
353355

354356
Link link = new Link(panel, SWT.WRAP);
357+
link.setForeground(JFaceColors.getHyperlink(composite.getDisplay()));
355358
link.setLayoutData(new RowData(SWT.DEFAULT, SWT.DEFAULT));
356359
link.setText("<a>" + uniqueWorkspaceEntry.getKey() + "</a>"); //$NON-NLS-1$ //$NON-NLS-2$
357360
link.setToolTipText(recentWorkspace);

bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ChooseWorkspaceWithSettingsDialog.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ private void createSettingsControls(Composite workArea) {
128128

129129
copySettingsExpandable.setText(IDEWorkbenchMessages.ChooseWorkspaceWithSettingsDialog_SettingsGroupName);
130130
copySettingsExpandable.setBackground(workArea.getBackground());
131+
copySettingsExpandable.setTitleBarForeground(workArea.getForeground());
131132
copySettingsExpandable.setLayout(new GridLayout());
132133
copySettingsExpandable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
133134
copySettingsExpandable.addExpansionListener(new IExpansionListener() {

0 commit comments

Comments
 (0)