到 Google 资讯主页   
EasyJF首页   资料   源码   软件    论坛   网站    
   使用帮助    
    该信息为本站MyRSS系统缓存内容,部分图片及附件有可能无法正常使用.easyjf.comBlogJava无关,不对该信息负责.通过http://kb.csdn.net/keyword/java//../../java/Articles/200604/c0974602-7633-4685-82d7-090cc4e1951d.html访问该信息的原始内容.
页面功能  【加入收藏】 【推荐给朋友】 【字体:  】 【关闭】   
给RCP系统添加全局快捷键
作者:陈刚 来源:BlogJava  发布时间:2006-04-28 00:00:00.0

?????????????????????????????????????????? 文/陈刚 from www.chengang.com.cn at 2006年4月28日

一个RCP系统,给它添加一个象Eclipse中Ctrl+Shift+O一样的全局快捷键,怎么加?

参考了RCP的Email项目示例,给我RCP项目中MonitorAction(显示一个监视器的命令)添加一个快捷键Ctrl+1。简单把添加的过程概述如下:

1、首先在plugin.xml中添加两个扩展点如下

???<extension
?????????point
="org.eclipse.ui.bindings">
??????
<key
????????????commandId
="org.eclipse.ui.file.exit"
????????????schemeId
="org.eclipse.ui.defaultAcceleratorConfiguration"
????????????sequence
="CTRL+X"/>
??????
<key
????????????commandId
="adminconsole.monitor"
????????????schemeId
="org.eclipse.ui.defaultAcceleratorConfiguration"
????????????sequence
="CTRL+1"/>
???
</extension>

???
<extension
?????????point
="org.eclipse.ui.commands">
??????
<category
????????????id
="adminconsole.perspective"
????????????name
="Perspective"/>
??????
<command
????????????categoryId
="adminconsole.perspective"
????????????id
="adminconsole.monitor"
????????????name
="Open?Monitor?Perspective"/>
???
</extension>

说明:
。org.eclipse.ui.file.exit是另一个退出系统命令,是复用了Eclipse本身的那个,它和本例无关。
。commandId要求唯一
。cmmands扩展点的category是一个组,估计不要也可以,最后还是加上吧。
。bindings扩展点中的commandId对应于cmmands扩展点中的id



2、创建一个类,专门保存所有commandId

public?interface?ICommandIds?{
????
public?static?final?String?CMD_MONITOR?=?"adminconsole.monitor";
}
???

3、创建Action类,在构造函数里用两个方法注册一下
????private?static?class?MonitorAction?extends?Action?{
????????
public?MonitorAction()?{
????????????setText(
"监视");
????????????
//?The?id?is?used?to?refer?to?the?action?in?a?menu?or?toolbar
????????????setId(ICommandIds.CMD_MONITOR);
????????????
//?Associate?the?action?with?a?pre-defined?command,?to?allow?key?bindings.
????????????setActionDefinitionId(ICommandIds.CMD_MONITOR);
????????}

??????? ...
????}

4、在ApplicationActionBarAdvisor的makeActions方法,给monitorAction对象加上这样一句
?
register(monitorAction);

注意:如果你没有在plugin.xml和makeActions做上面讲过的设置,加上这一句将可能导致你的RCP系统无法启动。


陈刚 2006-04-28 21:35

 
相关文章
 
页面功能  【加入收藏】 【推荐给朋友】 【字体:  】 【关闭】   


EasyJF.com 2006 隐私政策 使用EasyJF前必读