Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to issue #2522 Enable Theming Checkbox #2606

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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)) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<ITheme> getCSSThemes(boolean highContrastMode) {
ArrayList<ITheme> themes = new ArrayList<>();
for (ITheme theme : engine.getThemes()) {
Expand Down Expand Up @@ -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));
Expand All @@ -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);
Expand Down