Editor Menus, Toolbars and Actions

Identifier: org.eclipse.ui.editorActions

Description: This extension point is used to add actions to the menu and toolbar for editors registered by other plug-ins.

The initial contribution set for an editor is defined by another extension point (org.eclipse.ui.editors). One set of actions is created and shared by all instances of the same editor type.  When invoked, these action act upon the active editor.  This extension point follows the same pattern.  Each action extension is created and shared by all instances of the same editor type.  The action class is required to implement org.eclipse.ui.IEditorActionDelegate.  The active editor is passed to the delegate by invoking IEditorActionDelegate#setActiveEditor.

Configuration Markup:

   <!ELEMENT editorContribution (menu | action)*>
   <!ATTLIST editorContribution
      id         CDATA #REQUIRED
      targetID   CDATA #REQUIRED
   >

  • id - a unique identifier that can be used to reference this contribution
  • editorID - a unique identifier of a previously registered editor that is the target of this contribution
  •    <!ELEMENT menu (separator)+>
       <!ATTLIST menu
          id         CDATA #REQUIRED
          label      CDATA #REQUIRED
          path       CDATA #IMPLIED
       >    <!ELEMENT separator EMPTY>
       <!ATTLIST separator
          name       CDATA #REQUIRED
       >
  • name - a name of the separator that can later be referenced as the last token in the action path. Therefore, separators serve as named groups into which actions can be added.
  •    <!ELEMENT action (selection)* (enablement)?>
       <!ATTLIST action
          id                NMTOKEN #REQUIRED
          label             CDATA #REQUIRED
          accelerator       CDATA #IMPLIED
          menubarPath       CDATA #IMPLIED
          toolbarPath       CDATA #IMPLIED
          icon              CDATA #IMPLIED
          disabledIcon      CDATA #OPTIONAL
          hoverIcon         CDATA #OPTIONAL
          tooltip           CDATA #IMPLIED
          helpContextId     CDATA #IMPLIED
          state             (true | false) #IMPLIED
          class             CDATA #REQUIRED
          enablesFor        CDATA #IMPLIED
       >    <!ELEMENT selection EMPTY>
       <!ATTLIST selection
          class             CDATA #REQUIRED
          name              CDATA #IMPLIED
       >    <!ELEMENT enablement (and | or | not | objectClass | objectState | systemProperty
            | pluginState)>
       <!ATTLIST enablement EMPTY>
    In version 2.0 of Eclipse, an enablement element may be used to define the enablement for the action.  For more information on the use of enablement element, refer to actionExpressions.html.
    The enablement criteria for an action extension are initially defined by enablesFor, selection and enablement.  However, once the action delegate has been instantiated, it may control the action enable state directly within its selectionChanged method.

    Action and menu labels may contain special characters that encode mnemonics and accelerators using the following rules:

    1. Mnemonics are specified using the ampersand ('&') character in front of a selected character in the translated text. Since ampersand is not allowed in XML strings, use &amp; character entity.
    2. Optional accelerators are specified at the and of the name string, using @ followed by the series of modifiers and the final accelerator character (for example, &amp;Save@Ctrl+S). Modifiers can be chained using the '+' sign as the delimiter (as in @Ctrl+Shift+S).
    If two or more actions are contributed to a menu or toolbar by a single extension the actions will appear in the reverse order of how they are listed in the plugin.xml file. This behavior is admittedly unintuitive.  However, it was discovered after the  Eclipse Platform API was frozen.  Changing the behavior now would break every plug-in which relies upon the existing behavior.

    Examples:

    The following is an example of an editor action extension point:

       <extension point="org.eclipse.ui.editorActions">
          <editorContribution
             id="com.xyz.xyzContribution"
             targetID="com.ibm.XMLEditor">
             <menu id="XYZ" label="&amp;XYZ Menu">
                <separator name="group1"/>
             </menu>
             <action
                  id="com.xyz.runXYZ"
                  label="&amp;Run XYZ Tool"
                  menubarPath="XYZ/group1"
                  toolbarPath="Normal/additions"
                  state="true"
                  icon="icons/runXYZ.gif"
                  tooltip="Run XYZ Tool"
                  helpContextId="com.xyz.run_action_context"
                  class="com.xyz.actions.RunXYZ">
             </action>
          </editorContribution>
       </extension>

    In the example above, the specified action will appear as a check box item in the new top-level menu named "XYZ Menu", and as a toggle button in the toolbar.

    The following is an example of an editor action extension point:

       <extension point="org.eclipse.ui.editorActions">
          <editorContribution
             id="com.xyz.xyz2Contribution"
             targetID="com.ibm.XMLEditor">
             <menu
                id="XYZ2"
                label="&amp;XYZ2 Menu"
                path="edit/additions">
                <separator name="group1"/>
             </menu>
             <action
                  id="com.xyz.runXYZ2"
                  label="&amp;Run XYZ2 Tool"
                  menubarPath="edit/XYZ2/group1"
                  state="true"
                  icon="icons/runXYZ2.gif"
                  tooltip="Run XYZ2 Tool"
                  helpContextId="com.xyz.run_action_context2"
                  class="com.xyz.actions.RunXYZ2">
             </action>
          </editorContribution>
       </extension>

    In the example above, the specified action will appear as a check box item in the sub-menu named "XYZ2 Menu" in the top level "Edit" menu.

    API Information: The value of the class attribute must be a fully qualified name of a Java class that implements org.eclipse.ui.IEditorActionDelegate. This interface is loaded as late as possible to avoid loading the entire plug-in before it is really needed. The method setActiveEditor will be called each time an editor of the specified type is activated. Only one set of actions and menus will be created for all instances of the specified editor type, regardless of the number of editor instances currently opened in the workbench.

    This extension point can be used to contribute actions into menus previously created by the target editor. In addition, menus and actions can be contributed to the workbench window.  The identifiers for actions and major groups within the workbench window are defined in org.eclipse.ui.IWorkbenchActionConstants.  These should be used as a reference point for the addition of new actions.  Top level menus are created by using the following values for the path attribute:

    Actions and menus added into these paths will only be shown while the associated editor is active. When the editor is closed, menus and actions will be removed.

    Supplied Implementation: The workbench provides a built-in "Default Text Editor". Plug-ins can contribute into this default editor or editors provided by other plug-ins.

    Copyright IBM Corporation and others 2000, 2002.