Bug 262054 - [EditorMgmt] Provide hook to text editor save action
Summary: [EditorMgmt] Provide hook to text editor save action
Status: REOPENED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-01-22 12:39 EST by Adam Neal CLA
Modified: 2021-04-21 13:41 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Neal CLA 2009-01-22 12:39:07 EST
We would like to preform a code to model synchronization upon editor saves.  Currently there is no way to be notified when an editor is saved, and thus we are resorting to resource change notifications.  However these notifications can be a result of any number of actions, and not necessarily the result of the user explicitly saving the source file, which makes our solution prone to preforming its behavior at the wrong time.

I am requesting that there is either an extension point or public API provided to register an observer of text editor saves.

It will be important to know the context (the IEditorPart) of the save, and for our purposes, to simply be notified after the save has occurred.  We have no need to participate in the save, or preempt it.  We just need to know that the user has explicitly saved a given source file.
Comment 1 Paul Webster CLA 2009-01-22 13:53:11 EST
Is this something that can be known from org.eclipse.ui.ISaveablesLifecycleListener?

PW
Comment 2 Boris Bokowski CLA 2009-01-26 23:25:02 EST
(In reply to comment #1)
> Is this something that can be known from
> org.eclipse.ui.ISaveablesLifecycleListener?

No, the only useful implementation of ISaveablesLifecycleListener is internal - you can't just hook one on a part.

Why do you want to perform your actions only when an editor is saved, and not when the file changes on disk?

The JDT has a notion of "Save Participant" - does that help in any way?
Comment 3 Adam Neal CLA 2009-01-27 09:57:12 EST
Hi,

File changes could be a result of generating code, in which case we do not want to trigger our logic. Or our tooling may automatically save the source in some cases (not by invoking the Global SaveAction, but by invoking doSave directly on the editor()) in which case we again don't want to invoke our logic. 

Ideally we would be notified on explict user saves.  Perhaps the logic could be apart of the SaveableHelper?  In which case if we 'short cut' and save directly on the editor instance (via tooling) we could avoid notification.

We are currently only dealing with the CDT so the JDT save participant is not feasible.

I would also like to suggest that registration is done via an extension point, as this would allow interested plugins to stay as unloaded until a save occurs.

Thanks,
Adam
Comment 4 Paul Webster CLA 2009-01-27 10:17:33 EST
You could listen for the save command, org.eclipse.ui.file.save

See org.eclipse.ui.commands.ICommandService.addExecutionListener(IExecutionListener)

PW
Comment 5 Adam Neal CLA 2009-02-19 10:47:53 EST
Hi,  the ICommandService was a great suggestion.  This provides me with enough information to do what I was wanting.

Thanks,
Adam
Comment 6 Boris Bokowski CLA 2009-02-20 11:27:44 EST
(In reply to comment #5)
> Hi,  the ICommandService was a great suggestion.  This provides me with enough
> information to do what I was wanting.

I am skeptical that this will work for you long-term. Have you tested the following:

- Save All
- Save As...
- Close the editor and click "yes" when prompted to save
- Shutdown Eclipse and click "yes" when prompted to save
- Run/debug something from within Eclipse - before launching, you may be prompted to save
- I am sure there are more.

I have a feeling that you are working against the mechanisms provided by the Workbench and the IDE rather than with them.
Comment 7 Boris Bokowski CLA 2009-11-17 13:05:23 EST
Remy is now responsible for watching the [EditorMgmt] component area.
Comment 8 Remy Suen CLA 2011-02-01 11:03:13 EST
(In reply to comment #5)
> Hi,  the ICommandService was a great suggestion.  This provides me with enough
> information to do what I was wanting.

Adam, can I close this bug report then?
Comment 9 Adam Neal CLA 2011-02-01 16:24:47 EST
Hi,

We have taken a different approach to solve the problem on our side.  So if you see minimal to no benefit in providing this enhancement, a then you should go head an close it.
Comment 10 Lars Vogel CLA 2019-09-24 13:51:46 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.
Comment 11 Lars Vogel CLA 2021-04-21 09:46:14 EDT
Would be great to have some general save actions in platform, for example:

- Remove trailing whitespace


Tools which would benefit from such a framework would be JavaScript, Html editor, etc. Currently only JDT has this ability.

Fabrice, do you think it is reasonable / possible to provide a general framework in text which JDT could also use?
Comment 12 Fabrice Tiercelin CLA 2021-04-21 13:41:50 EDT
It would be great but it's a big deal 😄 I should finish easier targets first.