Skip to content

Commit 46258fa

Browse files
jeremypwJeremy Wootten
andauthored
Avoid calling doc.do_close () twice (#1538)
Co-authored-by: Jeremy Wootten <jeremy@Proteus-EL07R6-9b3c42bb.localdomain>
1 parent 9804df9 commit 46258fa

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/Services/Document.vala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ namespace Scratch.Services {
158158
}
159159
}
160160

161+
public bool closing { get; private set; default = false; }
162+
161163
public Gtk.Stack main_stack;
162164
public Scratch.Widgets.SourceView source_view;
163165
private Scratch.Services.SymbolOutline? outline = null;
@@ -181,7 +183,6 @@ namespace Scratch.Services {
181183
private ulong onchange_handler_id = 0; // It is used to not mark files as changed on load
182184
private bool loaded = false;
183185
private bool mounted = true; // Mount state of the file
184-
private bool closing = false;
185186
private Mount mount;
186187
private Icon locked_icon;
187188

@@ -470,6 +471,9 @@ namespace Scratch.Services {
470471

471472
public async bool do_close (bool app_closing = false) {
472473
debug ("Closing \"%s\"", get_basename ());
474+
if (closing) {
475+
return true;
476+
}
473477

474478
if (!loaded) {
475479
load_cancellable.cancel ();
@@ -488,7 +492,6 @@ namespace Scratch.Services {
488492

489493
// Ask whether to save changes
490494
var parent_window = source_view.get_toplevel () as Gtk.Window;
491-
492495
var dialog = new Granite.MessageDialog (
493496
_("Save changes to “%s” before closing?").printf (this.get_basename ()),
494497
_("If you don't save, changes will be permanently lost."),
@@ -1155,6 +1158,9 @@ namespace Scratch.Services {
11551158
file.delete ();
11561159
return true;
11571160
} catch (Error e) {
1161+
if (e is IOError.NOT_FOUND) {
1162+
return true;
1163+
}
11581164
warning ("Cannot delete temporary file “%s”: %s", file.get_uri (), e.message);
11591165
}
11601166

src/Widgets/DocumentView.vala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ public class Scratch.Widgets.DocumentView : Gtk.Box {
122122
// TabView tab events
123123
tab_view.close_page.connect ((tab) => {
124124
var doc = tab.child as Services.Document;
125+
if (doc == null || doc.closing) {
126+
return true; // doc.do_close () already called once
127+
}
128+
125129
if (doc == null) {
126130
tab_view.close_page_finish (tab, true);
127131
} else {

0 commit comments

Comments
 (0)