From cadc14e4b1f228165b6ff1db3d46303b6bd52593 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sun, 17 Dec 2023 14:51:21 +0000 Subject: [PATCH 1/2] Fix new backup creation during closing a document (#1344) * Stop recreating backup file when closing and stripping trailing space * Use new flag for closing to avoid side-effects --- src/Services/Document.vala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Services/Document.vala b/src/Services/Document.vala index 99e3cb797..9a60406ca 100644 --- a/src/Services/Document.vala +++ b/src/Services/Document.vala @@ -130,6 +130,7 @@ namespace Scratch.Services { private ulong onchange_handler_id = 0; // It is used to not mark files as changed on load private bool loaded = false; private bool mounted = true; // Mount state of the file + private bool closing = false; private Mount mount; private Icon locked_icon; @@ -468,6 +469,7 @@ namespace Scratch.Services { if (ret_value) { // Delete backup copy file + closing = true; // Stops recreating backup when trailing space stripped delete_backup (); doc_closed (); } @@ -1044,7 +1046,7 @@ namespace Scratch.Services { // Backup functions private void create_backup () { - if (!can_write ()) { + if (!can_write () || closing) { return; } From 50f50a92b6639d3e166566d84bbecfa54c373920 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sun, 17 Dec 2023 15:06:30 +0000 Subject: [PATCH 2/2] Close root folder if externally deleted or renamed (#1390) --- src/FolderManager/FolderItem.vala | 2 +- src/FolderManager/ProjectFolderItem.vala | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/FolderManager/FolderItem.vala b/src/FolderManager/FolderItem.vala index a4ab38b72..de0250080 100644 --- a/src/FolderManager/FolderItem.vala +++ b/src/FolderManager/FolderItem.vala @@ -253,7 +253,7 @@ namespace Scratch.FolderManager { has_dummy = false; } - private void on_changed (GLib.File source, GLib.File? dest, GLib.FileMonitorEvent event) { + protected virtual void on_changed (GLib.File source, GLib.File? dest, GLib.FileMonitorEvent event) { if (source.get_basename ().has_prefix (".goutputstream")) { return; // Ignore changes due to temp files and streams } diff --git a/src/FolderManager/ProjectFolderItem.vala b/src/FolderManager/ProjectFolderItem.vala index 247b0803c..46864b003 100644 --- a/src/FolderManager/ProjectFolderItem.vala +++ b/src/FolderManager/ProjectFolderItem.vala @@ -82,6 +82,14 @@ namespace Scratch.FolderManager { } } + protected override void on_changed (GLib.File source, GLib.File? dest, GLib.FileMonitorEvent event) { + if (source.equal (file.file) && event == DELETED) { + closed (); + } else { + base.on_changed (source, dest, event); + } + } + public void child_folder_changed (FolderItem folder) { if (monitored_repo != null) { monitored_repo.update_status_map ();