From e7e83ff1634ec4db5c890c06a95d7710913e0150 Mon Sep 17 00:00:00 2001 From: Antonio De Lucreziis Date: Tue, 5 Mar 2024 02:36:16 +0100 Subject: [PATCH] feat: added filechooser connect_response --- src/main.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9ac687d..2c67c46 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,4 @@ -use gtk::glib::property::PropertyGet; -use gtk::{prelude::*, Align, Box, Button, FileChooserAction, FileChooserDialog, Label, Orientation, ResponseType, Stack, StackSidebar}; +use gtk::{prelude::*, Box, Button, FileChooserAction, FileChooserDialog, Label, Orientation, ResponseType, Stack, StackSidebar}; use gtk::{glib, Application, ApplicationWindow}; const APP_ID: &str = "org.gtk_rs.HelloWorld2"; @@ -52,6 +51,17 @@ fn print_utils(window: &ApplicationWindow) -> Box { // if file_chooser.response(ResponseType::Ok) == ResponseType::Ok { // let filename = file_chooser.filename(); } + file_chooser.connect_response(move |fcd: &FileChooserDialog, response: ResponseType| { + if response == ResponseType::Ok { + let file = fcd.file().expect("Couldn't get file"); + let filename = file.path().expect("Couldn't get file path"); + + println!("Filename: {:?}", filename); + } + + fcd.close(); + }); + file_chooser.show(); }));