Skip to content

Commit 52b952e

Browse files
committed
Saving file on changing of notes if needed instead of not changing notes.
1 parent eb16835 commit 52b952e

3 files changed

Lines changed: 35 additions & 5 deletions

File tree

src/Note.vala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ public class Note : GLib.Object {
5050
public void setNoteInfo(string newTitle) {
5151
this.title = newTitle;
5252
this.filePath = FileUtility.pathCombine(UserData.notesDirPath, this.title + UserData.fileExtension);
53+
54+
if (this.title.has_prefix("/")) {
55+
Zystem.debug("Not setting noteFile for note starting with /");
56+
return;
57+
}
58+
5359
this.noteFile = File.new_for_path(this.filePath);
5460
}
5561

@@ -117,7 +123,7 @@ public class Note : GLib.Object {
117123
}
118124

119125
private async void saveFileContentsAsync(string text) throws GLib.Error {
120-
Zystem.debug("ACTUALLY SAVING FILE");
126+
Zystem.debug("ACTUALLY SAVING FILE: " + this.title);
121127
yield this.noteFile.replace_contents_async(text.data, null, false, FileCreateFlags.NONE, null, null);
122128
//this.loadedContents = text;
123129
}
@@ -131,7 +137,7 @@ public class Note : GLib.Object {
131137
}
132138

133139
private void saveFileContents(string text) {
134-
Zystem.debug("ACTUALLY SAVING FILE");
140+
Zystem.debug("ACTUALLY SAVING FILE: " + this.title);
135141

136142
try {
137143
this.noteFile.replace_contents(text.data, null, false, FileCreateFlags.NONE, null, null);

src/Zystem.vala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ class Zystem : GLib.Object {
4242
}
4343
}
4444

45+
/**
46+
* Debug method. Prints no matter what.
47+
*/
48+
/*public static void debugX(string s) {
49+
stdout.printf(s + "\n");
50+
}*/
51+
4552
/**
4653
*
4754
*/

src/psnotes.vala

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,15 @@ public class Main : Window {
480480
}
481481

482482
private void noteSelected(TreeSelection treeSelection) {
483-
if (this.loadingNotes || this.saveRequested) {
484-
Zystem.debug("Ignoring note selected due to loadingNotes || saveRequested. lastLoadRequestType: " + this.filter.lastLoadRequestType.to_string());
483+
if (this.loadingNotes) {
484+
Zystem.debug("Ignoring note selected due to loadingNotes. lastLoadRequestType: " + this.filter.lastLoadRequestType.to_string());
485485
return;
486486
}
487487

488+
if (this.saveRequested) {
489+
this.saveNonAsync(); // Trying this to call save on current note before changing it.
490+
}
491+
488492
TreeModel model;
489493
TreeIter iter;
490494
treeSelection.get_selected(out model, out iter);
@@ -809,6 +813,11 @@ public class Main : Window {
809813
}
810814

811815
private void createNewNote() {
816+
if (this.saveRequested) {
817+
this.saveNonAsync(); // Trying this to call save on current note before changing it.
818+
//return; // Don't create new note if waiting for current note to save.
819+
}
820+
812821
this.note = new Note("");
813822
this.needsSave = false;
814823
this.isOpening = true;
@@ -990,6 +999,14 @@ public class Main : Window {
990999
this.resetNotesView();
9911000
}
9921001

1002+
private void saveNonAsync() {
1003+
this.saveRequested = false;
1004+
if (this.timerId != 0) {
1005+
Source.remove(this.timerId);
1006+
}
1007+
this.note.save(this.editor.getText());
1008+
}
1009+
9931010
/**
9941011
* Quit P.S. Notes.
9951012
*/
@@ -999,7 +1016,7 @@ public class Main : Window {
9991016
if (this.saveRequested && this.timerId != 0) {
10001017
Source.remove(this.timerId);
10011018

1002-
this.note.save(this.editor.getText());
1019+
this.saveNonAsync();
10031020
}
10041021

10051022
// Save window size

0 commit comments

Comments
 (0)