Key binding for Eclipse commands
I would like to bind the Toggle Breakpoint command, org.eclipse.debug.ui.commands.To开发者_StackOverflow中文版ggleBreakpoint
, to F9 key.
I extended org.eclipse.ui.bindings
in this way:
<extension point="org.eclipse.ui.bindings">
<scheme
description="Default scheme for xvr"
id="org.xvr.scheme"
name="xvr.scheme"
parentId="org.eclipse.ui.defaultAcceleratorConfiguration">
</scheme>
<key
commandId="org.eclipse.debug.ui.commands.ToggleBreakpoint"
contextId="org.eclipse.ui.contexts.window"
schemeId="org.xvr.scheme"
sequence="F9">
</key>
But when I launch my RCP application nothing happens if I press F9.
What am I doing wrong?
EDIT
Sorry for the misunderstanding, but I'm developing a new product from eclipse and I can't use the preference window of eclipse.
I have to provide a binding through org.eclipse.ui.bindings extension point.
EDIT2
Thanks to Paul, using tracing I saw that an exception is thrown when I press F9
COMMANDS >>> execute >>> starting: id=org.eclipse.debug.ui.commands.ToggleBreakpoint; event=ExecutionEvent(Command(org.eclipse.debug.ui.commands.ToggleBreakpoint,Toggle Breakpoint,
Creates or removes a breakpoint,
Category(org.eclipse.debug.ui.category.run,Run/Debug,Run/Debug command category,true),
,
,,true),{},Event {type=1 StyledText {} time=25349140 data=null x=0 y=0 width=0 height=0 detail=0},org.eclipse.core.expressions.EvaluationContext@ffa7e1)
COMMANDS >>> execute >>> not handled: id=org.eclipse.debug.ui.commands.ToggleBreakpoint; exception=org.eclipse.core.commands.NotHandledException: There is no handler to execute for command org.eclipse.debug.ui.commands.ToggleBreakpoint
You need to add the following to plugin.xml, where defaultHandler is a class extending AbstractHandler and overridding execute()
<extension point="org.eclipse.ui.commands">
<command name="Remove All Comments"
defaultHandler="commentremover.actions.CommentRemover"
description="Removes all comments in source code"
categoryId="org.eclipse.jdt.ui.category.source"
id="commentremover.removeallcomments">
</command>
</extension>
Also, you need to add the following, where commandId equals the id of the command you defined above
<extension point="org.eclipse.ui.bindings">
<key sequence="Ctrl+Shift+D"
commandId="commentremover.removeallcomments"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
contextId="org.eclipse.jdt.ui.javaEditorScope"/>
</extension>
The above is all I needed to get my plugin to work. You will know it is working if it appears in the "Keys" preference menu. It is a plugin that removes all comments in the source code when you press Ctrl+Shift+D.
I suggest you go to
Windows → Preferences → General → Keys
and simply assign F9 to the Toggle Breakpoint command.
You don't specify which platform you're working on, but...
one some platforms - e.g. MacOS - the key assignment for F9, F10, etc cannot be changed :-(
You can try that out inside a regular Eclipse as well from the Keys preference page.
精彩评论