[gnome-games] display-view: Extract async dialog running



commit 97a6fad272972b342cfecaeb597b3cb652b1c806
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Fri Oct 16 20:54:05 2020 +0500

    display-view: Extract async dialog running
    
    It's going to be repeated for 2 other dialogs as well, make it a nice
    compact helper.

 src/ui/display-view.vala | 40 ++++++++++++++++++----------------------
 1 file changed, 18 insertions(+), 22 deletions(-)
---
diff --git a/src/ui/display-view.vala b/src/ui/display-view.vala
index e79f6bfd..f86b910f 100644
--- a/src/ui/display-view.vala
+++ b/src/ui/display-view.vala
@@ -580,17 +580,7 @@ private class Games.DisplayView : Gtk.Box, UiView {
                        quit_dialog = null;
                });
 
-               var response = Gtk.ResponseType.CANCEL;
-
-               quit_dialog.response.connect (r => {
-                       response = (Gtk.ResponseType) r;
-
-                       quit_game_with_cancellable.callback ();
-               });
-
-               quit_dialog.present ();
-
-               yield;
+               var response = yield run_dialog_async (quit_dialog);
 
                // The null check is necessary because the dialog could already
                // be canceled by this point
@@ -711,17 +701,7 @@ private class Games.DisplayView : Gtk.Box, UiView {
                        var button = restart_dialog.add_button (_("Restart"), Gtk.ResponseType.ACCEPT);
                        button.get_style_context ().add_class ("destructive-action");
 
-                       var response = Gtk.ResponseType.CANCEL;
-
-                       restart_dialog.response.connect (r => {
-                               response = (Gtk.ResponseType) r;
-
-                               restart_internal.callback ();
-                       });
-
-                       restart_dialog.present ();
-
-                       yield;
+                       var response = yield run_dialog_async (restart_dialog);
 
                        restart_dialog.destroy ();
                        restart_dialog = null;
@@ -831,4 +811,20 @@ private class Games.DisplayView : Gtk.Box, UiView {
                        return false;
                }
        }
+
+       private async Gtk.ResponseType run_dialog_async (Gtk.Dialog dialog) {
+               var response = Gtk.ResponseType.CANCEL;
+
+               dialog.response.connect (r => {
+                       response = (Gtk.ResponseType) r;
+
+                       run_dialog_async.callback ();
+               });
+
+               dialog.present ();
+
+               yield;
+
+               return response;
+       }
 }


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