Skip to content

Commit 06b47e7

Browse files
committed
Add 'Manage default...' button to theme preference page
Adds a button next to the theme selection combo box that opens a dialog allowing users to set the currently selected theme as the default for new workspaces or remove an existing default. The dialog explains that the default theme applies to new workspaces and workspaces without an explicit theme, and shows the current default if one is configured.
1 parent 3b23ac5 commit 06b47e7

3 files changed

Lines changed: 84 additions & 1 deletion

File tree

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchMessages.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ public class WorkbenchMessages extends NLS {
5151
public static String ThemeChangeWarningText;
5252
public static String ThemeChange_useAsDefault;
5353
public static String ThemeChangeWarningTitle;
54+
public static String ThemeDefault_manageButton;
55+
public static String ThemeDefault_dialogTitle;
56+
public static String ThemeDefault_description;
57+
public static String ThemeDefault_currentDefault;
58+
public static String ThemeDefault_noDefault;
59+
public static String ThemeDefault_setDefault;
60+
public static String ThemeDefault_removeDefault;
5461

5562
public static String BundleSigningTray_Cant_Find_Service;
5663

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.eclipse.e4.ui.workbench.renderers.swt.CTabRendering;
5252
import org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer;
5353
import org.eclipse.jface.dialogs.Dialog;
54+
import org.eclipse.jface.dialogs.IDialogConstants;
5455
import org.eclipse.jface.dialogs.MessageDialog;
5556
import org.eclipse.jface.fieldassist.ControlDecoration;
5657
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
@@ -149,7 +150,14 @@ protected Control createContents(Composite parent) {
149150

150151
new Label(comp, SWT.NONE).setText(WorkbenchMessages.ViewsPreferencePage_Theme);
151152

152-
themeIdCombo = new ComboViewer(comp, SWT.READ_ONLY);
153+
Composite themeComposite = new Composite(comp, SWT.NONE);
154+
GridLayout themeLayout = new GridLayout(2, false);
155+
themeLayout.marginWidth = 0;
156+
themeLayout.marginHeight = 0;
157+
themeComposite.setLayout(themeLayout);
158+
themeComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
159+
160+
themeIdCombo = new ComboViewer(themeComposite, SWT.READ_ONLY);
153161
themeIdCombo.setLabelProvider(createTextProvider(element -> ((ITheme) element).getLabel()));
154162
themeIdCombo.setContentProvider(ArrayContentProvider.getInstance());
155163
themeIdCombo.setInput(engine.getThemes());
@@ -159,6 +167,11 @@ protected Control createContents(Composite parent) {
159167
themeIdCombo.setSelection(new StructuredSelection(currentTheme));
160168
}
161169
themeComboDecorator = new ControlDecoration(themeIdCombo.getCombo(), SWT.TOP | SWT.LEFT);
170+
171+
Button manageDefaultButton = new Button(themeComposite, SWT.PUSH);
172+
manageDefaultButton.setText(WorkbenchMessages.ThemeDefault_manageButton);
173+
manageDefaultButton.addSelectionListener(widgetSelectedAdapter(e -> openManageDefaultThemeDialog()));
174+
162175
themeIdCombo.addSelectionChangedListener(event -> {
163176
ITheme selection = getSelectedTheme();
164177
if (!selection.equals(currentTheme)) {
@@ -324,6 +337,62 @@ private ITheme getSelectedTheme() {
324337
return (ITheme) (themeIdCombo.getStructuredSelection().getFirstElement());
325338
}
326339

340+
private void openManageDefaultThemeDialog() {
341+
IEclipsePreferences configNode = ConfigurationScope.INSTANCE.getNode(E4_THEME_EXTENSION_POINT);
342+
String currentDefaultId = configNode.get("themeid", null); //$NON-NLS-1$
343+
344+
String currentDefaultLabel = null;
345+
if (currentDefaultId != null) {
346+
for (ITheme t : engine.getThemes()) {
347+
if (t.getId().equals(currentDefaultId)) {
348+
currentDefaultLabel = t.getLabel();
349+
break;
350+
}
351+
}
352+
if (currentDefaultLabel == null) {
353+
currentDefaultLabel = currentDefaultId;
354+
}
355+
}
356+
357+
String message;
358+
if (currentDefaultLabel != null) {
359+
message = NLS.bind(WorkbenchMessages.ThemeDefault_currentDefault, currentDefaultLabel);
360+
} else {
361+
message = WorkbenchMessages.ThemeDefault_noDefault;
362+
}
363+
message = WorkbenchMessages.ThemeDefault_description + "\n\n" + message; //$NON-NLS-1$
364+
365+
ITheme selectedTheme = getSelectedTheme();
366+
List<String> buttonLabels = new ArrayList<>();
367+
buttonLabels.add(WorkbenchMessages.ThemeDefault_setDefault);
368+
if (currentDefaultId != null) {
369+
buttonLabels.add(WorkbenchMessages.ThemeDefault_removeDefault);
370+
}
371+
buttonLabels.add(IDialogConstants.CLOSE_LABEL);
372+
373+
MessageDialog dialog = new MessageDialog(getShell(), WorkbenchMessages.ThemeDefault_dialogTitle, null, message,
374+
MessageDialog.INFORMATION, 0, buttonLabels.toArray(new String[0]));
375+
376+
int result = dialog.open();
377+
if (result == 0 && selectedTheme != null) {
378+
// Set as default
379+
configNode.put("themeid", selectedTheme.getId()); //$NON-NLS-1$
380+
try {
381+
configNode.flush();
382+
} catch (BackingStoreException e) {
383+
WorkbenchPlugin.log("Failed to set default theme in configuration scope", e); //$NON-NLS-1$
384+
}
385+
} else if (currentDefaultId != null && result == 1) {
386+
// Remove default
387+
configNode.remove("themeid"); //$NON-NLS-1$
388+
try {
389+
configNode.flush();
390+
} catch (BackingStoreException e) {
391+
WorkbenchPlugin.log("Failed to remove default theme from configuration scope", e); //$NON-NLS-1$
392+
}
393+
}
394+
}
395+
327396
@Override
328397
public void init(IWorkbench workbench) {
329398
MApplication application = workbench.getService(MApplication.class);

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/messages.properties

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,13 @@ ThemingEnabled = E&nable theming
500500
ThemeChangeWarningText = Restart to fully apply theme changes
501501
ThemeChange_useAsDefault = &Use as default theme (only applies to workspaces without a configured theme)
502502
ThemeChangeWarningTitle = Theme Changed
503+
ThemeDefault_manageButton = Manage &default...
504+
ThemeDefault_dialogTitle = Manage Default Theme
505+
ThemeDefault_description = The default theme is used for new workspaces and workspaces in which no explicit theme has been set.
506+
ThemeDefault_currentDefault = Current default theme: {0}
507+
ThemeDefault_noDefault = No default theme configured. The product default will be used.
508+
ThemeDefault_setDefault = &Set current theme as default
509+
ThemeDefault_removeDefault = &Remove default
503510
RescaleAtRuntimeSettingChangeWarningTitle = DPI Setting Changed
504511
RescaleAtRuntimeSettingChangeWarningText = Restart for the DPI setting changes to take effect
505512
RescaleAtRuntimeDescription = Activating this option will dynamically scale all windows according to the monitor they are currently in

0 commit comments

Comments
 (0)