[fractal/wip/cdavis/use-filechoosernative] event_actions: Use GtkFileChooserNative for saving




commit fc82931751b5adbcacace6928f7569057a2ebdf8
Author: Christopher Davis <christopherdavis gnome org>
Date:   Tue Aug 2 20:47:03 2022 -0400

    event_actions: Use GtkFileChooserNative for saving
    
    Fractal does not have a full view of the filesystem, which
    means that we can't use GtkFileChooserDialog if we want users
    to be able to save anywhere. Instead, we need to use the
    file chooser portal via GtkFileChooserNative.
    
    Closes https://gitlab.gnome.org/GNOME/fractal/-/issues/1064

 src/session/room/event_actions.rs | 37 +++++++++++++++++++------------------
 1 file changed, 19 insertions(+), 18 deletions(-)
---
diff --git a/src/session/room/event_actions.rs b/src/session/room/event_actions.rs
index 5fc36d51e..0f09d338b 100644
--- a/src/session/room/event_actions.rs
+++ b/src/session/room/event_actions.rs
@@ -228,32 +228,33 @@ where
                     }
                 };
 
-                let dialog = gtk::FileChooserDialog::new(
+                let dialog = gtk::FileChooserNative::new(
                     Some(&gettext("Save File")),
                     Some(&window),
                     gtk::FileChooserAction::Save,
-                    &[
-                        (&gettext("Save"), gtk::ResponseType::Accept),
-                        (&gettext("Cancel"), gtk::ResponseType::Cancel),
-                    ],
+                    Some(&gettext("Save")),
+                    Some(&gettext("Cancel")),
                 );
                 dialog.set_current_name(&filename);
 
-                let response = dialog.run_future().await;
-                if response == gtk::ResponseType::Accept {
-                    if let Some(file) = dialog.file() {
-                        file.replace_contents(
-                            &data,
-                            None,
-                            false,
-                            gio::FileCreateFlags::REPLACE_DESTINATION,
-                            gio::Cancellable::NONE,
-                        )
-                        .unwrap();
+                dialog.connect_response(clone!(@strong dialog => move |_, response| {
+                    if response == gtk::ResponseType::Accept {
+                        if let Some(file) = dialog.file() {
+                            file.replace_contents(
+                                &data,
+                                None,
+                                false,
+                                gio::FileCreateFlags::REPLACE_DESTINATION,
+                                gio::Cancellable::NONE,
+                            )
+                            .unwrap();
+                        }
                     }
-                }
 
-                dialog.close();
+                    dialog.destroy();
+                }));
+
+                dialog.show();
             })
         );
     }


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