objectContribution 和命令之间缺少链接
使用 objectContribution
元素(它是 org.eclipse.ui.popupMenus
-扩展点),我经常(几乎总是)想委托给某些命令自己实施某些操作(因为通常我已经实施了命令和处理程序)。我正在使用 ICommandService
和 IHandlerService
来完成此操作,但感觉应该有一种方法可以以编程方式实现此目的。我可以使用 viewerContribution
而不是 objectContribution
,但是这样我就会失去仅在选择某些对象类型时显示菜单条目的简单方法。理想情况下,我想使用处理程序中已有的启用检查来应用于由 objectContribution
定义的菜单条目。
When using the objectContribution
-element (which is part of the org.eclipse.ui.popupMenus
-extension point), I often (practically always) want to delegate to some command instead of implementing some action myself (since usually, I have the command and a handler already implemented). I'm doing this by using ICommandService
and IHandlerService
, but it feels there should be a way to achieve this programmatically. I could use viewerContribution
instead of objectContribution
, but then I would lose the easy way of showing the menu entry only when certain object types are selected. Ideally, I would like to use the enablement-checks that already exist for my handlers to apply to the menu entry defined by the objectContribution
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,这就是我所缺少的:我必须使用
org.eclipse.ui.menus
< /a>-带有menuContribution
的扩展点,其locationURI
-属性指向popup:org.eclipse.ui.popup.any?after=additions< /代码>。此
-元素可以通过menuContribution
可以包含一个command
元素(实现直接绑定到现有命令的目标),并且此command
元素的 < code>visibleWhencheckEnabled
-属性绑定到绑定命令处理程序的激活状态(实现仅当启用时弹出菜单条目可见的目标)命令处理程序已满足)。不好的是 org.eclipse.ui.menus 扩展点的文档指出 org.eclipse.ui.popupMenus 扩展点被视为已弃用,但是 org.eclipse.ui.popupMenus 的文档没有提到这一事实。
Ok, here's what I was missing: instead of using the
org.eclipse.ui.popupMenus
-extension point, I had to use theorg.eclipse.ui.menus
-extension point with amenuContribution
that has itslocationURI
-attribute pointing topopup:org.eclipse.ui.popup.any?after=additions
. ThismenuContribution
can include acommand
-element (achieving the goal of binding directly to an existing command), and thiscommand
-element´svisibleWhen
-element can be bound to the activation status of the bound command's handler via thecheckEnabled
-attribute (achieving the goal of having the popup-menu entry visible only when the enablement for the command handler is satisfied).What's bad is that the documentation of the
org.eclipse.ui.menus
-extension point states that theorg.eclipse.ui.popupMenus
-extension point is to be considered deprecated, but the documentation oforg.eclipse.ui.popupMenus
does not mention this fact.