5151import org .eclipse .e4 .ui .workbench .renderers .swt .CTabRendering ;
5252import org .eclipse .e4 .ui .workbench .renderers .swt .StackRenderer ;
5353import org .eclipse .jface .dialogs .Dialog ;
54+ import org .eclipse .jface .dialogs .IDialogConstants ;
5455import org .eclipse .jface .dialogs .MessageDialog ;
5556import org .eclipse .jface .fieldassist .ControlDecoration ;
5657import 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 );
0 commit comments