From 38b87771e6bcb8869180004f0aa188822e9fa674 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sat, 8 Feb 2025 16:32:19 +0000 Subject: [PATCH] Avoid calling doc.do_close () twice --- src/Services/Document.vala | 10 ++++++++-- src/Widgets/DocumentView.vala | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Services/Document.vala b/src/Services/Document.vala index 528570095a..253356d9e2 100644 --- a/src/Services/Document.vala +++ b/src/Services/Document.vala @@ -158,6 +158,8 @@ namespace Scratch.Services { } } + public bool closing { get; private set; default = false; } + public Gtk.Stack main_stack; public Scratch.Widgets.SourceView source_view; private Scratch.Services.SymbolOutline? outline = null; @@ -181,7 +183,6 @@ 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; @@ -470,6 +471,9 @@ namespace Scratch.Services { public async bool do_close (bool app_closing = false) { debug ("Closing \"%s\"", get_basename ()); + if (closing) { + return true; + } if (!loaded) { load_cancellable.cancel (); @@ -488,7 +492,6 @@ namespace Scratch.Services { // Ask whether to save changes var parent_window = source_view.get_toplevel () as Gtk.Window; - var dialog = new Granite.MessageDialog ( _("Save changes to ā€œ%sā€ before closing?").printf (this.get_basename ()), _("If you don't save, changes will be permanently lost."), @@ -1155,6 +1158,9 @@ namespace Scratch.Services { file.delete (); return true; } catch (Error e) { + if (e is IOError.NOT_FOUND) { + return true; + } warning ("Cannot delete temporary file ā€œ%sā€: %s", file.get_uri (), e.message); } diff --git a/src/Widgets/DocumentView.vala b/src/Widgets/DocumentView.vala index f45fc16ab7..a98553980b 100644 --- a/src/Widgets/DocumentView.vala +++ b/src/Widgets/DocumentView.vala @@ -122,6 +122,10 @@ public class Scratch.Widgets.DocumentView : Gtk.Box { // TabView tab events tab_view.close_page.connect ((tab) => { var doc = tab.child as Services.Document; + if (doc == null || doc.closing) { + return true; // doc.do_close () already called once + } + if (doc == null) { tab_view.close_page_finish (tab, true); } else {