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