Skip to content

Commit 04547fb

Browse files
committed
Allow to ignore explicitly defined disabled icons
The algorithm for generating disabled icons on-the-fly has recently been enhanced. Most explicit disabled icons that have been embedded into bundles conform to what now can be generated on-the-fly. In addition, the algorithm is interchangeable, allowing custom stylings of disabled icons. However, when there are still bundles, such as extensions out of own control, that still explicitly define disabled icons, exchanging the algorithm for disabled icons will lead to inconsistent appearance as only the on-the-fly generated icons will adhere to that. This change allows to ignore explicitly defined disabled icons, such that even if some bundles defined disabled icons, they will be ignored and on-the-fly generated disabled icons according to the selected algorithm will be used instead. An according preference that can be configured via the appearance tab is added.
1 parent e6d3cbf commit 04547fb

12 files changed

Lines changed: 94 additions & 4 deletions

File tree

bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/AbstractContributionItem.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.eclipse.e4.ui.workbench.modeling.EModelService;
3939
import org.eclipse.e4.ui.workbench.swt.util.ISWTResourceUtilities;
4040
import org.eclipse.emf.common.util.URI;
41+
import org.eclipse.jface.action.ActionContributionItem;
4142
import org.eclipse.jface.action.ContributionItem;
4243
import org.eclipse.jface.action.IContributionManager;
4344
import org.eclipse.jface.action.IMenuCreator;
@@ -211,6 +212,9 @@ protected void updateIcons() {
211212
}
212213

213214
private String getDisabledIconURI(MItem toolItem) {
215+
if (ActionContributionItem.getIgnoreDisabledIcons()) {
216+
return ""; //$NON-NLS-1$
217+
}
214218
Object obj = toolItem.getTransientData().get(IPresentationEngine.DISABLED_ICON_IMAGE_KEY);
215219
return obj instanceof String s ? s : ""; //$NON-NLS-1$
216220
}

bundles/org.eclipse.jface/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.jface;singleton:=true
5-
Bundle-Version: 3.39.0.qualifier
5+
Bundle-Version: 3.40.0.qualifier
66
Bundle-Vendor: %providerName
77
Bundle-Localization: plugin
88
Export-Package: org.eclipse.jface,

bundles/org.eclipse.jface/src/org/eclipse/jface/action/ActionContributionItem.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,33 @@ public static void setUseColorIconsInToolbars(boolean useColorIcons) {
9696
USE_COLOR_ICONS = useColorIcons;
9797
}
9898

