|
|
|
Keybinding And Command Step By Step Instructions [message #533970 is a reply to message #524827] |
Mon, 17 May 2010 15:12 |
Andy Messages: 47 Registered: July 2009 |
Member |
|
|
Thought I would post this to help anyone else out trying to get a keybinding to work with a command. In this example I want to override the DEL key in Eclipse for my window.
1) Go to your plugin.xml => extensions tab => add org.eclipse.ui.commands
2) Right mouse on org.eclipse.ui.commands => new => command
3) Enter an id such as com.mycompany.commands.delete.
4) Enter a name, such as "Delete"
5) Click the defaultHandler link. On the resulting screen assign a package, have the class extend org.eclipse.core.commands.AbstractHandler, and enter a name for the class. In this case it is called com.mycompany.handlers.DeleteHandler. Leave the class as it stands for now.
6) Back in plugin.xml on the extensions tab, right mouse on org.eclipse.ui.commands => new => context.
7) Enter an id for the context, such as com.mycompany.contexts.forkeybinding
Enter a name, such as ForKeyBinding
9) Important! Enter the parentId as org.eclipse.ui.contexts.window. Eclipse leaves this field empty by default and the command will fail if this isn't added.
10) Still on the plugin.xml / extensions tab, press Add. Add org.eclipse.ui.bindings.
11) Right mouse on org.eclipse.ui.bindings => key. In the resulting screen enter the following:
sequence: DEL (If you want to override a different key, right mouse over the text "sequence*". A dialog will appear that will explain key combinations)
schemeId: org.eclipse.ui.defaultAcceleratorConfiguration
contextId: com.mycompany.contexts.forkeybinding (The id of the context we just created)
commandId: com.mycompany.commands.delete (The id of the command we created earlier)
12) At this point if you run your plugin the DEL key will now fire off the execute method in the command handler. Add whatever logic is necessary that you want achieved in the command.
13) If you have a ViewPart that needs to be updated as a result of the command, the way to get a hold of the ViewPart from within your command is as follows:
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchPart viewer = HandlerUtil.getActivePart(event);
}
Then you can fire an event into the viewer and update your display.
|
|
|
Powered by
FUDForum. Page generated in 0.03645 seconds