Scopes

A scope is used to define the appropriate context for a key binding.  The workbench defines two key binding scopes:

The scope dictates when a key binding (in the active key configuration) is considered active.  The scope is declared in the key binding markup:

...
<keyBinding
       string="Ctrl+S"
       scope="org.eclipse.ui.globalScope"
       command="org.eclipse.ui.file.save"
       configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
</keyBinding>
...
<keyBinding
       string="Ctrl+X Ctrl+S"
       scope="org.eclipse.ui.globalScope"
       command="org.eclipse.ui.file.save"
       configuration="org.eclipse.ui.emacsAcceleratorConfiguration">
</keyBinding>

How is the current scope determined?  By default, the workbench operates in a global scope.  When a text editor becomes active, it is responsible for resetting the scope to the text editor scope.  This is all handled by the workbench and text editor code.  Most plug-ins need only determine the appropriate scope for their key bindings when defining them.  

Defining new scopes

When a plug-in defines a key binding, it usually assigns it to an existing scope.   However, if your plug-in defines a new style of editor, it's possible that you'll also want to introduce a new scope for key bindings.  For example, a multi-page editor may have different scopes for each page in the editor.  

When you define your own scope, it is up to your plug-in to ensure that the proper scopes are set into the IKeyBindingService as appropriate for your editor.  A complete discussion of how this works is beyond the scope (pun intended!) of this documentation.  Refer to IKeyBindingService and its implementors for more detail.  

Plug-ins define their scopes inside (where else?) the org.eclipse.ui.commands extension point.  The workbench markup for the global and text editor scopes is located at the bottom of the extension definition:

<extension
         point="org.eclipse.ui.commands">
      ...
      <scope
            name="%scope.global.name"
            description="%scope.global.description"
            id="org.eclipse.ui.globalScope">
      </scope>
      <scope
            name="%scope.text.name"
            parent="org.eclipse.ui.globalScope"
            description="%scope.text.description"
            id="org.eclipse.ui.textEditorScope">
      </scope>
   </extension>

Copyright IBM Corporation and others 2000, 2003.