How to programmatically determine the key binding for Commnand for eclipse plugins?

I am extending Eclipse using the Eclipse plugin infrastructure and I am having a problem. I can't figure out how to get around:

I have a hotkey command. I also have an editor that should steal key bindings from Eclipse (disable the key filter in IBindingService). However, this command is so "important" that it still needs a hotkey. Currently, in this particular editor, in the part where I listen to key events, I check what is the default binding for this command and manually launches it if it detects it. The obvious problem for this is that if the key binding to the command is changed, it still uses the default binding only in this editor. Is there a way by which I can easily access key binding to a specific command so that I can verify this, and not just the default?

I understand that this solution is not transferred between different editors, but this is the only editor that I have to worry about, so in fact I am not against the special case.

+3
source share
1 answer

You need to use org.eclipse.ui.keys.IBindingServiceit because it is a bit complicated, through org.eclipse.ui.PlatformUI:

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

CMDID is the command identifier that you define in the plugin.xml file.

+5
source

Source: https://habr.com/ru/post/1726373/


All Articles