如何切换Eclipse插件的菜单按钮图标和工具提示文本? [英] How do I toggle the menu button icon and tooltip text for an Eclipse plugin?

查看:174
本文介绍了如何切换Eclipse插件的菜单按钮图标和工具提示文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Eclipse插件,它具有一个可以启用/禁用功能的工具栏菜单项。我知道如何使用plugin.xml文件设置图标和工具提示文本,但是我想要更改图标,特别是工具提示文本,具体取决于正在处理的项目的状态。也就是说,如果没有启用该功能,我想要一个图标,显示与启用功能的工具提示文字一起显示功能,但如果启用该功能,我想要一个图标,显示关闭功能以及工具提示说禁用功能的文本。现在,我唯一可以看到的选项是通用的图标和工具提示文字,表示启用/禁用功能,但对我来说感到笨拙。

I'm developing an Eclipse plugin that has a toolbar menu item that will be enabling/disabling a feature. I know how to set the icon and tooltip text for it using the plugin.xml file, but I want to be able to change the icon and especially the tooltip text for it depending on the state of the project being worked on. I.e., if the feature is not enabled, I want an icon that shows turning the feature on along with tooltip text that says "enable feature", but if the feature is enabled, I want an icon that shows turning the feature off along with tooltip text that says "disable feature". Right now, the only option I can see is a generic icon and tooltip text that says "enable/disable feature", but that feels clumsy to me.

编辑添加:为了回应indigomonkey的答案,这是一个基于我最初写的一个很好的答案,我想澄清一下,工具栏按钮所启用的行为是一旦它被启用,就会阻止它们被禁用(和一个对话框弹出,当它启用它来验证他们是否要启用它,因为它不应该被轻易地启动,并阻止它们禁用它一旦启用)。因此,我想将图标更改为建议不要点击我的图标。

Edit to add: In response to indigomonkey's answer, which is a good one based on what I originally wrote, I would like to clarify that the behavior that is being enabled by the toolbar button is one that we really discourage ever disabling once it has been enabled (and a dialog pops up both to when enabling it to verify that they want to enable it because it should not be started lightly as well as to discourage them from disabling it once it is enabled). Because of this, I would like the icon to change to one that suggests "don't click on me".

推荐答案

如果您的命令Handler实现 IElementUpdater 每当运行命令时,将调用 updateElement 方法。

If your command Handler implements IElementUpdater the updateElement method will be called whenever the command is run.

UIElement 参数 updateElement 具有 setIcon setTooltip 方法。

这篇关于如何切换Eclipse插件的菜单按钮图标和工具提示文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