Skip to content

Commit 414e679

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 ed75400 commit 414e679

File tree

12 files changed

+94
-4
lines changed

12 files changed

+94
-4
lines changed

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.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: 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
@@ -480,6 +480,9 @@ public class WorkbenchMessages extends NLS {
480480
public static String ViewsPreference_viewTabs_icons_and_titles_label;
481481
public static String ViewsPreference_showFullTextForViewTabs;
482482
public static String ViewsPreference_hideIconsForViewTabs;
483+
public static String ViewsPreference_disabledIcons_description;
484+
public static String ViewsPreference_ignoreDisabledIcons;
485+
public static String ViewsPreference_ignoreDisabledIcons_tooltip;
483486
public static String ToggleFullScreenMode_ActivationPopup_Description;
484487
public static String ToggleFullScreenMode_ActivationPopup_Description_NoKeybinding;
485488
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
@@ -114,6 +114,7 @@ public class ViewsPreferencePage extends PreferencePage implements IWorkbenchPre
114114

115115
private Button themingEnabled;
116116
private Button rescaleAtRuntime;
117+
private Button ignoreDisabledIcons;
117118

118119
private Button hideIconsForViewTabs;
119120
private Button showFullTextForViewTabs;
@@ -139,6 +140,7 @@ protected Control createContents(Composite parent) {
139140
layout.horizontalSpacing = 10;
140141
comp.setLayout(layout);
141142
createThemeIndependentComposits(comp);
143+
createDisabledIconsButtons(comp);
142144
createRescaleAtRuntimeCheckButton(comp);
143145
return comp;
144146
}
@@ -183,6 +185,7 @@ protected Control createContents(Composite parent) {
183185
createHideIconsForViewTabs(comp);
184186
createDependency(showFullTextForViewTabs, hideIconsForViewTabs);
185187

188+
createDisabledIconsButtons(comp);
186189
createRescaleAtRuntimeCheckButton(comp);
187190

188191
if (currentTheme != null) {
@@ -234,6 +237,17 @@ private void createRescaleAtRuntimeCheckButton(Composite parent) {
234237
}
235238
}
236239

240+
private void createDisabledIconsButtons(Composite parent) {
241+
createLabel(parent, ""); //$NON-NLS-1$
242+
createLabel(parent, WorkbenchMessages.ViewsPreference_disabledIcons_description);
243+
244+
boolean initialStateIgnoreDisabledIcons = PrefUtil.getAPIPreferenceStore()
245+
.getBoolean(IWorkbenchPreferenceConstants.IGNORE_DISABLED_ICONS);
246+
ignoreDisabledIcons = createCheckButton(parent, WorkbenchMessages.ViewsPreference_ignoreDisabledIcons,
247+
initialStateIgnoreDisabledIcons);
248+
ignoreDisabledIcons.setToolTipText(WorkbenchMessages.ViewsPreference_ignoreDisabledIcons_tooltip);
249+
}
250+
237251
private void createThemeIndependentComposits(Composite comp) {
238252
createColoredLabelsPref(comp);
239253
createEnableMruPref(comp);
@@ -357,6 +371,8 @@ public boolean performOk() {
357371
.getSelection();
358372
prefs.putBoolean(PartRenderingEngine.ENABLED_THEME_KEY, themingEnabled.getSelection());
359373
}
374+
PrefUtil.getAPIPreferenceStore().setValue(IWorkbenchPreferenceConstants.IGNORE_DISABLED_ICONS,
375+
ignoreDisabledIcons.getSelection());
360376

361377
boolean isRescaleAtRuntimeChanged = false;
362378
if (rescaleAtRuntime != null) {
@@ -459,6 +475,8 @@ protected void performDefaults() {
459475
}
460476
IPreferenceStore apiStore = PrefUtil.getAPIPreferenceStore();
461477
useColoredLabels.setSelection(apiStore.getDefaultBoolean(IWorkbenchPreferenceConstants.USE_COLORED_LABELS));
478+
ignoreDisabledIcons
479+
.setSelection(apiStore.getDefaultBoolean(IWorkbenchPreferenceConstants.IGNORE_DISABLED_ICONS));
462480

463481
enableMru.setSelection(defaultPrefs.getBoolean(StackRenderer.MRU_KEY_DEFAULT, StackRenderer.MRU_DEFAULT));
464482
super.performDefaults();

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
@@ -434,6 +434,9 @@ ViewsPreference_enableMRU = Show &most recently used tabs
434434
ViewsPreference_showFullTextForViewTabs = Always show full titles
435435
ViewsPreference_hideIconsForViewTabs = Hide icons
436436
ViewsPreference_viewTabs_icons_and_titles_label = Tab icons and titles in view areas:
437+
ViewsPreference_disabledIcons_description = Icons for disabled actions:
438+
ViewsPreference_ignoreDisabledIcons = Ignore pre-generated disabled icons
439+
ViewsPreference_ignoreDisabledIcons_tooltip = When enabled ignores pre-generated disabled icons in favor of generating consistently styled disabled icons on the fly
437440
ToggleFullScreenMode_ActivationPopup_Description=You have gone full screen. Use the Toggle Full Screen command ({0}) to deactivate.
438441
ToggleFullScreenMode_ActivationPopup_Description_NoKeybinding=You have gone full screen. Use the Toggle Full Screen command to deactivate.
439442
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)