Jarek
Jarek

Reputation: 7729

Adding shortcut to shortcutles Eclipse actions defined in plugins

There is a plugin that has an action (action itself is even placed on toolbar i.e. Tomcat runner and Vim editing mode).

So is there any way to add conveniently shortcuts to these actions, which have no shortcuts implicitly defined, by say changing an XML configuration...

Any advices are appreciated.

Upvotes: 0

Views: 1640

Answers (2)

Favonius
Favonius

Reputation: 13984

The answer is Yes you can do it.

  • Try window->preferences->keys now here you create new bindings or can change the old ones.

Example:

>>Original

enter image description here

>>Setting it

enter image description here

>>Result

enter image description here

Note: There is a hard way as mentioned in @greydet answer. But, don't worry its not that hard. Follow these steps:

  1. Identify the plug-in contributing the action. Lets if its a Java related action then most probably you will find it in org.eclipse.jdt.ui. Mostly a well written plugin divides its UI and processing component in different plugins.
  2. Now open its plugin.xml
  3. Search for your action item which you want to modify with name or some fuzzy id etc.
  4. Mostly there has to be command. If you find then good. Now write a very small plugin with a binding extension point. Use the values you have found earlier for the command extension.

For example for java getter and setter action following is the command extension point:

  <command
        name="%ActionDefinition.getterSetter.name"
        description="%ActionDefinition.getterSetter.description"
        categoryId="org.eclipse.jdt.ui.category.source"
        id="org.eclipse.jdt.ui.edit.text.java.create.getter.setter">
  </command>

The corresponding binding extension I have written:

<plugin>
   <extension
         point="org.eclipse.ui.bindings">
      <key
            commandId="org.eclipse.jdt.ui.edit.text.java.create.getter.setter"
            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
            sequence="CTRL+T">
      </key>
   </extension>

</plugin>

The Problem: The command you earlier found is for package explorer view. There is a command contributed by the java editor also. You have to create a binding for that.

Upvotes: 0

greydet
greydet

Reputation: 5539

There are two different ways to contribute to the Eclipse Workbench: Actions and Commands.

Prefer using the command framework taht is newer & more complete than the action one and that allows to add key binding easily.

Have a look to the org.eclipse.ui.bindings extension point to contribute a key binding for a given command: http://wiki.eclipse.org/FAQ_How_do_I_provide_a_keyboard_shortcut_for_my_action%3F

A more complete article about the Eclipse command framework: http://www.vogella.de/articles/EclipseCommands/article.html

Upvotes: 1

Related Questions