RSS

Search Engine

Wednesday, June 16, 2010

Keybindings for Commands

6.1. Overview

Via keybindings you can define shortcuts for your commands. Eclipse uses a default key configuration scheme. The challenge for Eclipse RCP application is that you usually do not want to have the standard Eclipse IDE shortcuts available in your application.

The following therefore explains how to create keybindings and how to overwrite the default key binding schema of Eclipse.

To define and use your own scheme you need:

  • Define a scheme in extension point "org.eclipse.ui.bindings"

  • Assign this scheme to the keybindings you defined

  • Have a product created

  • Define the file "plugin_customization.ini" and set the scheme for the product via a property.

6.2. Keybinding

Create a new project "de.vogella.rcp.intro.commands.keybinding" using the "Hello RCP" template, declare command "de.vogella.rcp.intro.commands.keybinding.hello" with a default handler "de.vogella.rcp.intro.commands.keybinding.HelloHandler" which prints out "Hello" to the console

Add the extension point "org.eclipse.ui.bindings" to your project. Right click in this extension point, select New-> Key.

Select as schemaID "org.eclipse.ui.defaultAcceleratorConfiguration" this is the workbench default and will make sure you keybinding is valid in the whole application. The commandId is the ID of the command you just created. The sequence is the shortcut key for calling the command. M1 represents the Cntr key.

If you now run it the keybinding should work and if you press Cntrl+1 the message on the console should be visible.

6.3. Defining your own schema

Add now another key binding "Cntr+N" to the command "de.vogella.rcp.intro.commands.keybinding.hello" . Try it. This will not work as it is conflicting with the Eclipse default schema.

Right click in this extension point "org.eclipse.ui.bindings", select New-> Scheme. Create a schema with the id "MyScheme".

Assign the scheme id to your commands.

Define a product. See Defining a product for Eclipse RCP for details.

Create the following file "plugin_customization.ini" and put it in your main directory

    

org.eclipse.ui/KEY_CONFIGURATION_ID=myscheme

If you now run your product the "Cntr+N" shortcut should work.

0 comments:

Post a Comment