Skip to content

Commit

Permalink
Support plugin_customization.ini for e4.ui.workbench.renderer.swt prefs
Browse files Browse the repository at this point in the history
Before this change, only the InstanceScope was queried explicitly.

Therefore, any preferences set in plugin_customization.ini, which end up
in the DefaultScope, were never respected.

Ideally, we would use org.eclipse.ui.preferences.ScopedPreferenceStore,
but that lies in a layer above us, so cannot be used.

Instead, we use the
org.eclipse.core.runtime.preferences.IPreferencesService when reading
preferences. This searches all relevant scopes in the proper order.

When writing preferences, we write explicitly into InstanceScope.

When performing 'Restore Defaults' in the preference page, we take the
DefaultScope into account.

Fixes #1794.
  • Loading branch information
soethoff committed Apr 3, 2024
1 parent cff785d commit f5a282c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.lang.reflect.Field;
import java.util.Objects;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
Expand Down Expand Up @@ -46,6 +47,11 @@
@SuppressWarnings("restriction")
public class CTabRendering extends CTabFolderRenderer implements ICTabRendering, IPreferenceChangeListener {

/**
* The preference qualifier.
*/
private static final String PREF_QUALIFIER_ECLIPSE_E4_UI_WORKBENCH_RENDERERS_SWT = "org.eclipse.e4.ui.workbench.renderers.swt"; //$NON-NLS-1$

/**
* A named preference for setting CTabFolder's to be rendered with rounded
* corners
Expand Down Expand Up @@ -169,7 +175,8 @@ public CTabRendering(CTabFolder parent) {
super(parent);
parentWrapper = new CTabFolderWrapper(parent);

IEclipsePreferences preferences = getSwtRendererPreferences();
IEclipsePreferences preferences = InstanceScope.INSTANCE
.getNode(PREF_QUALIFIER_ECLIPSE_E4_UI_WORKBENCH_RENDERERS_SWT);
preferences.addPreferenceChangeListener(this);
parent.addDisposeListener(e -> preferences.removePreferenceChangeListener(this));

Expand Down Expand Up @@ -1283,8 +1290,7 @@ public void setSelectedTabHighlightTop(boolean drawTabHiglightOnTop) {
}

private void cornerRadiusPreferenceChanged() {
IEclipsePreferences preferences = getSwtRendererPreferences();
boolean useRound = preferences.getBoolean(USE_ROUND_TABS, USE_ROUND_TABS_DEFAULT);
boolean useRound = getSwtRendererPreference(USE_ROUND_TABS, USE_ROUND_TABS_DEFAULT);
setCornerRadius(useRound ? 16 : 0);
}

Expand All @@ -1300,7 +1306,8 @@ public void preferenceChange(PreferenceChangeEvent event) {
}

private void showFullTextForViewTabsPreferenceChanged() {
boolean showFullText = getShowFullTextForViewTabsPreference();
boolean showFullText = getSwtRendererPreference(SHOW_FULL_TEXT_FOR_VIEW_TABS,
SHOW_FULL_TEXT_FOR_VIEW_TABS_DEFAULT);
if (!isPartOfEditorStack()) {
if (showFullText) {
parent.setMinimumCharacters(MAX_VIEW_CHARS);
Expand All @@ -1312,18 +1319,14 @@ private void showFullTextForViewTabsPreferenceChanged() {
}

private void hideIconsForViewTabsPreferenceChanged() {
boolean hideIcons = getHideIconsForViewTabsPreference();
boolean hideIcons = getSwtRendererPreference(HIDE_ICONS_FOR_VIEW_TABS, HIDE_ICONS_FOR_VIEW_TABS_DEFAULT);
if (!isPartOfEditorStack()) {
parent.setSelectedImageVisible(!hideIcons);
parent.setUnselectedImageVisible(!hideIcons);
parent.redraw();
}
}

private IEclipsePreferences getSwtRendererPreferences() {
return InstanceScope.INSTANCE.getNode("org.eclipse.e4.ui.workbench.renderers.swt"); //$NON-NLS-1$
}

private boolean isPartOfEditorStack() {
MUIElement element = (MUIElement) parent.getData(AbstractPartRenderer.OWNING_ME);
EObject root = EcoreUtil.getRootContainer((EObject) element, true);
Expand All @@ -1337,13 +1340,8 @@ private boolean isPartOfEditorStack() {
return false;
}

private boolean getHideIconsForViewTabsPreference() {
IEclipsePreferences preferences = getSwtRendererPreferences();
return preferences.getBoolean(HIDE_ICONS_FOR_VIEW_TABS, HIDE_ICONS_FOR_VIEW_TABS_DEFAULT);
}

private boolean getShowFullTextForViewTabsPreference() {
IEclipsePreferences preferences = getSwtRendererPreferences();
return preferences.getBoolean(SHOW_FULL_TEXT_FOR_VIEW_TABS, SHOW_FULL_TEXT_FOR_VIEW_TABS_DEFAULT);
private boolean getSwtRendererPreference(String prefName, boolean defaultValue) {
return Platform.getPreferencesService().getBoolean(PREF_QUALIFIER_ECLIPSE_E4_UI_WORKBENCH_RENDERERS_SWT,
prefName, defaultValue, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.RegistryFactory;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.e4.core.contexts.IEclipseContext;
Expand Down Expand Up @@ -90,6 +92,9 @@
* applies to the overall appearance, hence the name.
*/
public class ViewsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {

private static final String PREF_QUALIFIER_ECLIPSE_E4_UI_WORKBENCH_RENDERERS_SWT = "org.eclipse.e4.ui.workbench.renderers.swt"; //$NON-NLS-1$

private static final String E4_THEME_EXTENSION_POINT = "org.eclipse.e4.ui.css.swt.theme"; //$NON-NLS-1$

/** The workbench theme engine; may be {@code null} if no engine */
Expand Down Expand Up @@ -194,8 +199,7 @@ private void createThemeIndependentComposits(Composite comp) {
}

protected void createShowFullTextForViewTabs(Composite composite) {
IEclipsePreferences prefs = getSwtRendererPreferences();
boolean actualValue = prefs.getBoolean(CTabRendering.SHOW_FULL_TEXT_FOR_VIEW_TABS,
boolean actualValue = getSwtRendererPreference(CTabRendering.SHOW_FULL_TEXT_FOR_VIEW_TABS,
CTabRendering.SHOW_FULL_TEXT_FOR_VIEW_TABS_DEFAULT);
createLabel(composite, ""); //$NON-NLS-1$
createLabel(composite, WorkbenchMessages.ViewsPreference_viewTabs_icons_and_titles_label);
Expand All @@ -204,13 +208,17 @@ protected void createShowFullTextForViewTabs(Composite composite) {
}

protected void createHideIconsForViewTabs(Composite composite) {
IEclipsePreferences prefs = getSwtRendererPreferences();
boolean actualValue = prefs.getBoolean(CTabRendering.HIDE_ICONS_FOR_VIEW_TABS,
boolean actualValue = getSwtRendererPreference(CTabRendering.HIDE_ICONS_FOR_VIEW_TABS,
CTabRendering.HIDE_ICONS_FOR_VIEW_TABS_DEFAULT);
hideIconsForViewTabs = createCheckButton(composite, WorkbenchMessages.ViewsPreference_hideIconsForViewTabs,
actualValue);
}

private boolean getSwtRendererPreference(String prefName, boolean defaultValue) {
return Platform.getPreferencesService().getBoolean(PREF_QUALIFIER_ECLIPSE_E4_UI_WORKBENCH_RENDERERS_SWT,
prefName, defaultValue, null);
}

/**
* @param showFullTextForViewTabs
* @param hideIconsForViewTabs
Expand Down Expand Up @@ -287,17 +295,15 @@ private Label createLabel(Composite composite, String text) {
}

protected void createUseRoundTabs(Composite composite) {
IEclipsePreferences prefs = getSwtRendererPreferences();
boolean enabled = prefs.getBoolean(CTabRendering.USE_ROUND_TABS, CTabRendering.USE_ROUND_TABS_DEFAULT);
boolean enabled = getSwtRendererPreference(CTabRendering.USE_ROUND_TABS, CTabRendering.USE_ROUND_TABS_DEFAULT);
useRoundTabs = createCheckButton(composite, WorkbenchMessages.ViewsPreference_useRoundTabs, enabled);
}

protected void createEnableMruPref(Composite composite) {
createLabel(composite, ""); //$NON-NLS-1$
createLabel(composite, WorkbenchMessages.ViewsPreference_visibleTabs_description);
IEclipsePreferences prefs = getSwtRendererPreferences();
boolean defaultValue = getDefaultMRUValue();
boolean actualValue = prefs.getBoolean(StackRenderer.MRU_KEY, defaultValue);
boolean defaultValue = getSwtRendererPreference(StackRenderer.MRU_KEY_DEFAULT, StackRenderer.MRU_DEFAULT);
boolean actualValue = getSwtRendererPreference(StackRenderer.MRU_KEY, defaultValue);
enableMru = createCheckButton(composite, WorkbenchMessages.ViewsPreference_enableMRU, actualValue);
}

Expand All @@ -316,7 +322,8 @@ public void init(IWorkbench workbench) {

@Override
public boolean performOk() {
IEclipsePreferences prefs = getSwtRendererPreferences();
IEclipsePreferences prefs = InstanceScope.INSTANCE
.getNode(PREF_QUALIFIER_ECLIPSE_E4_UI_WORKBENCH_RENDERERS_SWT);
if (engine != null) {
ITheme theme = getSelectedTheme();
if (theme != null) {
Expand Down Expand Up @@ -379,14 +386,6 @@ private void showRestartDialog() {
}
}

private IEclipsePreferences getSwtRendererPreferences() {
return InstanceScope.INSTANCE.getNode("org.eclipse.e4.ui.workbench.renderers.swt"); //$NON-NLS-1$
}

private boolean getDefaultMRUValue() {
return getSwtRendererPreferences().getBoolean(StackRenderer.MRU_KEY_DEFAULT, StackRenderer.MRU_DEFAULT);
}

private void setColorsAndFontsTheme(ColorsAndFontsTheme theme) {
org.eclipse.ui.themes.ITheme currentTheme = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme();
if (theme != null && !currentTheme.getId().equals(theme.getId())) {
Expand All @@ -396,21 +395,27 @@ private void setColorsAndFontsTheme(ColorsAndFontsTheme theme) {

@Override
protected void performDefaults() {
IEclipsePreferences defaultPrefs = DefaultScope.INSTANCE
.getNode(PREF_QUALIFIER_ECLIPSE_E4_UI_WORKBENCH_RENDERERS_SWT);
if (engine != null) {
setColorsAndFontsTheme(currentColorsAndFontsTheme);

engine.setTheme(defaultTheme, true);
if (engine.getActiveTheme() != null) {
themeIdCombo.setSelection(new StructuredSelection(engine.getActiveTheme()));
}
hideIconsForViewTabs.setSelection(CTabRendering.HIDE_ICONS_FOR_VIEW_TABS_DEFAULT);
showFullTextForViewTabs.setSelection(CTabRendering.SHOW_FULL_TEXT_FOR_VIEW_TABS_DEFAULT);
hideIconsForViewTabs.setSelection(defaultPrefs.getBoolean(CTabRendering.HIDE_ICONS_FOR_VIEW_TABS,
CTabRendering.HIDE_ICONS_FOR_VIEW_TABS_DEFAULT));
showFullTextForViewTabs.setSelection(defaultPrefs.getBoolean(CTabRendering.SHOW_FULL_TEXT_FOR_VIEW_TABS,
CTabRendering.SHOW_FULL_TEXT_FOR_VIEW_TABS_DEFAULT));
showFullTextForViewTabs.notifyListeners(SWT.Selection, null);
}
IPreferenceStore apiStore = PrefUtil.getAPIPreferenceStore();
useColoredLabels.setSelection(apiStore.getDefaultBoolean(IWorkbenchPreferenceConstants.USE_COLORED_LABELS));

useRoundTabs.setSelection(CTabRendering.USE_ROUND_TABS_DEFAULT);
enableMru.setSelection(getDefaultMRUValue());
useRoundTabs.setSelection(
defaultPrefs.getBoolean(CTabRendering.USE_ROUND_TABS, CTabRendering.USE_ROUND_TABS_DEFAULT));
enableMru.setSelection(defaultPrefs.getBoolean(StackRenderer.MRU_KEY_DEFAULT, StackRenderer.MRU_DEFAULT));
super.performDefaults();
}

Expand Down

0 comments on commit f5a282c

Please sign in to comment.