Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to override Eclipse "File > Save" Action(Need help in overriding default Eclipse Save Action/Command)
How to override Eclipse "File > Save" Action [message #668445] Thu, 05 May 2011 16:55 Go to next message
Abhishek Rakshit is currently offline Abhishek RakshitFriend
Messages: 8
Registered: April 2011
Junior Member
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 16:55]

Report message to a moderator

Re: How to override Eclipse "File > Save" Action [message #668468 is a reply to message #668445] Thu, 05 May 2011 19:13 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

File>Save is defined and added to the menu in the RCP apps
ActionBarAdvisor. In the Eclipse IDE, that's the IDE's
WorkbenchActionBuilder adding it as a Action (as opposed to command),
which you can't change.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Re: How to override Eclipse "File > Save" Action [message #668477 is a reply to message #668468] Thu, 05 May 2011 19:49 Go to previous messageGo to next message
Abhishek Rakshit is currently offline Abhishek RakshitFriend
Messages: 8
Registered: April 2011
Junior Member
Thanks for the quick reply Paul.

So, is there a workaround for adding some functionality to the eclipse WorkbenchActionBuilder actions for a specific type of activePartId?
Re: How to override Eclipse "File > Save" Action [message #668600 is a reply to message #668477] Fri, 06 May 2011 11:06 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

On 05/05/2011 03:49 PM, Abhishek Rakshit wrote:
> So, is there a workaround for adding some functionality to the eclipse
> WorkbenchActionBuilder actions for a specific type of activePartId?

In your own RCP app, you control the main menu/toolbar using your
ActionBarAdvisor. In the eclipse IDE, you can add whatever you'd like
to the main menu/toolbar using org.eclipse.ui.menus, commands, and
handlers. You just cannot change something that's added directly to the
main menu (as Save is done by the WorkbenchActionBuilder).


PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Re: How to override Eclipse "File > Save" Action [message #668601 is a reply to message #668477] Fri, 06 May 2011 11:07 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

On 05/05/2011 03:49 PM, Abhishek Rakshit wrote:
> So, is there a workaround for adding some functionality to the eclipse
> WorkbenchActionBuilder actions for a specific type of activePartId?

The best you can do is add an execution listener to the
ICommandService, and listen for the save command. The IDs are listed in
org.eclipse.ui.IWorkbenchCommandConstants

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Re: How to override Eclipse "File > Save" Action [message #668649 is a reply to message #668601] Fri, 06 May 2011 14:58 Go to previous messageGo to next message
Abhishek Rakshit is currently offline Abhishek RakshitFriend
Messages: 8
Registered: April 2011
Junior Member
Thanks for your help Paul. I'll look into adding the execution Listener.
Re: How to override Eclipse "File > Save" Action [message #873442 is a reply to message #668601] Fri, 18 May 2012 08:51 Go to previous message
Stoian Vlad is currently offline Stoian VladFriend
Messages: 1
Registered: May 2012
Junior Member
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) {
.....

}
});
Previous Topic:How to use the RefreshProvider?
Next Topic:Why does getElement() always return null in PropertyPage?
Goto Forum:
  


Current Time: Tue Mar 19 08:12:15 GMT 2024

Powered by FUDForum. Page generated in 0.02498 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top