Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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$
Expand Down Expand Up @@ -145,6 +149,9 @@ public Object start(IApplicationContext appContext) throws Exception {
Job.getJobManager().suspend();

Display display = createDisplay();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please once done, extract into a protected method, so whoever extends this (non API, I know) application can overwrite the code if needed.

initializeDefaultTheme(display);

// processor must be created before we start event loop
DelayedEventsProcessor processor = new DelayedEventsProcessor(display);

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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("<a>" + uniqueWorkspaceEntry.getKey() + "</a>"); //$NON-NLS-1$ //$NON-NLS-2$
link.setToolTipText(recentWorkspace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading