Merge lp:~niclasl/scratch/fix-1299240 into lp:~elementary-apps/scratch/scratch

Proposed by Niclas Lockner
Status: Merged
Approved by: Mario Guerriero
Approved revision: 1276
Merged at revision: 1281
Proposed branch: lp:~niclasl/scratch/fix-1299240
Merge into: lp:~elementary-apps/scratch/scratch
Diff against target: 59 lines (+11/-4)
1 file modified
src/Services/Document.vala (+11/-4)
To merge this branch: bzr merge lp:~niclasl/scratch/fix-1299240
Reviewer Review Type Date Requested Status
Mario Guerriero (community) Approve
Review via email: mp+215059@code.launchpad.net

Commit message

Description of the change

After a document has been opened from the files manager plugin, it is immediately saved due to the save call in the focus out callback. (After the doc is opened, the focus is back at the files manager plugin.)
Since the document's content is loaded asynchronously, the save action is performed before the content has been read from the file.

In this branch, the focus out callback only saves the document if it has been fully loaded.

To post a comment you must log in.
lp:~niclasl/scratch/fix-1299240 updated
1275. By Niclas Lockner

Moved the not-loaded check to save. Changed the type back to a bool

1276. By Niclas Lockner

Only load the content once

Revision history for this message
Niclas Lockner (niclasl) wrote :

I've pushed two new commits to the branch. The fix is better now than when I requested the merge.

Revision history for this message
Danielle Foré (danrabbit) wrote :

This definitely fixes the issue for me. Hope your branch gets reviewed soon :)

Revision history for this message
Mario Guerriero (mefrio-g) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Services/Document.vala'
2--- src/Services/Document.vala 2014-04-09 01:00:52 +0000
3+++ src/Services/Document.vala 2014-04-11 14:25:16 +0000
4@@ -52,6 +52,7 @@
5
6 // It is used to load file content on focusing
7 private bool loaded = false;
8+ private bool has_started_loading = false;
9
10 #if HAVE_ZEITGEIST
11 // Zeitgeist integration
12@@ -163,6 +164,7 @@
13 if (settings.autosave) {
14 save ();
15 }
16+
17 return false;
18 });
19
20@@ -249,7 +251,10 @@
21 public bool save () {
22 if (last_saved_content == get_text () && this.file != null)
23 return false;
24-
25+
26+ if (!this.loaded)
27+ return false;
28+
29 // Create backup copy file if it does not still exist
30 create_backup ();
31
32@@ -480,7 +485,7 @@
33
34 // Load file content
35 internal void load_content () {
36- if (!this.loaded) {
37+ if (!this.has_started_loading) {
38 FileHandler.load_content_from_file.begin (file, (obj, res) => {
39 var text = FileHandler.load_content_from_file.end (res);
40 if (text == null) {
41@@ -493,8 +498,10 @@
42 this.source_view.set_text (text);
43 this.last_saved_content = text;
44 this.original_content = text;
45+ this.loaded = true;
46 });
47- this.loaded = true;
48+
49+ this.has_started_loading = true;
50 }
51 }
52
53@@ -653,5 +660,5 @@
54 return this.file.query_exists ();
55 }
56 }
57-
58 }
59+

Subscribers

People subscribed via source and target branches