Skip to main content

gtk/
file_chooser.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::FileChooser;
4use glib::object::IsA;
5#[cfg(feature = "v3_22")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v3_22")))]
7use glib::translate::*;
8
9// rustdoc-stripper-ignore-next
10/// Trait containing manually implemented methods of [`FileChooser`](crate::FileChooser).
11mod sealed {
12    pub trait Sealed {}
13    impl<T: glib::object::IsA<crate::FileChooser>> Sealed for T {}
14}
15
16pub trait FileChooserExtManual: IsA<FileChooser> + sealed::Sealed + 'static {
17    /// Adds a 'choice' to the file chooser. This is typically implemented
18    /// as a combobox or, for boolean choices, as a checkbutton. You can select
19    /// a value using [`FileChooserExt::set_choice()`][crate::prelude::FileChooserExt::set_choice()] before the dialog is shown,
20    /// and you can obtain the user-selected value in the ::response signal handler
21    /// using [`FileChooserExt::choice()`][crate::prelude::FileChooserExt::choice()].
22    ///
23    /// Compare [`FileChooserExt::set_extra_widget()`][crate::prelude::FileChooserExt::set_extra_widget()].
24    /// ## `id`
25    /// id for the added choice
26    /// ## `label`
27    /// user-visible label for the added choice
28    /// ## `options`
29    /// ids for the options of the choice, or [`None`] for a boolean choice
30    /// ## `option_labels`
31    /// user-visible labels for the options, must be the same length as `options`
32    #[cfg(feature = "v3_22")]
33    #[cfg_attr(docsrs, doc(cfg(feature = "v3_22")))]
34    #[doc(alias = "gtk_file_chooser_add_choice")]
35    fn add_choice(&self, id: &str, label: &str, options: &[(&str, &str)]) {
36        unsafe {
37            let stashes_ids = options
38                .iter()
39                .map(|o| o.0.to_glib_none())
40                .collect::<Vec<_>>();
41            let stashes_labels = options
42                .iter()
43                .map(|o| o.1.to_glib_none())
44                .collect::<Vec<_>>();
45            let (options_ids, options_labels) = (
46                stashes_ids
47                    .iter()
48                    .map(|o| o.0)
49                    .collect::<Vec<*const libc::c_char>>(),
50                stashes_labels
51                    .iter()
52                    .map(|o| o.0)
53                    .collect::<Vec<*const libc::c_char>>(),
54            );
55
56            crate::ffi::gtk_file_chooser_add_choice(
57                self.as_ref().to_glib_none().0,
58                id.to_glib_none().0,
59                label.to_glib_none().0,
60                mut_override(options_ids.as_ptr()),
61                mut_override(options_labels.as_ptr()),
62            );
63        }
64    }
65}
66
67impl<O: IsA<FileChooser>> FileChooserExtManual for O {}