1use crate::{ffi, prelude::*, FileChooser};
4use glib::translate::*;
5
6#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
10#[allow(deprecated)]
11pub trait FileChooserExtManual: IsA<FileChooser> + 'static {
12 #[doc(alias = "gtk_file_chooser_add_choice")]
13 fn add_choice(&self, id: impl IntoGStr, label: impl IntoGStr, options: &[(&str, &str)]) {
14 if options.is_empty() {
15 id.run_with_gstr(|id| {
16 label.run_with_gstr(|label| unsafe {
17 ffi::gtk_file_chooser_add_choice(
18 self.as_ref().to_glib_none().0,
19 id.as_ptr(),
20 label.as_ptr(),
21 mut_override(std::ptr::null()),
22 mut_override(std::ptr::null()),
23 );
24 });
25 });
26 } else {
27 let stashes_ids = options
28 .iter()
29 .map(|o| o.0.to_glib_none())
30 .collect::<Vec<_>>();
31 let stashes_labels = options
32 .iter()
33 .map(|o| o.1.to_glib_none())
34 .collect::<Vec<_>>();
35 let options_ids = stashes_ids
36 .iter()
37 .map(|o| o.0)
38 .chain(std::iter::once(std::ptr::null()))
39 .collect::<Vec<*const libc::c_char>>();
40 let options_labels = stashes_labels
41 .iter()
42 .map(|o| o.0)
43 .chain(std::iter::once(std::ptr::null()))
44 .collect::<Vec<*const libc::c_char>>();
45 id.run_with_gstr(|id| {
46 label.run_with_gstr(|label| unsafe {
47 ffi::gtk_file_chooser_add_choice(
48 self.as_ref().to_glib_none().0,
49 id.as_ptr(),
50 label.as_ptr(),
51 mut_override(options_ids.as_ptr()),
52 mut_override(options_labels.as_ptr()),
53 );
54 });
55 });
56 }
57 }
58
59 #[doc(alias = "gtk_file_chooser_set_current_folder")]
60 fn set_current_folder(&self, file: Option<&impl IsA<gio::File>>) -> Result<bool, glib::Error> {
61 unsafe {
62 let mut error = std::ptr::null_mut();
63 let result = from_glib(ffi::gtk_file_chooser_set_current_folder(
64 self.as_ref().to_glib_none().0,
65 file.map(|p| p.as_ref()).to_glib_none().0,
66 &mut error,
67 ));
68 if error.is_null() {
69 Ok(result)
70 } else {
71 Err(from_glib_full(error))
72 }
73 }
74 }
75}
76
77impl<O: IsA<FileChooser>> FileChooserExtManual for O {}