更新Eclipse菜单项的启用状态 [英] Update Eclipse menu item enabled state

查看:81
本文介绍了更新Eclipse菜单项的启用状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我作为命令在文件菜单中创建了菜单项。对于此命令,有一个处理程序实现 IHandler 接口。该处理程序包含 isEnabled 方法。我试图使用此方法启用/禁用我的菜单项,但是当我单击文件菜单时,该方法仅被调用一次。单击第二次,第三次等时,即使我之前更改了页面状态(打开/关闭编辑器),也不会再次调用 isEnabled 方法。

I created the menu item in the "File" menu as a command. For this command there is a handler implementing the IHandler interface. This handler contains the isEnabled method. I am trying to use this method to enable/disable my menu item, but that method is called only once when I click on the "File" menu. When clicked for the second, third etc. times, the isEnabled method is not called again even if I changed the state of page (open/close editors) before.

我该怎么办?

推荐答案

您是否将 org.eclipse.core子类化? .commands.AbstractHandler ?您应该使用 setBaseEnabled(boolean)来更新处理程序的状态(这将更新您的命令)。

Are you subclassing org.eclipse.core.commands.AbstractHandler? You should use setBaseEnabled(boolean) to update the state of your handler (which would update your command).

仅当您还触发 HandlerEvent 时,才可以更改处理程序中的启用状态。调用 setBaseEnabled(boolean)通常会更容易,它将为您触发该事件。

It's only valid to change enabled state in your handler as long as you also fire the HandlerEvent. It's usually easier to call setBaseEnabled(boolean) which will fire the event for you.

这篇关于更新Eclipse菜单项的启用状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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