[go: up one dir, main page]

gtk4/
file_chooser_dialog.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::ptr;
4
5use glib::translate::*;
6use libc::c_char;
7
8use crate::{ffi, prelude::*, FileChooserAction, FileChooserDialog, ResponseType, Widget, Window};
9
10impl FileChooserDialog {
11    #[doc(alias = "gtk_file_chooser_dialog_new")]
12    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
13    #[allow(deprecated)]
14    pub fn new(
15        title: impl IntoOptionalGStr,
16        parent: Option<&impl IsA<Window>>,
17        action: FileChooserAction,
18        buttons: &[(&str, ResponseType)],
19    ) -> Self {
20        assert_initialized_main_thread!();
21        unsafe {
22            let dialog: Self = title.run_with_gstr(|title| {
23                Widget::from_glib_none(ffi::gtk_file_chooser_dialog_new(
24                    title.to_glib_none().0,
25                    parent.map(|p| p.as_ref()).to_glib_none().0,
26                    action.into_glib(),
27                    ptr::null::<c_char>(),
28                ))
29                .unsafe_cast()
30            });
31            dialog.add_buttons(buttons);
32            dialog
33        }
34    }
35}
36
37impl Default for FileChooserDialog {
38    fn default() -> Self {
39        glib::Object::new()
40    }
41}