Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override Eclipse File > Save Action

I am trying to override the Eclipse File > Save menu action to add some functionality. I have tried the following things

a) Create a new action and add it to the global action handler

actionBars.setGlobalActionHandler(ActionFactory.SAVE.getId(), mySaveAction); actionRegistry.registerAction(action);

b) Create a new handler and override the save command

<extension point="org.eclipse.ui.handlers">
<handler commandId="org.eclipse.ui.file.save"
  class="com.diagrams.ui.SaveFileHandler">
<enabledWhen> 
  <with variable="activePartId">
  <equals 
    value="com.diagrams.editors.MultiPageEditor" />
  </with>
</enabledWhen>
<activeWhen>
  <with variable="activePartId">
  <equals 
  value="com.diagrams.editors.MultiPageEditor" />
  </with>
</activeWhen>
</handler>
</extension> 

With both these approaches I have been able to override the Keyboard Ctrl+S functionality but the "File > Save" menu seem to work differently.

Would really appreciate any help, Thanks

like image 901
Abhishek Rakshit Avatar asked May 05 '11 14:05

Abhishek Rakshit


1 Answers

In an RCP application, you can contribute the Save action in your ActionBarAdvisor. This also registers the action so it is available from the save command.

But as a plugin in the Eclipse IDE, the IDE provides the ActionBarAdvisor and hooks up the Save action in the File menu. Because that's not technically a command (Actions are a step above an SWT.Selection listener) that's why you can't override the File>Save action.

However, each part provides its own save implementation, so you can do whatever you want in your MultiPageEditor.

The other option is to use org.eclipse.ui.commands.ICommandService.addExecutionListener(IExecutionListener) and add an IExecutionListener (or IEL2). That can listen for the save command, the ID is declared in org.eclipse.ui.IWorkbenchCommandConstants.

like image 64
Paul Webster Avatar answered Oct 16 '22 12:10

Paul Webster