tags:

views:

41

answers:

1

I'm extending Eclipse using the Eclipse plugin infrastructure, and I've come into a problem I can't quite figure out how to get around:

I have a command that has some hotkey. I also have an editor that needs to steal the key bindings from Eclipse (disabling the key filter in the IBindingService). However, this command is "important" enough that the hotkey for it still needs to work. Currently, in that specific editor, in the part where I'm listening for key events I check for what is the default key bind for that command and manually launch it if it detects it. The obvious problem for this is that if the key binding for the command is changed, this still uses the default binding in just that editor. Is there some way I can easily access the key binding of a particular command so that I can check for that rather than simply the default one?

I realize this solution isn't portable between different editors, but this is the only editor I have to worry about this in, so I don't really mind special casing this one.

+2  A: 

You need to use the org.eclipse.ui.keys.IBindingService getting it is a bit tricky, through org.eclipse.ui.PlatformUI:

IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class);
bindingService.getBestActiveBindingFormattedFor(CMDID);

The CMDID is the command ID as you defined in your plugin.xml.

zvikico
Awesome, this worked great. I used getActiveBindings instead, because I wanted it to pick up on all of the bindings, but it's working now. Thanks!
DivineWolfwood