Reputation: 28104
We currently have implemented a lot of SWT Actions, because it is a nice way to bind a single command to be added to the menubars and toolbars, and to have Keyboard Shortcuts for these commands.
Now... how can I register an Action in plain SWT/JFace without having to add it to a menubar, but in a way that it still can be called by a keyboard shortcut?
Upvotes: 3
Views: 3956
Reputation: 6406
I use to solve this in plain SWT by using Display.addFilter
on the KeyDown
event. See this question for an example.
Upvotes: 1
Reputation: 13922
Use the org.eclipse.ui.bindings extension, and add a new key.
You assign the sequence (M1, M2, M3, and M4 are used to represent keys like Shift, Command, and Alt, depending on the system). For example, I have assigned Alt+D as my key combo for a command, so I entered "M3+D" in the sequence field.
To get your key binding to work, you'll need to pick a schemeId. You could make one under the bindings extension. Just assign it an ID. Then you need to add an entry to the "plugin_customization.ini" file:
org.eclipse.ui/KEY_CONFIGURATION_ID=your.binding.scheme.id
Or you could just use the "org.eclipse.ui.defaultAcceleratorConfiguration" as your scheme ID, but that includes a lot of Eclipse's key combos, which will override yours I think.
You can leave the contextId field blank, it says it will default to org.eclipse.ui.contexts.window in that case.
Finally, just specify the ID of your command, and you should be set!
Upvotes: 0