biosbob
biosbob

Reputation: 311

Eclipse: how do you add a key binding to an action on an editor context menu

My custom Eclipse editor overrides createAction, where it registers an IAction with the editor. Then, in editorContextMenuAboutToShow I add this action to the menu.

Everything works fine, in that the action appears on the context menu within the editor; and I'm able to invoke the action from the menu itself.

Now, I'd like to add a key binding for this action. So far, I've added three extensions to my plugin.xml: a command, a binding, and a context. I can actually see the command/binding/context show up in the keys preference.

As for binding the command to my action, I've passed the command id declared in plugin.xml as the parameter to setActionDefinitionId after creating the action itself in createActions.

Needless to say, the key binding doesn't invoke the action - hence this question. What steps am I missing?

Upvotes: 1

Views: 825

Answers (1)

Rüdiger Herrmann
Rüdiger Herrmann

Reputation: 20985

In a TextEditor-based editor, I had to touch these places in order to provide an action with a key binding:

  • define a command, key binding and scope (as you did)

  • set the actionDefinitionId to match the command id (as you did)

  • after creating the action in createActions(), I had to call setAction( myAction.getActionDefinitionId(), myAction );

  • set the scope in initializeKeyBindingScopes() with setKeyBindingScopes( new String[]{ "org.example.myScope" } );

Does that help?

Upvotes: 1

Related Questions