Project Explorer (2) - 给"Build Project" 添加快捷键

来源:互联网 发布:qq游戏无法连接网络 编辑:程序博客网 时间:2024/06/05 04:49

背景介绍

CDT并没有给"Build Project"添加快捷键,而Wind River的Workbench则有。添加快捷键给常用操作,比用鼠标点图标更适合我的喜好。

目标

给[1]中添加的"Build Project" Action添加快捷键控制。

分析

在Workbench中,也没有把"Clean Project"加入到Windows Menu "Project"里面去。所以这里只给"Build Project"添加快捷键。

2]的6.6写道

"The new approach involves associating actions and key bindings with commands and grouping those commands into categories. In addition, each command has a scope indicating when it will be available to the user, and is part of a configuration so that the user can select between different configuration to get different key bindings."

我们需要在显示地将Command和Key Bindings关联起来。

实现

修改 window menu command, "Build Project/Project".

在org.eclipse.ui.ide这个插件的plugin.xml中,可以找到Build Project Command的id: org.eclipse.ui.project.buildProject。

在我们的插件中,对这个command加入Key Binding.

         <keyBinding
               command="org.eclipse.ui.project.buildProject"
               configuration="org.eclipse.ui.defaultAcceleratorConfiguration"
               string="Ctrl+B Ctrl+P">
         </keyBinding>


启动ide后,在Eclipse-->Window-->Preference-->General-->Keys,就能看到这个命令加入了 Ctrl+B Ctrl+P的绑定了。


Modifying Navigator.

在[1]中给出的ActionGroup中,给Build Action添加definitionId:

protected void makeActions() {
fBuildAction = new BuildAction(getViewPart().getSite(), IncrementalProjectBuilder.INCREMENTAL_BUILD);
fCleanAction= new BuildAction(getViewPart().getSite(), IncrementalProjectBuilder.CLEAN_BUILD);
fBuildAction.setActionDefinitionId("org.eclipse.ui.project.buildProject");
fCleanAction.setText("Clean Project");
}

结果




参考文献

[1] Project Explorer -- "Build Project" and "Clean Project".http://blog.csdn.net/fanchou1215/article/details/8582216
[2] Building Commercial Quality Eclipse Plug-ins.
原创粉丝点击