To hook up the command to a keystroke a binding is used. This allows a key (or series of keys) to be used to invoke the command, instead of only via the menu. Bindings are set up via an extension point org.eclipse.ui.bindings
, and connect a sequence of keystrokes to a command ID.
Open the
plugin.xml
in theclock.ui
project.In the
plugin.xml
tab, add the following:<extension point="org.eclipse.ui.bindings"> <key commandId="com.packtpub.e4.clock.ui.command.hello" sequence="M1+9" contextId="org.eclipse.ui.contexts.window" schemeId= "org.eclipse.ui.defaultAcceleratorConfiguration"/> </extension>
Run the Eclipse instance, and press Cmd + 9 (for OS X) or Ctrl + 9 (for Windows/Linux). The same
Hello
dialog should be displayed, as if it was shown from the menu. The same keystroke should be displayed in theHelp
menu.