How to use the Eclipse RCP command environment Save command with default save action?

The Eclipse RCP command frame is intended to replace the scope of the action as a mechanism that allows plugins to add UI commands to the workbench. In addition to defining new commands, plugins can provide handlers for RCP commands by default, such as "org.eclipse.ui.file.save" (the full list of default commands is here: http://svn2.assembla.com/svn/eclipsecommands/ trunk / EclipseCommands / contents / article.html ).

Using default commands gives you the benefits of standard key and icon bindings, and in some cases, the ability to use the Eclipse built-in actions.

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

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

You can then define a handler for this command by adding a handler definition to the extension point of the handlers in the plugin.xml file. If, however, the contributed editors implement IEditorPart, it should be possible to simply use the built-in Eclipse save action (which monitors the active editor and dirty property updates) instead of defining a new handler. What additional steps are required to use the built-in save action?

+3
source share
1 answer

To activate a save action, you must call ActionBarAdvisor.register (). For instance:

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

plugin.xml , .

+5

Source: https://habr.com/ru/post/1766007/


All Articles