From bf2f122d027ece08acacf453d04fd3cbef1fb4fa Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Wed, 22 Oct 2025 18:15:56 +0200 Subject: [PATCH] Allow to ignore custom disabled icons The algorithm for generating disabled icons on-the-fly has recently been enhanced. Most custom 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 contain custom 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 custom 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. This is enabled by default and can be configured via system property. --- .../swt/AbstractContributionItem.java | 4 ++ .../org.eclipse.jface/META-INF/MANIFEST.MF | 2 +- .../jface/action/ActionContributionItem.java | 37 ++++++++++++++++++- .../ui/menus/CommandContributionItem.java | 5 ++- .../tests/action/ToolBarManagerTest.java | 6 +++ 5 files changed, 51 insertions(+), 3 deletions(-) diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/AbstractContributionItem.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/AbstractContributionItem.java index 020601182d7..0202ecd1e8a 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/AbstractContributionItem.java +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/AbstractContributionItem.java @@ -38,6 +38,7 @@ import org.eclipse.e4.ui.workbench.modeling.EModelService; import org.eclipse.e4.ui.workbench.swt.util.ISWTResourceUtilities; import org.eclipse.emf.common.util.URI; +import org.eclipse.jface.action.ActionContributionItem; import org.eclipse.jface.action.ContributionItem; import org.eclipse.jface.action.IContributionManager; import org.eclipse.jface.action.IMenuCreator; @@ -211,6 +212,9 @@ protected void updateIcons() { } private String getDisabledIconURI(MItem toolItem) { + if (!ActionContributionItem.getUseDisabledIcons()) { + return ""; //$NON-NLS-1$ + } Object obj = toolItem.getTransientData().get(IPresentationEngine.DISABLED_ICON_IMAGE_KEY); return obj instanceof String s ? s : ""; //$NON-NLS-1$ } diff --git a/bundles/org.eclipse.jface/META-INF/MANIFEST.MF b/bundles/org.eclipse.jface/META-INF/MANIFEST.MF index a28edbfee32..a627f5c1706 100644 --- a/bundles/org.eclipse.jface/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.jface/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.jface;singleton:=true -Bundle-Version: 3.39.100.qualifier +Bundle-Version: 3.40.0.qualifier Bundle-Vendor: %providerName Bundle-Localization: plugin Export-Package: org.eclipse.jface, diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/action/ActionContributionItem.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/action/ActionContributionItem.java index 7cc82c7d5db..cc18c765055 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/action/ActionContributionItem.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/action/ActionContributionItem.java @@ -56,6 +56,12 @@ @NoExtend public class ActionContributionItem extends ContributionItem { + /** + * System property for specifying whether custom disabled icons for actions + * shall be used or whether all disabled icons shall be generated on-the-fly. + */ + private static final String SYSTEM_PROPERTY_USE_DISABLED_ICONS = "org.eclipse.jface.action.useDisabledIcons"; //$NON-NLS-1$ + /** * Mode bit: Show text on tool items or buttons, even if an image is * present. If this mode bit is not set, text is only shown on tool items if @@ -96,6 +102,32 @@ public static void setUseColorIconsInToolbars(boolean useColorIcons) { USE_COLOR_ICONS = useColorIcons; } + private static boolean USE_DISABLED_ICONS = Boolean.getBoolean(SYSTEM_PROPERTY_USE_DISABLED_ICONS); + + /** + * Returns whether disabled icons assigned to actions shall be used or whether + * all such disabled icons shall be generated on-the-fly. + * + * @return true if disabled icons assigned to actions shall be + * used, false otherwise + * @since 3.40 + */ + public static boolean getUseDisabledIcons() { + return USE_DISABLED_ICONS; + } + + /** + * Sets whether disabled icons assigned to actions shall be used or whether all + * such disabled icons shall be generated on-the-fly. + * + * @param useDisabledIcons true if disabled icons set to actions + * shall be used, false otherwise + * @since 3.40 + */ + public static void setUseDisabledIcons(boolean useDisabledIcons) { + USE_DISABLED_ICONS = useDisabledIcons; + } + /** * The presentation mode. */ @@ -988,7 +1020,10 @@ private boolean updateImages(boolean forceImage) { if (widget instanceof ToolItem) { ImageDescriptor image = action.getImageDescriptor(); ImageDescriptor hoverImage = action.getHoverImageDescriptor(); - ImageDescriptor disabledImage = action.getDisabledImageDescriptor(); + ImageDescriptor disabledImage = null; + if (getUseDisabledIcons()) { + disabledImage = action.getDisabledImageDescriptor(); + } // Make sure there is a valid image in case images are forced. if (image == null && forceImage) { image = ImageDescriptor.getMissingImageDescriptor(); diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/menus/CommandContributionItem.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/menus/CommandContributionItem.java index 5fdbaa986e8..d5134e73c6d 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/menus/CommandContributionItem.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/menus/CommandContributionItem.java @@ -28,6 +28,7 @@ import org.eclipse.core.commands.common.NotDefinedException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.jface.action.ActionContributionItem; import org.eclipse.jface.action.ContributionItem; import org.eclipse.jface.action.IContributionManager; import org.eclipse.jface.action.IMenuListener2; @@ -892,7 +893,9 @@ private void updateIcons() { localResourceManager = m; } else if (widget instanceof ToolItem item) { LocalResourceManager m = new LocalResourceManager(JFaceResources.getResources()); - item.setDisabledImage(disabledIcon == null ? null : m.create(disabledIcon)); + if (ActionContributionItem.getUseDisabledIcons()) { + item.setDisabledImage(disabledIcon == null ? null : m.create(disabledIcon)); + } item.setHotImage(hoverIcon == null ? null : m.create(hoverIcon)); item.setImage(icon == null ? null : m.create(icon)); disposeOldImages(); diff --git a/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/action/ToolBarManagerTest.java b/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/action/ToolBarManagerTest.java index 889b98522b4..4aaa33fd7f3 100644 --- a/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/action/ToolBarManagerTest.java +++ b/tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/action/ToolBarManagerTest.java @@ -141,8 +141,10 @@ protected Control createControl(Composite parent) { @Test public void testDefaultImageIsGray() { boolean oldState = ActionContributionItem.getUseColorIconsInToolbars(); + boolean oldStateUseDisabled = ActionContributionItem.getUseDisabledIcons(); try { ActionContributionItem.setUseColorIconsInToolbars(false); + ActionContributionItem.setUseDisabledIcons(true); ToolBarManager manager = new ToolBarManager(); Action action = new Action("Button with Hover") { }; @@ -165,14 +167,17 @@ public void testDefaultImageIsGray() { assertImageEqualsDescriptor(ImageDescriptor.createWithFlags(descriptor, SWT.IMAGE_GRAY), item.getImage()); } finally { ActionContributionItem.setUseColorIconsInToolbars(oldState); + ActionContributionItem.setUseDisabledIcons(oldStateUseDisabled); } } @Test public void testActionImagesAreSet() { boolean oldState = ActionContributionItem.getUseColorIconsInToolbars(); + boolean oldStateUseDisabled = ActionContributionItem.getUseDisabledIcons(); try { ActionContributionItem.setUseColorIconsInToolbars(true); + ActionContributionItem.setUseDisabledIcons(true); ToolBarManager manager = new ToolBarManager(); Action action = new Action("Button with Hover") { }; @@ -195,6 +200,7 @@ public void testActionImagesAreSet() { assertImageEqualsDescriptor(disabledDescriptor, item.getDisabledImage()); } finally { ActionContributionItem.setUseColorIconsInToolbars(oldState); + ActionContributionItem.setUseDisabledIcons(oldStateUseDisabled); } }