Eclipse rcp 如何为类似于“快捷菜单”的快捷菜单添加键绑定;“重构”;JDT中的上下文菜单?
我想给我的eclipse插件添加一个快捷方式,用现有绑定显示一个快速菜单。它应该像JDT中的“重构”快捷菜单一样工作 JDT中快速菜单的快捷方式: JDT快速菜单: 我已经添加了一个绑定和一个命令,但似乎缺少了一些东西。“删除某些内容”条目也适用于关联菜单,只是缺少快捷菜单的快捷方式。 有人知道怎么做吗Eclipse rcp 如何为类似于“快捷菜单”的快捷菜单添加键绑定;“重构”;JDT中的上下文菜单?,eclipse-rcp,eclipse-jdt,Eclipse Rcp,Eclipse Jdt,我想给我的eclipse插件添加一个快捷方式,用现有绑定显示一个快速菜单。它应该像JDT中的“重构”快捷菜单一样工作 JDT中快速菜单的快捷方式: JDT快速菜单: 我已经添加了一个绑定和一个命令,但似乎缺少了一些东西。“删除某些内容”条目也适用于关联菜单,只是缺少快捷菜单的快捷方式。 有人知道怎么做吗 <extension point="org.eclipse.ui.bindings"> <key commandId="myplugin.refacto
<extension point="org.eclipse.ui.bindings">
<key
commandId="myplugin.refactoring.actions.DeleteSomething"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1+5">
</key>
<key
commandId="myplugin.refactoring.quickMenu"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1+9">
</key>
您可以看看JDT是如何实现相同的功能的。例如,当查看Eclipse 3.8.2源代码时,您将看到有趣的方法:
org.eclipse.jdt.ui.actions.RefactorActionGroup.installQuickAccessAction()
当Java编辑器打开时调用。这是与当前编辑器一起发生的
要总结在JDT中是如何完成的:
org.eclipse.jdt.internal.ui.actions.JDTQuickMenuCreator
)负责用项目填充快速菜单您不必以编程方式将命令与处理程序关联—另一个选项是使用扩展点。您也可以这样做:
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
...
Menu menu = new Menu(some parent);
new MenuItem(menu, SWT.PUSH).setText("...");
menu.setVisible(true);
return null;
}
为快速菜单添加命令并设置默认处理程序
<command
defaultHandler="myplugin.refactoring.QuickmenuHandler"
id="myplugin.refactoring.quickMenu"
name="Show Refactor Quick Menu">
</command>
向命令添加快捷方式(如您所做的):
最后在菜单扩展点中将所有这些绑定在一起:
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="popup:ch.arenae.dnp.frame.popup?after=additions">
<menu
commandId="myplugin.refactoring.quickMenu"
label="Refactor">
<command
commandId="<first refactoring command>"
style="push">
</command>
</menu>
...
</menuContribution>
...
重点是menu元素中的commandId属性。它用于在菜单中显示键盘快捷键。您使用的是e4还是其他什么?Peter,我实现了一个简单的示例。当出现关联菜单且快捷方式也可用于显示快捷菜单时,关联菜单中不会显示快捷键绑定。因此,用户必须知道快捷方式。要在关联菜单中显示快捷方式,是否还有其他步骤?
<key
commandId="myplugin.refactoring.quickMenu"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1+9">
</key>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="popup:ch.arenae.dnp.frame.popup?after=additions">
<menu
commandId="myplugin.refactoring.quickMenu"
label="Refactor">
<command
commandId="<first refactoring command>"
style="push">
</command>
</menu>
...
</menuContribution>