禁用 Jface 菜单管理器(灰显)
我有一个菜单管理器“menuManager”,其中包含菜单项(操作)和一个子菜单,另一个菜单管理器“subMenu”包含更多操作。
final MenuManager subMenu = new MenuManager("Main",null);
subMenu.add(mActionClose);
MenuManager menuManager = new MenuManager("#PopupMenu", "contextMenu");
menuManager.add(action1);
menuManager.add(action2);
menuManager.add(subMenu);
我只能在操作上设置 setEnabled(false) 而不能在菜单管理器上设置。
I have a menumanager "menuManager" that holds menu items (actions) and a sub-menu, another menumanager "subMenu" that contains more actions.
final MenuManager subMenu = new MenuManager("Main",null);
subMenu.add(mActionClose);
MenuManager menuManager = new MenuManager("#PopupMenu", "contextMenu");
menuManager.add(action1);
menuManager.add(action2);
menuManager.add(subMenu);
I can only set setEnabled(false) on actions and not on menumanager.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
重写
MenuManager
没有任何效果。您可以做的是访问相关的MenuItem
并尝试禁用它。首先,添加
IMenuListener
到您的“上下文菜单”管理器以访问关联的 < code>Menu:在侦听器中,您可以找到与子菜单管理器匹配的
MenuItem
:问题在于
MenuManager 中有一个错误修复代码
类将单击后重新启用子菜单项(如果它包含任何项目)。要覆盖此设置,您还需要向子菜单添加SWT.Show
侦听器,以便在单击后菜单变得可见时更新子菜单项的启用:Overriding
isEnabled()
method ofMenuManager
doesn't have any effect. What you can do is get access to relatedMenuItem
and try to disable it.First, you add
IMenuListener
to your "context menu" manager to access associatedMenu
:In the listener you find the
MenuItem
that matches your sub-menu manager:The problem with this is that there's a bug fix code in
MenuManager
class that will re-enable your sub-menu item once it is clicked (in case it contains any items). To override this you also need to addSWT.Show
listener to the sub-menu that will update the enablement of sub-menu item when the menu becomes visible after a click:无法在jface
MenuManager
上设置enabled==false,并且当我查看代码时,我没有看到它在渲染期间使用isEnabled()
。我知道在大多数情况下,如果该菜单为空,它根本不会呈现子菜单。在弹出菜单中,如果在
SWT.Show
事件上它可以确定没有子菜单,它将禁用子菜单,但我认为这种行为有点违反直觉。一种体面的用户体验行为是始终保留该子菜单,但在应该使用时将其扩展为一个禁用的菜单项:“<无可用操作>”或“<未启用>”或类似的东西。
There is no way to set enabled==false on the jface
MenuManager
, and when I looked through the code I didn't see it usingisEnabled()
during its rendering. I know in most cases it simply doesn't render a submenu if that menu is empty.In popup menus, it will disable a submenu if on an
SWT.Show
event it can determine that there are no children, but I think that behaviour is a little counter-intuitive.A decent UX behaviour is to always have that submenu there, but have it expand to one disabled menu item when it should be used: "<no actions available>" or "<not enabled>" or something like that.