posts - 36, comments - 30, trackbacks - 0, articles - 3

Eclipse中一些扩展点介绍三

Posted on 2010-07-09 20:52 笑看人生 阅读(2705) 评论(0)  编辑  收藏 所属分类: Java插件开发
扩展点:
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");

只有注册用户登录后才能发表评论。


网站导航: