Reputation: 366
Probably a duplicate of this question, but I am specifically looking for a way to check that the save button in Eclipse was clicked, not that the editor is being saved.
Upvotes: 0
Views: 401
Reputation: 111142
You can use an IExecutionListener
to listen to the File Save command. Something like:
ICommandService commandSvc = PlatformUI.getWorkbench().getAdapter(ICommandService.class);
Command saveCommand = commandSvc.getCommand(IWorkbenchCommandConstants.FILE_SAVE);
saveCommand.addExecutionListener(new IExecutionListener()
{
@Override
public void preExecute(final String commandId, final ExecutionEvent event)
{
}
@Override
public void postExecuteSuccess(final String commandId, final Object returnValue)
{
}
@Override
public void postExecuteFailure(final String commandId, final ExecutionException exception)
{
}
@Override
public void notHandled(final String commandId, final NotHandledException exception)
{
}
});
IWorkbenchCommandConstants.FILE_SAVE
is the standard constant containing the file save command id.
The ExecutionEvent
parameter has a getTrigger
method which returns to object that caused the command to run. It looks like this will be a MenuItem
if the 'File > Save' menu caused the command to run.
Upvotes: 1