Last Comment Bug 700893 - API for tracking unsaved/saved state in source editor
: API for tracking unsaved/saved state in source editor
Status: RESOLVED FIXED
[sourceeditor]
: dev-doc-complete
Product: Firefox
Classification: Client Software
Component: Developer Tools: Scratchpad (show other bugs)
: Trunk
: All All
: -- normal (vote)
: Firefox 13
Assigned To: Mihai Sucan [:msucan]
:
: Julian Descottes [:jdescottes]
Mentors:
Depends on: 717613
Blocks: 684445 723057
  Show dependency treegraph
 
Reported: 2011-11-08 18:12 PST by Heather Arthur [:harth]
Modified: 2012-04-28 11:58 PDT (History)
5 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
proposed patch (30.07 KB, patch)
2012-02-01 13:23 PST, Mihai Sucan [:msucan]
no flags Details | Diff | Splinter Review
[in-fx-team] rebased patch (30.07 KB, patch)
2012-02-09 09:47 PST, Mihai Sucan [:msucan]
rcampbell: review+
fayearthur: feedback+
Details | Diff | Splinter Review

Description Heather Arthur [:harth] 2011-11-08 18:12:05 PST
As brought up in bug 669612, there should be a way to tell the source editor "this text is 'saved'", and a way to query whether the text is still in that 'saved' state, across changes and undos.
Comment 1 Cedric Vivier [:cedricv] 2011-11-08 23:22:28 PST
Perhaps it would make sense to implement the Save to file feature within SourceEditor to avoid duplication as well?
Comment 2 Mihai Sucan [:msucan] 2011-11-09 05:24:51 PST
(In reply to Cedric Vivier [cedricv] from comment #1)
> Perhaps it would make sense to implement the Save to file feature within
> SourceEditor to avoid duplication as well?

Interesting idea.

Currently I want to keep the Source Editor a "text widget" with the common features needed to build the UI of devtools, for source code editing. Syntax highlighting, rulers, autocomplete and so on.

Saving files is what the user of the Source Editor might want to do, but not always. We'll see, in the future.

The Orion editor upstream has the concept of tracking the "dirty"/saved/unsaved state. Save is also a command that is implemented externally - it's up to the integrator what save means. That's what I imagine for our Source Editor as well. We just didn't (yet) take in this part of their code.

We'll see in the future. Anyhow, this bug is about the saved state. :)
Comment 3 Rob Campbell [:rc] (:robcee) 2011-11-18 14:58:07 PST
One potential way to implement this would be to verify the content's of the editor's undo stack. If the stack is empty, the file is back to "saved" or "unchanged". If there are undos on the stack, then the file is considered modified.

This seems to match up with the way other editors (e.g., TextMate) check their modified state.
Comment 4 Mihai Sucan [:msucan] 2012-01-30 13:00:54 PST
This now blocks bug 684445 because we need a proper way to update the undo/redo xul:commands.

I already have patches in the works for both bugs.
Comment 5 Mihai Sucan [:msucan] 2012-02-01 13:23:04 PST
Created attachment 593586 [details] [diff] [review]
proposed patch

Proposed patch. Note that this also fixes bug 723057.
Comment 6 Mihai Sucan [:msucan] 2012-02-09 09:47:41 PST
Created attachment 595790 [details] [diff] [review]
[in-fx-team] rebased patch
Comment 7 Mihai Sucan [:msucan] 2012-02-09 11:08:21 PST
The new Source Editor API event, DIRTY_CHANGED, and the new editor.dirty property need to be documented. Example use is in scratchpad.js. Thank you!
Comment 8 Rob Campbell [:rc] (:robcee) 2012-02-21 02:23:11 PST
Comment on attachment 595790 [details] [diff] [review]
[in-fx-team] rebased patch

solid. I wish I had some comments for you, but it all looks ok to my pre-caffeinated self.

You could ask harth for feedback around the Scratchpad title-marking and saving stuff and I will do so.
Comment 9 Mihai Sucan [:msucan] 2012-02-21 10:15:03 PST
Thanks Rob for the r+!

Yep, it makes sense to ask Heather for a feedback round. Looking forward to her feedback!
Comment 10 Heather Arthur [:harth] 2012-02-22 18:25:43 PST
Comment on attachment 595790 [details] [diff] [review]
[in-fx-team] rebased patch

looks good to me too.
Comment 11 Mihai Sucan [:msucan] 2012-02-27 10:56:13 PST
Comment on attachment 595790 [details] [diff] [review]
[in-fx-team] rebased patch

Landed:
https://hg.mozilla.org/integration/fx-team/rev/5b33f5c7e630
Comment 12 Mihai Sucan [:msucan] 2012-02-27 10:57:05 PST
Thanks Heather for the f+!
Comment 13 Tim Taubert [:ttaubert] 2012-02-27 23:46:20 PST
https://hg.mozilla.org/mozilla-central/rev/5b33f5c7e630
Comment 14 Eric Shepherd [:sheppy] 2012-04-28 11:58:28 PDT
This is already documented on:

https://developer.mozilla.org/en/JavaScript_code_modules/source-editor.jsm

Added to Firefox 13 for developers.

Note You need to log in before you can comment on or make changes to this bug.