Difference between revisions of "FAQ How do I provide a keyboard shortcut for my action?"

From Eclipsepedia

Jump to: navigation, search
 
m
Line 1: Line 1:
Keyboard shortcuts are created by defining a <i>key binding</i>, using the
+
Keyboard shortcuts are created by defining a <i>key binding</i>, using the <tt>org.eclipse.ui.commands</tt> extension point. When you define a key binding, you generally specify four things:
<tt>org.eclipse.ui.commands</tt> extension point. When you define a  
+
key binding, you generally specify four things:
+
  
* The ID of the configuration to which it applies.</li>
+
* The ID of the configuration to which it applies.
 +
* The context, or scope, for the key binding.  For example, the text editor defines a context that can override bindings from the global context.
 +
* The ID of the command that you are creating a binding for.  You can find command IDs by browsing the <tt>plugin.xml</tt> file of the plug-in that defines that action.
 +
* The accelerator sequence.
  
* The context, or scope, for the key binding. For example, the text editor defines
+
You can also define a key binding that applies only to a particular locale or platform. For example, you can define an accelerator that applies only to a German Linux GTK installation of Eclipse. See the <tt>command</tt> extension point documentation for more details on these advanced features.
a context that can override bindings from the global context.</li>
+
  
* The ID of the command that you are creating a binding for.  You can find
+
The following is an example key-binding definition.  This binding sets the accelerator for the Java '''Sort Members''' action, which by default has no key binding:
command IDs by browsing the <tt>plugin.xml</tt> file of the plug-in that defines that action.</li>
+
 
+
* The accelerator sequence.</li>
+
 
+
 
+
You can also define a key binding that applies only to a particular locale or platform.
+
For example, you can define an accelerator that applies only to a German Linux GTK
+
installation of Eclipse.  See the <tt>command</tt> extension point documentation for more
+
details on these advanced features.
+
 
+
The following is an example key-binding definition.  This binding sets the accelerator
+
for the Java '''Sort Members''' action, which by default has no key binding:
+
 
<pre>
 
<pre>
 
   &lt;keyBinding
 
   &lt;keyBinding
Line 30: Line 18:
 
</pre>
 
</pre>
  
The difference between a configuration and a context can be confusing  
+
The difference between a configuration and a context can be confusing at first.  The configuration is explicitly set by the user; once it is set, it does not change.  The context can be changed programmatically by any plug-in.  For example, you can change the scope whenever your view or editor becomes active.  Scopes can be queried and set by using the <tt>IKeyBindingService</tt>.  This service can be accessed within a workbench part by using the method <tt>getKeyBindingService</tt> on <tt>IWorkbenchPartSite</tt>.
at first.  The configuration is explicitly set by the user; once it is set, it does
+
not change.  The context can be changed programmatically by any plug-in.  For example,
+
you can change the scope whenever your view or editor becomes active.  Scopes
+
can be queried and set by using the <tt>IKeyBindingService</tt>.  This service can
+
be accessed within a workbench part by using the method
+
<tt>getKeyBindingService</tt> on <tt>IWorkbenchPartSite</tt>.
+
  
  
 
== See Also: ==
 
== See Also: ==
 +
*[[FAQ How do I create my own key-binding configuration?]]
  
[[FAQ_How_do_I_create_my_own_key-binding_configuration%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>
+

Revision as of 23:38, 14 June 2006

Keyboard shortcuts are created by defining a key binding, using the org.eclipse.ui.commands extension point. When you define a key binding, you generally specify four things:

  • The ID of the configuration to which it applies.
  • The context, or scope, for the key binding. For example, the text editor defines a context that can override bindings from the global context.
  • The ID of the command that you are creating a binding for. You can find command IDs by browsing the plugin.xml file of the plug-in that defines that action.
  • The accelerator sequence.

You can also define a key binding that applies only to a particular locale or platform. For example, you can define an accelerator that applies only to a German Linux GTK installation of Eclipse. See the command extension point documentation for more details on these advanced features.

The following is an example key-binding definition. This binding sets the accelerator for the Java Sort Members action, which by default has no key binding:

   <keyBinding
      string="Ctrl+Shift+D"
      context="org.eclipse.ui.globalScope"
      command="org.eclipse.jdt.ui.edit.text.java.sort.members"
      configuration="org.eclipse.faq.sampleConfiguration">
   </keyBinding>

The difference between a configuration and a context can be confusing at first. The configuration is explicitly set by the user; once it is set, it does not change. The context can be changed programmatically by any plug-in. For example, you can change the scope whenever your view or editor becomes active. Scopes can be queried and set by using the IKeyBindingService. This service can be accessed within a workbench part by using the method getKeyBindingService on IWorkbenchPartSite.


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.