[swell-foop/arnaudb/wip/gtk4: 38/44] Save settings on window destroy.




commit aad00e5f8606d4e647799510c9fd71ce94a650bd
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed May 13 19:31:42 2020 +0200

    Save settings on window destroy.

 src/swell-foop.vala | 13 +------------
 src/window.vala     |  6 ++++--
 2 files changed, 5 insertions(+), 14 deletions(-)
---
diff --git a/src/swell-foop.vala b/src/swell-foop.vala
index 62d99af..a80dd73 100644
--- a/src/swell-foop.vala
+++ b/src/swell-foop.vala
@@ -33,7 +33,7 @@ public class SwellFoop : Gtk.Application
     {
         { "help",          help_cb        },
         { "about",         about_cb       },
-        { "quit",          quit_cb        }
+        { "quit",          quit           }
     };
 
     public static int main (string[] args)
@@ -77,22 +77,11 @@ public class SwellFoop : Gtk.Application
         add_window (window);
     }
 
-    protected override void shutdown ()
-    {
-        window.destroy ();
-        base.shutdown ();
-    }
-
     protected override void activate ()
     {
         window.present ();
     }
 
-    private inline void quit_cb (/* SimpleAction action, Variant? variant */)
-    {
-        window.destroy ();
-    }
-
     private inline void help_cb (/* SimpleAction action, Variant? variant */)
     {
         Gtk.show_uri (window, "help:swell-foop", Gdk.CURRENT_TIME);
diff --git a/src/window.vala b/src/window.vala
index 6eacd85..26f4fab 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -96,6 +96,8 @@ private class SwellFoopWindow : ApplicationWindow
         settings.changed ["theme"].connect (load_theme);
         load_theme (settings, "theme");
 
+        close_request.connect (on_close_request);
+
         int32 colors = settings.get_int ("colors"); // 2 <= colors <= 4, per schema file
         SimpleAction colors_action = (SimpleAction) lookup_action ("change-colors");
         colors_action.set_state (new Variant.@string (colors.to_string ()));
@@ -228,7 +230,7 @@ private class SwellFoopWindow : ApplicationWindow
         game.bind_property ("can-redo", redo_action, "enabled", BindingFlags.SYNC_CREATE);
     }
 
-    protected override void destroy ()
+    private inline bool on_close_request ()
     {
         settings.delay ();
         settings.set_value ("saved-game", game.get_saved_game ());
@@ -241,7 +243,7 @@ private class SwellFoopWindow : ApplicationWindow
             }
         settings.apply ();
 
-        base.destroy ();
+        return /* do not stop other handlers */ false;
     }
 
     /*\


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]