[gnome-tetravex/arnaudb/wip/gtk4: 56/60] Adapt to Dialog API.




commit ec5f2622596c521ab8e298bc7cfc68af27adc313
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Mon Aug 3 18:31:50 2020 +0200

    Adapt to Dialog API.

 src/gnome-tetravex.vala | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)
---
diff --git a/src/gnome-tetravex.vala b/src/gnome-tetravex.vala
index 0666fc8..a25b8d2 100644
--- a/src/gnome-tetravex.vala
+++ b/src/gnome-tetravex.vala
@@ -791,11 +791,13 @@ private class Tetravex : Gtk.Application
         /* Translators: popup dialog possible answer (with a mnemonic that appears pressing Alt); appearing 
when user clicks "New Game" from the hamburger menu; other possible answer is "_Keep Playing" */
                                 _("_Start New Game"), ResponseType.ACCEPT);
 
-            int response = dialog.run ();
-            dialog.destroy ();
-
-            if (response != ResponseType.ACCEPT)
-                return;
+            dialog.response.connect ((_dialog, response) => {
+                    _dialog.destroy ();
+                    if (response == ResponseType.ACCEPT)
+                        new_game (/* saved game */ null, size);
+                });
+            dialog.present ();
+            return;
         }
         new_game (/* saved game */ null, size);
     }
@@ -823,9 +825,12 @@ private class Tetravex : Gtk.Application
             dialog.set_transient_for (window);
         }
 
-        dialog.run ();
-        dialog.destroy ();
-        scores_dialog_visible = false;
+        dialog.close_request.connect (() => {
+                scores_dialog_visible = false;
+
+                return /* do your usual stuff */ false;
+            });
+        dialog.present ();
     }
 
     private bool has_been_solved = false;
@@ -849,13 +854,18 @@ private class Tetravex : Gtk.Application
             /* Translators: popup dialog possible answer (with a mnemonic that appears pressing Alt); 
appearing when user clicks the "Give up" button in the bottom bar; other possible answer is "_Keep Playing" */
                                 _("_Give Up"),      ResponseType.ACCEPT);
 
-            int response = dialog.run ();
-            dialog.destroy ();
-
-            if (response != ResponseType.ACCEPT)
-                return;
+            dialog.response.connect ((_dialog, response) => {
+                    _dialog.destroy ();
+                    if (response == ResponseType.ACCEPT)
+                        after_solve_cb ();
+                });
+            dialog.present ();
+            return;
         }
-
+        after_solve_cb ();
+    }
+    private void after_solve_cb ()
+    {
         has_been_solved = true;
         puzzle.solve ();
         new_game_solve_stack.set_visible_child_name ("new-game");


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