Missing link between objectContribution and command(objectContribution 和 command 之间缺少链接)
问题描述
当使用 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.
推荐答案
好的,这就是我所缺少的:我不得不使用 org.eclipse.ui.popupMenus 扩展点而不是使用 org.eclipse.ui.menus-带有 menuContribution 的扩展点,其 locationURI-属性指向 popup:org.eclipse.ui.popup.any?after=additions.这个 menuContribution 可以包含一个 command-元素(实现直接绑定到现有命令的目标),并且这个 command-元素的 visibleWhen-元素可以通过 checkEnabled-属性绑定到绑定命令的处理程序的激活状态(实现只有在启用命令处理程序满足).
Ok, here's what I was missing: instead of using the org.eclipse.ui.popupMenus-extension point, I had to use the org.eclipse.ui.menus-extension point with a menuContribution that has its locationURI-attribute pointing to popup:org.eclipse.ui.popup.any?after=additions. This menuContribution can include a command-element (achieving the goal of binding directly to an existing command), and this command-element´s visibleWhen-element can be bound to the activation status of the bound command's handler via the checkEnabled-attribute (achieving the goal of having the popup-menu entry visible only when the enablement for the command handler is satisfied).
不好的是 org.eclipse.ui.menus-extension 点的文档指出 org.eclipse.ui.popupMenus-extension 点是被认为已弃用,但 org.eclipse.ui.popupMenus 的文档没有提及这一事实.
What's bad is that the documentation of the org.eclipse.ui.menus-extension point states that the org.eclipse.ui.popupMenus-extension point is to be considered deprecated, but the documentation of org.eclipse.ui.popupMenus does not mention this fact.
这篇关于objectContribution 和 command 之间缺少链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:objectContribution 和 command 之间缺少链接
基础教程推荐
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 多个组件的复杂布局 2022-01-01
