[gnome-games/wip/exalm/dialogs: 3/3] preferences-page-import-export: Stop using dialog.run()




commit aaa4c64aefbd6c9d2b94c34351694647a068c575
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Wed Mar 24 22:59:07 2021 +0500

    preferences-page-import-export: Stop using dialog.run()

 .../preferences-page-import-export.vala            | 42 +++++++++++++++-------
 1 file changed, 30 insertions(+), 12 deletions(-)
---
diff --git a/src/preferences/preferences-page-import-export.vala 
b/src/preferences/preferences-page-import-export.vala
index f3940ef3..19c64d9a 100644
--- a/src/preferences/preferences-page-import-export.vala
+++ b/src/preferences/preferences-page-import-export.vala
@@ -4,12 +4,26 @@
 private class Games.PreferencesPageImportExport : PreferencesPage {
        [GtkCallback]
        private void on_import_clicked () {
-               var toplevel = get_toplevel () as Gtk.Window;
-               var chooser = new Gtk.FileChooserNative (_("Import save data"), toplevel,
-                                                        Gtk.FileChooserAction.OPEN,
-                                                        _("_Import"), _("_Cancel"));
+               import_saves_async.begin ();
+       }
+
+       [GtkCallback]
+       private void on_export_clicked () {
+               export_saves_async.begin ();
+       }
 
-               if (chooser.run () == Gtk.ResponseType.ACCEPT) {
+       private async void import_saves_async () {
+               var chooser = new Gtk.FileChooserNative (
+                       _("Import save data"),
+                       window,
+                       Gtk.FileChooserAction.OPEN,
+                       _("_Import"),
+                       _("_Cancel")
+               );
+
+               var response = yield DialogUtils.run_native_async (chooser);
+
+               if (response == Gtk.ResponseType.ACCEPT) {
                        var archive_name = chooser.get_filename ();
 
                        try {
@@ -24,12 +38,14 @@ private class Games.PreferencesPageImportExport : PreferencesPage {
                chooser.destroy ();
        }
 
-       [GtkCallback]
-       private void on_export_clicked () {
-               var toplevel = get_toplevel () as Gtk.Window;
-               var chooser = new Gtk.FileChooserNative (_("Export save data"), toplevel,
-                                                       Gtk.FileChooserAction.SAVE,
-                                                       _("_Export"), _("_Cancel"));
+       private async void export_saves_async () {
+               var chooser = new Gtk.FileChooserNative (
+                       _("Export save data"),
+                       window,
+                       Gtk.FileChooserAction.SAVE,
+                       _("_Export"),
+                       _("_Cancel")
+               );
 
                chooser.do_overwrite_confirmation = true;
 
@@ -39,7 +55,9 @@ private class Games.PreferencesPageImportExport : PreferencesPage {
 
                chooser.set_current_name (archive_filename);
 
-               if (chooser.run () == Gtk.ResponseType.ACCEPT) {
+               var response = yield DialogUtils.run_native_async (chooser);
+
+               if (response == Gtk.ResponseType.ACCEPT) {
                        var filename = chooser.get_filename ();
 
                        try {


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