tags:

views:

107

answers:

1

The Eclipse RCP command framework is intended to replace the action framework as the mechanism for allowing plugins to contribute UI commands to the workbench. As well as defining new commands, plugins may provide handlers for default RCP commands such as "org.eclipse.ui.file.save" (full list of default commands here: http://svn2.assembla.com/svn/eclipsecommands/trunk/EclipseCommands/contents/article.html).

Using default commands brings the advantages of standard key bindings and icons, and in some cases the ability to use the built-in Eclipse actions.

For example the default editor save command can be added to the File menu with the following snippet in plugin.xml:

<extension point="org.eclipse.ui.menus">
  <menuContribution locationURI="menu:file">
    <command commandId="org.eclipse.ui.file.save"
             style="push">
    </command>
  </menuContribution>
</extension>

A handler can then be defined for this command by adding a handler definition in the handlers extension point in plugin.xml. If, however, the editors being contributed implement IEditorPart, it should be possible to simply use the built-in Eclipse save action (which takes care of tracking the active editor and dirty property updates) instead of defining a new handler. What further steps are necessary to use the built-in save action?

A: 

It is necessary to call ActionBarAdvisor.register() to make the save action available. For example:

public class MyActionBarAdvisor extends ActionBarAdvisor {
  public MyActionBarAdvisor(IActionBarConfigurer configurer) {
    super(configurer);
  }
  protected void makeActions(final IWorkbenchWindow window) {
    register(ActionFactory.SAVE.create(window));
  }
}

Given the addition to plugin.xml in the question, the built-in save handler will now be invoked for any active editor.

Steve Seear

related questions