Skip to content

Commit

Permalink
Saving file on changing of notes if needed instead of not changing no…
Browse files Browse the repository at this point in the history
…tes.
  • Loading branch information
thejambi committed Jul 1, 2017
1 parent eb16835 commit 52b952e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/Note.vala
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public class Note : GLib.Object {
public void setNoteInfo(string newTitle) {
this.title = newTitle;
this.filePath = FileUtility.pathCombine(UserData.notesDirPath, this.title + UserData.fileExtension);

if (this.title.has_prefix("/")) {
Zystem.debug("Not setting noteFile for note starting with /");
return;
}

this.noteFile = File.new_for_path(this.filePath);
}

Expand Down Expand Up @@ -117,7 +123,7 @@ public class Note : GLib.Object {
}

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

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

try {
this.noteFile.replace_contents(text.data, null, false, FileCreateFlags.NONE, null, null);
Expand Down
7 changes: 7 additions & 0 deletions src/Zystem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ class Zystem : GLib.Object {
}
}

/**
* Debug method. Prints no matter what.
*/
/*public static void debugX(string s) {
stdout.printf(s + "\n");
}*/

/**
*
*/
Expand Down
23 changes: 20 additions & 3 deletions src/psnotes.vala
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,15 @@ public class Main : Window {
}

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

if (this.saveRequested) {
this.saveNonAsync(); // Trying this to call save on current note before changing it.
}

TreeModel model;
TreeIter iter;
treeSelection.get_selected(out model, out iter);
Expand Down Expand Up @@ -809,6 +813,11 @@ public class Main : Window {
}

private void createNewNote() {
if (this.saveRequested) {
this.saveNonAsync(); // Trying this to call save on current note before changing it.
//return; // Don't create new note if waiting for current note to save.
}

this.note = new Note("");
this.needsSave = false;
this.isOpening = true;
Expand Down Expand Up @@ -990,6 +999,14 @@ public class Main : Window {
this.resetNotesView();
}

private void saveNonAsync() {
this.saveRequested = false;
if (this.timerId != 0) {
Source.remove(this.timerId);
}
this.note.save(this.editor.getText());
}

/**
* Quit P.S. Notes.
*/
Expand All @@ -999,7 +1016,7 @@ public class Main : Window {
if (this.saveRequested && this.timerId != 0) {
Source.remove(this.timerId);

this.note.save(this.editor.getText());
this.saveNonAsync();
}

// Save window size
Expand Down

0 comments on commit 52b952e

Please sign in to comment.