Browse Source

Guard against spuriously saving blank files.

Because for some reason this would happen seemingly at random before.
No idea why. But I did test that it occurs during save, not read.

And it doesn't appear to happen anymore.
tags/v1.0.0
Adrian Cochrane 5 years ago
parent
commit
961c8cde87
1 changed files with 6 additions and 2 deletions
  1. +6
    -2
      src/window.vala

+ 6
- 2
src/window.vala View File

@@ -56,8 +56,12 @@ public class WriteAs.MainWindow : Gtk.ApplicationWindow {
Timeout.add_full(Priority.DEFAULT_IDLE, 100/*ms*/, () => {
if (!text_changed) return Source.CONTINUE;

var text = canvas.buffer.text;
// This happens sometimes for some reason, but it's difficult to debug.
if (text == "") return Source.CONTINUE;

try {
draft_file().replace_contents(canvas.buffer.text.data, null, false,
draft_file().replace_contents(text.data, null, false,
FileCreateFlags.PRIVATE | FileCreateFlags.REPLACE_DESTINATION,
null);
text_changed = false;
@@ -76,7 +80,7 @@ public class WriteAs.MainWindow : Gtk.ApplicationWindow {
init_folder();
try {
open_file(draft_file());
} catch (Error err) {/* It's fine... */}
} catch (Error err) {canvas.buffer.text = err.message;}
restore_styles();

set_default_size(800, 600);


Loading…
Cancel
Save