[gnome-games/wip/exalm/rebrand: 13/102] display-view: Split run_dialog_async() into a separate file




commit 0b2f7a270a8cf686e7d62c36ebbf85f3da0a336f
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Wed Mar 24 20:25:24 2021 +0500

    display-view: Split run_dialog_async() into a separate file
    
    It will be useful in other places too. Add a native dialog variant as well.

 src/meson.build             |  1 +
 src/ui/display-view.vala    | 24 ++++--------------------
 src/utils/dialog-utils.vala | 35 +++++++++++++++++++++++++++++++++++
 3 files changed, 40 insertions(+), 20 deletions(-)
---
diff --git a/src/meson.build b/src/meson.build
index 58a8ff90..00eede56 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -170,6 +170,7 @@ vala_sources = [
   'utils/cue-sheet/cue-sheet-file-node.vala',
   'utils/cue-sheet/cue-sheet-track-mode.vala',
   'utils/cue-sheet/cue-sheet-track-node.vala',
+  'utils/dialog-utils.vala',
   'utils/directory.vala',
   'utils/file-operations.vala',
   'utils/filename-title.vala',
diff --git a/src/ui/display-view.vala b/src/ui/display-view.vala
index 6662521a..3d2b8258 100644
--- a/src/ui/display-view.vala
+++ b/src/ui/display-view.vala
@@ -458,7 +458,7 @@ private class Games.DisplayView : Gtk.Box, UiView {
                        resume_dialog = null;
                });
 
-               var response = yield run_dialog_async (resume_dialog);
+               var response = yield DialogUtils.run_async (resume_dialog);
 
                // The null check is necessary because the dialog could already
                // be canceled by this point
@@ -506,7 +506,7 @@ private class Games.DisplayView : Gtk.Box, UiView {
                        resume_failed_dialog = null;
                });
 
-               var response = yield run_dialog_async (resume_failed_dialog);
+               var response = yield DialogUtils.run_async (resume_failed_dialog);
 
                resume_failed_dialog.destroy ();
                resume_failed_dialog = null;
@@ -584,7 +584,7 @@ private class Games.DisplayView : Gtk.Box, UiView {
                        quit_dialog = null;
                });
 
-               var response = yield run_dialog_async (quit_dialog);
+               var response = yield DialogUtils.run_async (quit_dialog);
 
                // The null check is necessary because the dialog could already
                // be canceled by this point
@@ -706,7 +706,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 = yield run_dialog_async (restart_dialog);
+                       var response = yield DialogUtils.run_async (restart_dialog);
 
                        restart_dialog.destroy ();
                        restart_dialog = null;
@@ -820,20 +820,4 @@ 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;
-       }
 }
diff --git a/src/utils/dialog-utils.vala b/src/utils/dialog-utils.vala
new file mode 100644
index 00000000..85da22fd
--- /dev/null
+++ b/src/utils/dialog-utils.vala
@@ -0,0 +1,35 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+namespace Games.DialogUtils {
+       public async Gtk.ResponseType run_async (Gtk.Dialog dialog) {
+               var response = Gtk.ResponseType.CANCEL;
+
+               dialog.response.connect (r => {
+                       response = (Gtk.ResponseType) r;
+
+                       run_async.callback ();
+               });
+
+               dialog.present ();
+
+               yield;
+
+               return response;
+       }
+
+       public async Gtk.ResponseType run_native_async (Gtk.NativeDialog dialog) {
+               var response = Gtk.ResponseType.CANCEL;
+
+               dialog.response.connect (r => {
+                       response = (Gtk.ResponseType) r;
+
+                       run_native_async.callback ();
+               });
+
+               dialog.show ();
+
+               yield;
+
+               return response;
+       }
+}


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