Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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$
}
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.eclipse.jface/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <code>true</code> if disabled icons assigned to actions shall be
* used, <code>false</code> 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 <code>true</code> if disabled icons set to actions
* shall be used, <code>false</code> otherwise
* @since 3.40
*/
public static void setUseDisabledIcons(boolean useDisabledIcons) {
USE_DISABLED_ICONS = useDisabledIcons;
}

/**
* The presentation mode.
*/
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
};
Expand All @@ -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") {
};
Expand All @@ -195,6 +200,7 @@ public void testActionImagesAreSet() {
assertImageEqualsDescriptor(disabledDescriptor, item.getDisabledImage());
} finally {
ActionContributionItem.setUseColorIconsInToolbars(oldState);
ActionContributionItem.setUseDisabledIcons(oldStateUseDisabled);
}
}

Expand Down
Loading