99+
private static boolean IGNORE_DISABLED_ICONS = false;
100+
101+
/**
102+
* Returns whether explicitly defined disabled icons should be ignored, such
103+
* that all disabled icons are generated on-the-fly.
104+
*
105+
* @return <code>true</code> if disabled icons set to tool items should be
106+
* ignored, <code>false</code> otherwise
107+
* @since 3.40
108+
*/
109+
public static boolean getIgnoreDisabledIcons() {
110+
return IGNORE_DISABLED_ICONS;
111+
}
112+
113+
/**
114+
* Sets whether explicitly defined disabled icons should be ignored, such that
115+
* all disabled icons are generated on-the-fly.
116+
*
117+
* @param ignoreDisabledIcons <code>true</code> if disabled icons set to tool
118+
* items should be ignored, <code>false</code>
119+
* otherwise
120+
* @since 3.40
121+
*/
122+
public static void setIgnoreDisabledIcons(boolean ignoreDisabledIcons) {
123+
IGNORE_DISABLED_ICONS = ignoreDisabledIcons;
124+
}
125+
99126
/**
100127
* The presentation mode.
101128
*/
@@ -988,7 +1015,10 @@ private boolean updateImages(boolean forceImage) {
9881015
if (widget instanceof ToolItem) {
9891016
ImageDescriptor image = action.getImageDescriptor();
9901017
ImageDescriptor hoverImage = action.getHoverImageDescriptor();
991-
ImageDescriptor disabledImage = action.getDisabledImageDescriptor();
1018+
ImageDescriptor disabledImage = null;
1019+
if (!getIgnoreDisabledIcons()) {
1020+
disabledImage = action.getDisabledImageDescriptor();
1021+
}
9921022
// Make sure there is a valid image in case images are forced.
9931023
if (image == null && forceImage) {
9941024
image = ImageDescriptor.getMissingImageDescriptor();

bundles/org.eclipse.ui.workbench/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.ui.workbench; singleton:=true
5-
Bundle-Version: 3.138.100.qualifier
5+
Bundle-Version: 3.139.0.qualifier
66
Bundle-Activator: org.eclipse.ui.internal.WorkbenchPlugin
77
Bundle-ActivationPolicy: lazy
88
Bundle-Vendor: %providerName

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/IWorkbenchPreferenceConstants.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,4 +721,15 @@ public interface IWorkbenchPreferenceConstants {
721721
* @since 3.134
722722
*/
723723
String RESCALING_AT_RUNTIME = "monitorSpecificScaling"; //$NON-NLS-1$
724+
725+
/**
726+
* <p>
727+
* Whether explicitly defined disabled icons shall be ignored in favor of using
728+
* on-the-fly generated disabled icons.
729+
* </p>
730+
*
731+
* @since 3.139
732+
*/
733+
String IGNORE_DISABLED_ICONS = "ignoreDisabledIcons"; //$NON-NLS-1$
734+
724735
}

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchMessages.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,9 @@ public class WorkbenchMessages extends NLS {
481481
public static String ViewsPreference_viewTabs_icons_and_titles_label;
482482
public static String ViewsPreference_showFullTextForViewTabs;
483483
public static String ViewsPreference_hideIconsForViewTabs;
484+
public static String ViewsPreference_disabledIcons_description;
485+
public static String ViewsPreference_ignoreDisabledIcons;
486+
public static String ViewsPreference_ignoreDisabledIcons_tooltip;
484487
public static String ToggleFullScreenMode_ActivationPopup_Description;
485488
public static String ToggleFullScreenMode_ActivationPopup_Description_NoKeybinding;
486489
public static String ToggleFullScreenMode_ActivationPopup_DoNotShowAgain;

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public class ViewsPreferencePage extends PreferencePage implements IWorkbenchPre
115115

116116
private Button themingEnabled;
117117
private Button rescaleAtRuntime;
118+
private Button ignoreDisabledIcons;
118119

119120
private Button hideIconsForViewTabs;
120121
private Button showFullTextForViewTabs;
@@ -140,6 +141,7 @@ protected Control createContents(Composite parent) {
140141
layout.horizontalSpacing = 10;
141142
comp.setLayout(layout);
142143
createThemeIndependentComposits(comp);
144+
createDisabledIconsButtons(comp);
143145
createRescaleAtRuntimeCheckButton(comp);
144146
return comp;
145147
}
@@ -184,6 +186,7 @@ protected Control createContents(Composite parent) {
184186
createHideIconsForViewTabs(comp);
185187
createDependency(showFullTextForViewTabs, hideIconsForViewTabs);
186188

189+
createDisabledIconsButtons(comp);
187190
createRescaleAtRuntimeCheckButton(comp);
188191

189192
if (currentTheme != null) {
@@ -235,6 +238,17 @@ private void createRescaleAtRuntimeCheckButton(Composite parent) {
235238
}
236239
}
237240

241+
private void createDisabledIconsButtons(Composite parent) {
242+
createLabel(parent, ""); //$NON-NLS-1$
243+
createLabel(parent, WorkbenchMessages.ViewsPreference_disabledIcons_description);
244+
245+
boolean initialStateIgnoreDisabledIcons = PrefUtil.getAPIPreferenceStore()
246+
.getBoolean(IWorkbenchPreferenceConstants.IGNORE_DISABLED_ICONS);
247+
ignoreDisabledIcons = createCheckButton(parent, WorkbenchMessages.ViewsPreference_ignoreDisabledIcons,
248+
initialStateIgnoreDisabledIcons);
249+
ignoreDisabledIcons.setToolTipText(WorkbenchMessages.ViewsPreference_ignoreDisabledIcons_tooltip);
250+
}
251+
238252
private void createThemeIndependentComposits(Composite comp) {
239253
createUseRoundTabs(comp);
240254
createColoredLabelsPref(comp);
@@ -364,6 +378,8 @@ public boolean performOk() {
364378
.getSelection();
365379
prefs.putBoolean(PartRenderingEngine.ENABLED_THEME_KEY, themingEnabled.getSelection());
366380
}
381+
PrefUtil.getAPIPreferenceStore().setValue(IWorkbenchPreferenceConstants.IGNORE_DISABLED_ICONS,
382+
ignoreDisabledIcons.getSelection());
367383

368384
boolean isRescaleAtRuntimeChanged = false;
369385
if (rescaleAtRuntime != null) {
@@ -467,6 +483,8 @@ protected void performDefaults() {
467483
}
468484
IPreferenceStore apiStore = PrefUtil.getAPIPreferenceStore();
469485
useColoredLabels.setSelection(apiStore.getDefaultBoolean(IWorkbenchPreferenceConstants.USE_COLORED_LABELS));
486+
ignoreDisabledIcons
487+
.setSelection(apiStore.getDefaultBoolean(IWorkbenchPreferenceConstants.IGNORE_DISABLED_ICONS));
470488

471489
useRoundTabs.setSelection(
472490
defaultPrefs.getBoolean(CTabRendering.USE_ROUND_TABS, CTabRendering.USE_ROUND_TABS_DEFAULT));

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/messages.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,9 @@ ViewsPreference_enableMRU = Show &most recently used tabs
435435
ViewsPreference_showFullTextForViewTabs = Always show full titles
436436
ViewsPreference_hideIconsForViewTabs = Hide icons
437437
ViewsPreference_viewTabs_icons_and_titles_label = Tab icons and titles in view areas:
438+
ViewsPreference_disabledIcons_description = Icons for disabled actions:
439+
ViewsPreference_ignoreDisabledIcons = Ignore pre-generated disabled icons
440+
ViewsPreference_ignoreDisabledIcons_tooltip = When enabled ignores pre-generated disabled icons in favor of generating consistently styled disabled icons on the fly
438441
ToggleFullScreenMode_ActivationPopup_Description=You have gone full screen. Use the Toggle Full Screen command ({0}) to deactivate.
439442
ToggleFullScreenMode_ActivationPopup_Description_NoKeybinding=You have gone full screen. Use the Toggle Full Screen command to deactivate.
440443
ToggleFullScreenMode_ActivationPopup_DoNotShowAgain=Do not show again

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/menus/CommandContributionItem.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.eclipse.core.commands.common.NotDefinedException;
2929
import org.eclipse.core.runtime.IStatus;
3030
import org.eclipse.core.runtime.Status;
31+
import org.eclipse.jface.action.ActionContributionItem;
3132
import org.eclipse.jface.action.ContributionItem;
3233
import org.eclipse.jface.action.IContributionManager;
3334
import org.eclipse.jface.action.IMenuListener2;
@@ -892,7 +893,9 @@ private void updateIcons() {
892893
localResourceManager = m;
893894
} else if (widget instanceof ToolItem item) {
894895
LocalResourceManager m = new LocalResourceManager(JFaceResources.getResources());
895-
item.setDisabledImage(disabledIcon == null ? null : m.create(disabledIcon));
896+
if (!ActionContributionItem.getIgnoreDisabledIcons()) {
897+
item.setDisabledImage(disabledIcon == null ? null : m.create(disabledIcon));
898+
}
896899
item.setHotImage(hoverIcon == null ? null : m.create(hoverIcon));
897900
item.setImage(icon == null ? null : m.create(icon));
898901
disposeOldImages();

bundles/org.eclipse.ui/src/org/eclipse/ui/internal/UIPlugin.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
package org.eclipse.ui.internal;
1515

1616
import org.eclipse.core.runtime.Assert;
17+
import org.eclipse.jface.action.ActionContributionItem;
1718
import org.eclipse.jface.preference.IPreferenceStore;
1819
import org.eclipse.jface.resource.ImageRegistry;
20+
import org.eclipse.ui.IWorkbenchPreferenceConstants;
1921
import org.eclipse.ui.internal.util.PrefUtil;
2022
import org.eclipse.ui.plugin.AbstractUIPlugin;
2123
import org.osgi.framework.BundleContext;
@@ -98,5 +100,14 @@ public void savePreferences() {
98100
UIPlugin.this.savePluginPreferences();
99101
}
100102
});
103+
initializeIconConfigurations();
101104
}
105+
106+
private void initializeIconConfigurations() {
107+
// configure disabled icons appearance
108+
boolean ignoreDisabledIcons = PrefUtil.getAPIPreferenceStore()
109+
.getBoolean(IWorkbenchPreferenceConstants.IGNORE_DISABLED_ICONS);
110+
ActionContributionItem.setIgnoreDisabledIcons(ignoreDisabledIcons);
111+
}
112+
102113
}

0 commit comments

Comments
 (0)