diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java index cf08b6a17b6..21967544571 100644 --- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java +++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java @@ -122,6 +122,11 @@ public class PartRenderingEngine implements IPresentationEngine { public static final String ENABLED_THEME_KEY = "themeEnabled"; + /** + * Default default value for "enable theming" behavior. + */ + public static final boolean ENABLED_THEME_KEY_DEFAULT = true; + private String factoryUrl; IRendererFactory curFactory = null; diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java index cc76a5897fe..4fea9efae41 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java @@ -106,6 +106,8 @@ public class ViewsPreferencePage extends PreferencePage implements IWorkbenchPre private ControlDecoration themeComboDecorator; private ITheme currentTheme; private String defaultTheme; + private Composite themeDependentComp; + private Button useRoundTabs; private Button enableMru; private Button useColoredLabels; @@ -130,7 +132,7 @@ protected Control createContents(Composite parent) { Composite comp = new Composite(parent, SWT.NONE); - themingEnabled = createCheckButton(comp, WorkbenchMessages.ThemingEnabled, engine != null); + createEnableTheming(comp); // if started with "-cssTheme none", CSS settings should be disabled // but other appearance settings should be *not* disabled @@ -143,50 +145,13 @@ protected Control createContents(Composite parent) { return comp; } - GridLayout layout = new GridLayout(2, false); - layout.horizontalSpacing = 10; - comp.setLayout(layout); - - new Label(comp, SWT.NONE).setText(WorkbenchMessages.ViewsPreferencePage_Theme); - highContrastMode = parent.getDisplay().getHighContrast(); - - themeIdCombo = new ComboViewer(comp, SWT.READ_ONLY); - themeIdCombo.setLabelProvider(createTextProvider(element -> ((ITheme) element).getLabel())); - themeIdCombo.setContentProvider(ArrayContentProvider.getInstance()); - themeIdCombo.setInput(getCSSThemes(highContrastMode)); - themeIdCombo.getCombo().setEnabled(!highContrastMode); - themeIdCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - this.currentTheme = engine.getActiveTheme(); - if (this.currentTheme != null) { - themeIdCombo.setSelection(new StructuredSelection(currentTheme)); - } - themeComboDecorator = new ControlDecoration(themeIdCombo.getCombo(), SWT.TOP | SWT.LEFT); - themeIdCombo.addSelectionChangedListener(event -> { - ITheme selection = getSelectedTheme(); - if (!selection.equals(currentTheme)) { - themeComboDecorator.setDescriptionText(WorkbenchMessages.ThemeChangeWarningText); - Image decorationImage = FieldDecorationRegistry.getDefault() - .getFieldDecoration(FieldDecorationRegistry.DEC_WARNING).getImage(); - themeComboDecorator.setImage(decorationImage); - themeComboDecorator.show(); - } else { - themeComboDecorator.hide(); - } - selectColorsAndFontsTheme(getColorAndFontThemeIdByThemeId(selection.getId())); - }); - - currentColorsAndFontsTheme = getCurrentColorsAndFontsTheme(); - createColorsAndFontsThemeCombo(comp); - - createThemeIndependentComposits(comp); - - // Theme dependent controls for Tab icons and titles in view areas - createShowFullTextForViewTabs(comp); - createHideIconsForViewTabs(comp); - createDependency(showFullTextForViewTabs, hideIconsForViewTabs); + createThemeDependentComposite(comp); + updateThemingEnablement(); + createThemeIndependentComposite(comp); createHiDPISettingsGroup(comp); + currentColorsAndFontsTheme = getCurrentColorsAndFontsTheme(); if (currentTheme != null) { String colorsAndFontsThemeId = getColorAndFontThemeIdByThemeId(currentTheme.getId()); if (colorsAndFontsThemeId != null && !currentColorsAndFontsTheme.getId().equals(colorsAndFontsThemeId)) { @@ -223,12 +188,36 @@ private void createHiDPISettingsGroup(Composite parent) { rescaleAtRuntime = createCheckButton(group, WorkbenchMessages.RescaleAtRuntimeEnabled, initialStateRescaleAtRuntime); } + private void createThemeDependentComposite(Composite parent) { + themeDependentComp = new Composite(parent, SWT.NONE); + GridLayout dependentLayout = new GridLayout(2, false); + dependentLayout.horizontalSpacing = 10; + themeDependentComp.setLayout(dependentLayout); + GridData dependentData = new GridData(SWT.FILL, SWT.TOP, true, false); + themeDependentComp.setLayoutData(dependentData); + + // Theme dependent controls for themes and color and fonts drop-down selections + createThemeIdCombo(themeDependentComp); + createColorsAndFontsThemeCombo(themeDependentComp); + + // Theme dependent controls for Tab icons and titles in view areas + createShowFullTextForViewTabs(themeDependentComp); + createHideIconsForViewTabs(themeDependentComp); + createTabDependency(showFullTextForViewTabs, hideIconsForViewTabs); + } + private void createThemeIndependentComposits(Composite comp) { createUseRoundTabs(comp); createColoredLabelsPref(comp); createEnableMruPref(comp); } + protected void createEnableTheming(Composite composite) { + boolean actualValue = getSwtRendererPreference(PartRenderingEngine.ENABLED_THEME_KEY, + PartRenderingEngine.ENABLED_THEME_KEY_DEFAULT); + themingEnabled = createCheckButton(composite, WorkbenchMessages.ThemingEnabled, actualValue); + } + protected void createShowFullTextForViewTabs(Composite composite) { boolean actualValue = getSwtRendererPreference(CTabRendering.SHOW_FULL_TEXT_FOR_VIEW_TABS, CTabRendering.SHOW_FULL_TEXT_FOR_VIEW_TABS_DEFAULT); @@ -277,6 +266,27 @@ public void widgetDefaultSelected(SelectionEvent e) { parent.addSelectionListener(listener); } + private void updateThemingEnablement() { + themingEnabled.setSelection(getSwtRendererPreference(PartRenderingEngine.ENABLED_THEME_KEY, + PartRenderingEngine.ENABLED_THEME_KEY_DEFAULT)); + + SelectionListener listener = new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent e) { + boolean isThemingEnabled = themingEnabled.getSelection(); + themeDependentComp.setVisible(isThemingEnabled); + GridData gridData = ((GridData) themeDependentComp.getLayoutData()); + gridData.exclude = !isThemingEnabled; + themeDependentComp.getParent().layout(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }; + themingEnabled.addSelectionListener(listener); + } + private List getCSSThemes(boolean highContrastMode) { ArrayList themes = new ArrayList<>(); for (ITheme theme : engine.getThemes()) { @@ -454,6 +464,8 @@ protected void performDefaults() { IPreferenceStore apiStore = PrefUtil.getAPIPreferenceStore(); useColoredLabels.setSelection(apiStore.getDefaultBoolean(IWorkbenchPreferenceConstants.USE_COLORED_LABELS)); + themingEnabled.setSelection(defaultPrefs.getBoolean(PartRenderingEngine.ENABLED_THEME_KEY, + PartRenderingEngine.ENABLED_THEME_KEY_DEFAULT)); useRoundTabs.setSelection( defaultPrefs.getBoolean(CTabRendering.USE_ROUND_TABS, CTabRendering.USE_ROUND_TABS_DEFAULT)); enableMru.setSelection(defaultPrefs.getBoolean(StackRenderer.MRU_KEY_DEFAULT, StackRenderer.MRU_DEFAULT)); @@ -473,6 +485,41 @@ public boolean performCancel() { return super.performCancel(); } + private void createThemeIdCombo(Composite composite) { + new Label(composite, SWT.NONE).setText(WorkbenchMessages.ViewsPreferencePage_Theme); + highContrastMode = composite.getDisplay().getHighContrast(); + + themeIdCombo = new ComboViewer(composite, SWT.READ_ONLY); + themeIdCombo.setLabelProvider(new LabelProvider() { + @Override + public String getText(Object element) { + return ((ITheme) element).getLabel(); + } + }); + themeIdCombo.setContentProvider(ArrayContentProvider.getInstance()); + themeIdCombo.setInput(getCSSThemes(highContrastMode)); + themeIdCombo.getCombo().setEnabled(!highContrastMode); + themeIdCombo.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + this.currentTheme = engine.getActiveTheme(); + if (this.currentTheme != null) { + themeIdCombo.setSelection(new StructuredSelection(currentTheme)); + } + themeComboDecorator = new ControlDecoration(themeIdCombo.getCombo(), SWT.TOP | SWT.LEFT); + themeIdCombo.addSelectionChangedListener(event -> { + ITheme selection = getSelectedTheme(); + if (!selection.equals(currentTheme)) { + themeComboDecorator.setDescriptionText(WorkbenchMessages.ThemeChangeWarningText); + Image decorationImage = FieldDecorationRegistry.getDefault() + .getFieldDecoration(FieldDecorationRegistry.DEC_WARNING).getImage(); + themeComboDecorator.setImage(decorationImage); + themeComboDecorator.show(); + } else { + themeComboDecorator.hide(); + } + selectColorsAndFontsTheme(getColorAndFontThemeIdByThemeId(selection.getId())); + }); + } + private void createColorsAndFontsThemeCombo(Composite composite) { new Label(composite, SWT.NONE).setText(WorkbenchMessages.ViewsPreference_currentTheme); colorsAndFontsThemeCombo = new ComboViewer(composite, SWT.READ_ONLY);