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 associate an action with a command?"

 
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
Actions are associated with commands in various ways depending on
+
Actions are associated with commands in various ways depending on how the actions are defined.  For actions contributed via the <tt>actionSets</tt> extension point, the association with a command is done directly in the action definition.  The <tt>definitionId</tt> attribute of the <tt>action</tt> element must match the ID of the command it is associated with:
how the actions are defined.  For actions contributed via the <tt>actionSets</tt>
+
extension point, the association with a command is done directly in the action
+
definition.  The <tt>definitionId</tt> attribute of the <tt>action</tt> element must
+
match the ID of the command it is associated with:
+
 
<pre>
 
<pre>
 
   &lt;actionSet ...&gt;
 
   &lt;actionSet ...&gt;
Line 17: Line 13:
 
</pre>
 
</pre>
  
 
+
For actions created programmatically, associating the action with a command is a two-step process.  As with declarative actions, the first step is to set the action&#146;s definition ID to match the ID of the command. The command must still be defined declaratively, using the <tt>command</tt> extension point.  The definition ID is set by calling <tt>Action.setDefinitionId</tt>. The second step is to register the action with the platform, using the key-binding service.  This service can be accessed from the <tt>IWorkbenchPartSite</tt>, which is accessible to both views and editors.  Here is an example of these steps for an action in a view:
For actions created programmatically, associating the action with a command
+
is a two-step process.  As with declarative actions, the first step is to
+
set the action&#146;s definition ID to match the ID of the command.
+
The command must still be defined declaratively, using the <tt>command</tt>
+
extension point.  The definition ID is set by calling <tt>Action.setDefinitionId</tt>.
+
The second step is to register the action with the platform, using the  
+
key-binding service.  This service can be accessed from the  
+
<tt>IWorkbenchPartSite</tt>, which is accessible to both views and  
+
editors.  Here is an example of these steps for an action in a view:
+
 
<pre>
 
<pre>
 
   action.setActionDefinitionId(&quot;some.unique.id&quot;);
 
   action.setActionDefinitionId(&quot;some.unique.id&quot;);
 
   view.getSite().getKeyBindingService().registerAction(action);
 
   view.getSite().getKeyBindingService().registerAction(action);
 
</pre>
 
</pre>
 
  
 
== See Also: ==
 
== See Also: ==
 +
*[[FAQ How do I make key bindings work in an RCP application?]]
 +
*[[FAQ What is the difference between a command and an action?]]
  
[[FAQ_How_do_I_make_key_bindings_work_in_an_RCP_application%3F]]
+
{{Template:FAQ_Tagline}}
 
+
<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>
+

Latest revision as of 10:59, 18 August 2006

Actions are associated with commands in various ways depending on how the actions are defined. For actions contributed via the actionSets extension point, the association with a command is done directly in the action definition. The definitionId attribute of the action element must match the ID of the command it is associated with:

   <actionSet ...>
      <action
         definitionId="org.eclipse.faq.sampleCommand"
         ...>
      </action>
   </actionSet>
   <command
      id="org.eclipse.faq.sampleCommand"
      ...>
   </command>

For actions created programmatically, associating the action with a command is a two-step process. As with declarative actions, the first step is to set the action&#146;s definition ID to match the ID of the command. The command must still be defined declaratively, using the command extension point. The definition ID is set by calling Action.setDefinitionId. The second step is to register the action with the platform, using the key-binding service. This service can be accessed from the IWorkbenchPartSite, which is accessible to both views and editors. Here is an example of these steps for an action in a view:

   action.setActionDefinitionId("some.unique.id");
   view.getSite().getKeyBindingService().registerAction(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