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    /// Creates a new [`FileChooserDialog`][crate::FileChooserDialog].
12    ///
13    /// This function is analogous to [`Dialog::with_buttons()`][crate::Dialog::with_buttons()].
14    ///
15    /// # Deprecated since 4.10
16    ///
17    /// Use [`FileDialog`][crate::FileDialog] instead
18    /// ## `title`
19    /// Title of the dialog
20    /// ## `parent`
21    /// Transient parent of the dialog
22    /// ## `action`
23    /// Open or save mode for the dialog
24    /// ## `first_button_text`
25    /// text to go in the first button
26    ///
27    /// # Returns
28    ///
29    /// a new [`FileChooserDialog`][crate::FileChooserDialog]
30    #[doc(alias = "gtk_file_chooser_dialog_new")]
31    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
32    #[allow(deprecated)]
33    pub fn new(
34        title: impl IntoOptionalGStr,
35        parent: Option<&impl IsA<Window>>,
36        action: FileChooserAction,
37        buttons: &[(&str, ResponseType)],
38    ) -> Self {
39        assert_initialized_main_thread!();
40        unsafe {
41            let dialog: Self = title.run_with_gstr(|title| {
42                Widget::from_glib_none(ffi::gtk_file_chooser_dialog_new(
43                    title.to_glib_none().0,
44                    parent.map(|p| p.as_ref()).to_glib_none().0,
45                    action.into_glib(),
46                    ptr::null::<c_char>(),
47                ))
48                .unsafe_cast()
49            });
50            dialog.add_buttons(buttons);
51            dialog
52        }
53    }
54}
55
56impl Default for FileChooserDialog {
57    fn default() -> Self {
58        glib::Object::new()
59    }
60}