如何从基于Eclipse RCP的应用程序中的菜单项中删除图标?

时间:2023-01-20 18:04:13

I am working on an Eclipse RCP-based application, and we have decided that we do not want any of the menu items to display icons next to the text. The problem we are seeing is that the standard actions like Undo, Redo, Cut, Copy, Paste, and so on all display the default icons for the corresponding actions.

我正在开发基于Eclipse RCP的应用程序,我们已经决定不希望任何菜单项在文本旁边显示图标。我们看到的问题是撤消,重做,剪切,复制,粘贴等标准操作都显示相应操作的默认图标。

Is there any way to tell the action management infrastructure to ignore the icons? My brute force solution to this was to rebuild the SWT so that MenuItem.setImage() was a no-op, and then include our own copy of the SWT in the final product, but it seems like there should be a lighter-weight solution.

有没有办法告诉行动管理基础设施忽略图标?我的强力解决方案是重建SWT,以便MenuItem.setImage()是一个无操作,然后在最终产品中包含我们自己的SWT副本,但似乎应该有一个更轻量级的解决方案。

4 个解决方案

#1


This turned out to be easier than I had hoped.

事实证明这比我希望的要容易。

Create a subclass of org.eclipse.ui.application.ActionBarAdvisor. Override the method register like this:

创建org.eclipse.ui.application.ActionBarAdvisor的子类。像这样覆盖方法寄存器:

protected void register(IAction action) {
    super.register(action);
    action.setImageDescriptor(null);
}

Then, create a subclass of org.eclipse.ui.application.WorkbenchWindowAdvisor that overrides createActionBarAdvisor:

然后,创建一个覆盖createActionBarAdvisor的org.eclipse.ui.application.WorkbenchWindowAdvisor的子类:

public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) {
    return new MyActionBarAdvisor(configurer);
}

That's it. All actions will no longer have icons.

而已。所有操作都将不再有图标。

#2


I believe you want to further examine going into the manifest and looking into org.eclipse.ui.views and seeing if there is anything in there for removing icons

我相信你想进一步检查进入清单并查看org.eclipse.ui.views并查看是否有任何内容可以删除图标

#3


What is the reason for not including icons? A lot of effort went into creating a standard interface, what would be the benefit of deviating from the standard? Do you think their omission increases usability?

不包括图标的原因是什么?创建标准接口需要付出很多努力,偏离标准有什么好处?你认为他们的遗漏会增加可用性吗?

Having said all that you could try contributing a fragment with some AspectJ around advice to intercept calls to setImage() and veto them.

说了所有你可以尝试用一些AspectJ提供一个片段来建议拦截对setImage()的调用并否决它们。

#4


You can do this by going to the extension tab in plugin.xml.add the extension org.eclipse.ui.menu (if not present).Right click create a new menu contribution.again right click and create a new menu.here u have the option to change the images with the ones saved in your icon folder in your class path

您可以通过转到plugin.xml.add中的扩展选项卡扩展org.eclipse.ui.menu(如果不存在)来执行此操作。右键单击创建新菜单contrib.again右键单击并创建一个新菜单。可以选择使用类路径中图标文件夹中保存的图像更改图像

#1


This turned out to be easier than I had hoped.

事实证明这比我希望的要容易。

Create a subclass of org.eclipse.ui.application.ActionBarAdvisor. Override the method register like this:

创建org.eclipse.ui.application.ActionBarAdvisor的子类。像这样覆盖方法寄存器:

protected void register(IAction action) {
    super.register(action);
    action.setImageDescriptor(null);
}

Then, create a subclass of org.eclipse.ui.application.WorkbenchWindowAdvisor that overrides createActionBarAdvisor:

然后,创建一个覆盖createActionBarAdvisor的org.eclipse.ui.application.WorkbenchWindowAdvisor的子类:

public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) {
    return new MyActionBarAdvisor(configurer);
}

That's it. All actions will no longer have icons.

而已。所有操作都将不再有图标。

#2


I believe you want to further examine going into the manifest and looking into org.eclipse.ui.views and seeing if there is anything in there for removing icons

我相信你想进一步检查进入清单并查看org.eclipse.ui.views并查看是否有任何内容可以删除图标

#3


What is the reason for not including icons? A lot of effort went into creating a standard interface, what would be the benefit of deviating from the standard? Do you think their omission increases usability?

不包括图标的原因是什么?创建标准接口需要付出很多努力,偏离标准有什么好处?你认为他们的遗漏会增加可用性吗?

Having said all that you could try contributing a fragment with some AspectJ around advice to intercept calls to setImage() and veto them.

说了所有你可以尝试用一些AspectJ提供一个片段来建议拦截对setImage()的调用并否决它们。

#4


You can do this by going to the extension tab in plugin.xml.add the extension org.eclipse.ui.menu (if not present).Right click create a new menu contribution.again right click and create a new menu.here u have the option to change the images with the ones saved in your icon folder in your class path

您可以通过转到plugin.xml.add中的扩展选项卡扩展org.eclipse.ui.menu(如果不存在)来执行此操作。右键单击创建新菜单contrib.again右键单击并创建一个新菜单。可以选择使用类路径中图标文件夹中保存的图像更改图像