Eclipseでは任意のキーバインドを特定のアクションに割り当てることが可能です。
しかし、その手順は意外と面倒です。
内容は大したこと無いのですが、とにかく記述量が多いのです。
アクション、コマンド、キーバインドの3段階が必要なので、順に説明します。
まずはアクション定義。
<extension
point="org.eclipse.ui.actionSets">
<actionSet
id="sample.command.actionSet"
label="Sample Command ActionSet">
<action
class="sample.SampleCommandAction"
label="Sample Command Action"
id="sample.SampleCommandAction"
definitionId="sample.SampleCommandAction"/>
</actionSet>
</extension>
メニューの作り方 のところで説明した内容と大体同じです。
一つ増えてるのが、definitionId という属性です。
アクションをコマンドに結び付けるためには定義する必要があるので、idと同じにしておきましょう。
次はコマンド定義。
<extension
point="org.eclipse.ui.commands">
<command
name="Sample Command"
id="sample.SampleCommandAction">
</command>
</extension>
action#definitionId と、command#id を合わせる必要があります。
最後にキーバインド定義。
<extension
point="org.eclipse.ui.bindings">
<key
sequence="Ctrl+C Ctrl+X Z"
contextId="org.eclipse.jdt.ui.javaEditorScope"
commandId="sample.SampleCommandAction"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
</extension>
キーストローク定義
どの状態でキーバインドを有効にするかという指定。
ここではJavaエディタ内で有効になるようにしています。
コマンドID
どのスキーマでキーバインドを有効にするかという指定。
Default または Emacs のどちらかにします。
ふぅ、これで完了です。
作成したキーバインドはEclipseのPreferenceから変更することも可能です。