首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

eclipse 命令绑定快捷键并设置下上文

2012-12-18 
eclipse 命令绑定快捷键并设置上下文扩展点:org.eclipse.ui.bindingsorg.eclipse.ui.contexts扩展点org.ec

eclipse 命令绑定快捷键并设置上下文

扩展点:
org.eclipse.ui.bindings
org.eclipse.ui.contexts

扩展点org.eclipse.ui.bindings是给command增加快捷键,给命令com.xxxx.test.command1增加快捷键,
示例代码如下:

<extension
???????? point="org.eclipse.ui.bindings">
????? <key
??????????? commandId="com.xxxx.test.command1"
??????????? contextId="org.eclipse.ui.contexts.window"
??????????? schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
??????????? sequence="M2+F7">
????? </key>?
</extension>


这样快捷键Shift+F7在Eclipse工作台上都会起作用,但是如果想让命令的快捷键只对特定的视图或者编辑器起作用,那么可以通过org.eclipse.ui.contexts扩展点来自定义上下文。

<extension
?????????? point="org.eclipse.ui.contexts">
??????? <context
????????????? id="viewmenu.testcontext"
????????????? name="ViewContext"
????????????? parentId="org.eclipse.ui.contexts.window">
??????? </context>
</extension>


扩展之后,需要修改org.eclipse.ui.bindings扩展中的contextId属性为viewmenu.testcontext。

另外还需要在需要增加该快捷键的编辑器或者视图对应类中增加如下代码(视图类在代码的createControl方法,编辑器类在代码的init方法):

IContextService contextService =
(IContextService) getSite().getService(IContextService.class);
contextService.activateContext("viewmenu.testcontext");

?

?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 转自?玩转Java

?

热点排行