Skip to content

Commit bf2f122

Browse files
committed
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.
1 parent a086677 commit bf2f122

5 files changed

Lines changed: 51 additions & 3 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.getUseDisabledIcons()) {
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.100.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: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@
5656
@NoExtend
5757
public class ActionContributionItem extends ContributionItem {
5858

59+
/**
60+
* System property for specifying whether custom disabled icons for actions
61+
* shall be used or whether all disabled icons shall be generated on-the-fly.
62+
*/
63+
private static final String SYSTEM_PROPERTY_USE_DISABLED_ICONS = "org.eclipse.jface.action.useDisabledIcons"; //$NON-NLS-1$
64+
5965
/**
6066
* Mode bit: Show text on tool items or buttons, even if an image is
6167
* 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) {
96102
USE_COLOR_ICONS = useColorIcons;
97103
}
98104

105+
private static boolean USE_DISABLED_ICONS = Boolean.getBoolean(SYSTEM_PROPERTY_USE_DISABLED_ICONS);
106+
107+
/**
108+
* Returns whether disabled icons assigned to actions shall be used or whether
109+
* all such disabled icons shall be generated on-the-fly.
110+
*
111+
* @return <code>true</code> if disabled icons assigned to actions shall be
112+
* used, <code>false</code> otherwise
113+
* @since 3.40
114+
*/
115+
public static boolean getUseDisabledIcons() {
116+
return USE_DISABLED_ICONS;
117+
}
118+
119+
/**
120+
* Sets whether disabled icons assigned to actions shall be used or whether all
121+
* such disabled icons shall be generated on-the-fly.
122+
*
123+
* @param useDisabledIcons <code>true</code> if disabled icons set to actions
124+
* shall be used, <code>false</code> otherwise
125+
* @since 3.40
126+
*/
127+
public static void setUseDisabledIcons(boolean useDisabledIcons) {
128+
USE_DISABLED_ICONS = useDisabledIcons;
129+
}
130+
99131
/**
100132
* The presentation mode.
101133
*/
@@ -988,7 +1020,10 @@ private boolean updateImages(boolean forceImage) {
9881020
if (widget instanceof ToolItem) {
9891021
ImageDescriptor image = action.getImageDescriptor();
9901022
ImageDescriptor hoverImage = action.getHoverImageDescriptor();
991-
ImageDescriptor disabledImage = action.getDisabledImageDescriptor();
1023+
ImageDescriptor disabledImage = null;
1024+
if (getUseDisabledIcons()) {
1025+
disabledImage = action.getDisabledImageDescriptor();
1026+
}
9921027
// Make sure there is a valid image in case images are forced.
9931028
if (image == null && forceImage) {
9941029
image = ImageDescriptor.getMissingImageDescriptor();

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.getUseDisabledIcons()) {
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();

tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/action/ToolBarManagerTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,10 @@ protected Control createControl(Composite parent) {
141141
@Test
142142
public void testDefaultImageIsGray() {
143143
boolean oldState = ActionContributionItem.getUseColorIconsInToolbars();
144+
boolean oldStateUseDisabled = ActionContributionItem.getUseDisabledIcons();
144145
try {
145146
ActionContributionItem.setUseColorIconsInToolbars(false);
147+
ActionContributionItem.setUseDisabledIcons(true);
146148
ToolBarManager manager = new ToolBarManager();
147149
Action action = new Action("Button with Hover") {
148150
};
@@ -165,14 +167,17 @@ public void testDefaultImageIsGray() {
165167
assertImageEqualsDescriptor(ImageDescriptor.createWithFlags(descriptor, SWT.IMAGE_GRAY), item.getImage());
166168
} finally {
167169
ActionContributionItem.setUseColorIconsInToolbars(oldState);
170+
ActionContributionItem.setUseDisabledIcons(oldStateUseDisabled);
168171
}
169172
}
170173

171174
@Test
172175
public void testActionImagesAreSet() {
173176
boolean oldState = ActionContributionItem.getUseColorIconsInToolbars();
177+
boolean oldStateUseDisabled = ActionContributionItem.getUseDisabledIcons();
174178
try {
175179
ActionContributionItem.setUseColorIconsInToolbars(true);
180+
ActionContributionItem.setUseDisabledIcons(true);
176181
ToolBarManager manager = new ToolBarManager();
177182
Action action = new Action("Button with Hover") {
178183
};
@@ -195,6 +200,7 @@ public void testActionImagesAreSet() {
195200
assertImageEqualsDescriptor(disabledDescriptor, item.getDisabledImage());
196201
} finally {
197202
ActionContributionItem.setUseColorIconsInToolbars(oldState);
203+
ActionContributionItem.setUseDisabledIcons(oldStateUseDisabled);
198204
}
199205
}
200206

0 commit comments

Comments
 (0)