| How to override Eclipse "File > Save" Action [message #668445] |
Thu, 05 May 2011 12:55  |
Eclipse User |
|
|
|
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
[Updated on: Thu, 05 May 2011 12:55] by Moderator
|
|
|
|
|
|
|
|
| Re: How to override Eclipse "File > Save" Action [message #873442 is a reply to message #668601] |
Fri, 18 May 2012 04:51  |
Eclipse User |
|
|
|
Hi , I'am trying to do the same thing.
I have tried the solution that Paul proposed and I have added an execution listener to the save command but unfortunately it was working just for the keyboard combination Ctrl+S. For the save from menus it doesn't work.
Maybe you can help me with other solution? or maybe it's a reason why it's not working for me . The code is listed bellow :
String commandId = "org.eclipse.ui.file.save";
ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
Command command = service.getCommand(commandId);
command.addExecutionListener(new IExecutionListener() {
@Override
public void notHandled(String arg0, NotHandledException arg1) {
...
}
@Override
public void postExecuteFailure(String arg0, ExecutionException arg1){
...
}
@Override
public void postExecuteSuccess(String arg0, Object arg1) {
....
}
@Override
public void preExecute(String arg0, ExecutionEvent arg1) {
.....
}
});
|
|
|
Powered by
FUDForum. Page generated in 0.08530 seconds