给Action添加快捷键,参考了RCP的项目,简单的添加过程如下:
1、 首先在plugin.xml中添加两个扩展点如下:
<extension
point="org.eclipse.ui.bindings">
<key
commandId="gef.autoLayout"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="ALT+G"/>
</extension>
<extension
point="org.eclipse.ui.commands">
<category
id="gef.eos.commands"
name="自动布局"/>
<command
categoryId="gef.eos.commands"
id="gef.autoLayout"
name="自动布局Command"/>
</extension>
说明:
CommandID要求唯一
Commands扩展点的category是一个组,估计不要也可以,最后还是加上吧
Binding扩展点中的CommandID对应于Commands扩展点的ID。
2、 创建Action,在构造函数里注册一下:
public ToggleAutomaticLayoutAction(MainMode mainMode) {
super();
this.mainMode = mainMode;
setText("自动布局");
setId(Activator.ACTION_AUTOMATIC_LAYOUT);
// 添加快捷键
setActionDefinitionId("gef.autoLayout");
}
这样就成功了。
本文介绍如何在Eclipse RCP项目中为Action添加快捷键,通过在plugin.xml文件中定义扩展点实现自动布局功能,并在Action构造函数中进行注册。
1924

被折叠的 条评论
为什么被折叠?



