From f5a282cbb2aa4b59d89b54e05b4b467cde5fcc86 Mon Sep 17 00:00:00 2001 From: Yannic Soethoff Date: Wed, 3 Apr 2024 15:17:35 +0200 Subject: [PATCH] Support plugin_customization.ini for e4.ui.workbench.renderer.swt prefs 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. --- .../renderers/swt/CTabRendering.java | 32 ++++++------ .../internal/dialogs/ViewsPreferencePage.java | 49 ++++++++++--------- 2 files changed, 42 insertions(+), 39 deletions(-) diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/CTabRendering.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/CTabRendering.java index 3151ac2d980..afc4e9b25da 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/CTabRendering.java +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/CTabRendering.java @@ -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; @@ -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 @@ -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)); @@ -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); } @@ -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); @@ -1312,7 +1319,7 @@ 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); @@ -1320,10 +1327,6 @@ private void hideIconsForViewTabsPreferenceChanged() { } } - 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); @@ -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); } } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java index e398d5ad8be..5defbcaa271 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java @@ -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; @@ -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 */ @@ -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); @@ -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 @@ -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); } @@ -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) { @@ -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())) { @@ -396,6 +395,8 @@ 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); @@ -403,14 +404,18 @@ protected void performDefaults() { 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(); }