Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "FAQ How do I make key bindings work in an RCP application?"

 
m
Line 11: Line 11:
 
calling the <tt>setActionDefinitionId</tt> method inherited from <tt>Action</tt>.
 
calling the <tt>setActionDefinitionId</tt> method inherited from <tt>Action</tt>.
 
Typically this is done from your action&#146;s constructor.
 
Typically this is done from your action&#146;s constructor.
 
  
 
Now that your action is linked to a command, you need to register the
 
Now that your action is linked to a command, you need to register the
Line 31: Line 30:
 
that your action exists.  When the key binding is invoked by the user,
 
that your action exists.  When the key binding is invoked by the user,
 
it will now be able locate and run your action.
 
it will now be able locate and run your action.
 
  
 
== See Also: ==
 
== See Also: ==
 +
*[[FAQ What is the difference between a command and an action?]]
 +
*[[FAQ How do I associate an action with a command?]]
 +
*[[FAQ How do I provide a keyboard shortcut for my action?]]
  
[[FAQ_What_is_the_difference_between_a_command_and_an_action%3F]]
+
{{Template:FAQ_Tagline}}
 
+
[[FAQ_How_do_I_associate_an_action_with_a_command%3F]]
+
 
+
[[FAQ_How_do_I_provide_a_keyboard_shortcut_for_my_action%3F]]
+
 
+
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>
+

Revision as of 23:35, 14 June 2006

When actions are contributed via the actionSets extension point, key bindings are configured by associating the action with a declarative command. In this case, no code is required to hook the action to the key binding. However, if you programmatically create actions in an RCP application, you have to register actions yourself. This requires two steps. First, you need to specify the command ID for your action. If you are using built-in actions from an action factory, they usually have the command ID already set. If you create your own action, as a subclass of Action, you need to set the command ID yourself by calling the setActionDefinitionId method inherited from Action. Typically this is done from your action&#146;s constructor.

Now that your action is linked to a command, you need to register the action with the platform. You should do this the first time the platform calls your implementation of WorkbenchAdvisor.fillActionBars:

   public void fillActionBars(IWorkbenchWindow window,
      IActionBarConfigurer configurer, int flags) {
      ...
      if (maximizeAction == null) {
         maximizeAction = ActionFactory.MAXIMIZE.create(window);
         configurer.registerGlobalAction(maximizeAction);
      }
      menu.add(maximizeAction);
   }

The method registerGlobalAction will let the platform know that your action exists. When the key binding is invoked by the user, it will now be able locate and run your action.

See Also:


This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.

Back to the top