gtk4/file_chooser.rs
1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::{ffi, prelude::*, FileChooser};
4use glib::translate::*;
5
6// rustdoc-stripper-ignore-next
7/// Trait containing manually implemented methods of
8/// [`FileChooser`](crate::FileChooser).
9#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
10#[allow(deprecated)]
11pub trait FileChooserExtManual: IsA<FileChooser> + 'static {
12 /// Adds a 'choice' to the file chooser.
13 ///
14 /// This is typically implemented as a combobox or, for boolean choices,
15 /// as a checkbutton. You can select a value using
16 /// [`FileChooserExt::set_choice()`][crate::prelude::FileChooserExt::set_choice()] before the dialog is shown,
17 /// and you can obtain the user-selected value in the
18 /// [`response`][struct@crate::Dialog#response] signal handler using
19 /// [`FileChooserExt::choice()`][crate::prelude::FileChooserExt::choice()].
20 ///
21 /// # Deprecated since 4.10
22 ///
23 /// Use [`FileDialog`][crate::FileDialog] instead
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 #[doc(alias = "gtk_file_chooser_add_choice")]
33 fn add_choice(&self, id: impl IntoGStr, label: impl IntoGStr, options: &[(&str, &str)]) {
34 if options.is_empty() {
35 id.run_with_gstr(|id| {
36 label.run_with_gstr(|label| unsafe {
37 ffi::gtk_file_chooser_add_choice(
38 self.as_ref().to_glib_none().0,
39 id.as_ptr(),
40 label.as_ptr(),
41 mut_override(std::ptr::null()),
42 mut_override(std::ptr::null()),
43 );
44 });
45 });
46 } else {
47 let stashes_ids = options
48 .iter()
49 .map(|o| o.0.to_glib_none())
50 .collect::<Vec<_>>();
51 let stashes_labels = options
52 .iter()
53 .map(|o| o.1.to_glib_none())
54 .collect::<Vec<_>>();
55 let options_ids = stashes_ids
56 .iter()
57 .map(|o| o.0)
58 .chain(std::iter::once(std::ptr::null()))
59 .collect::<Vec<*const libc::c_char>>();
60 let options_labels = stashes_labels
61 .iter()
62 .map(|o| o.0)
63 .chain(std::iter::once(std::ptr::null()))
64 .collect::<Vec<*const libc::c_char>>();
65 id.run_with_gstr(|id| {
66 label.run_with_gstr(|label| unsafe {
67 ffi::gtk_file_chooser_add_choice(
68 self.as_ref().to_glib_none().0,
69 id.as_ptr(),
70 label.as_ptr(),
71 mut_override(options_ids.as_ptr()),
72 mut_override(options_labels.as_ptr()),
73 );
74 });
75 });
76 }
77 }
78
79 /// Sets the current folder for @self from a `GFile`.
80 ///
81 /// # Deprecated since 4.10
82 ///
83 /// Use [`FileDialog`][crate::FileDialog] instead
84 /// ## `file`
85 /// the `GFile` for the new folder
86 ///
87 /// # Returns
88 ///
89 /// [`true`] if the folder could be changed successfully, [`false`]
90 /// otherwise.
91 #[doc(alias = "gtk_file_chooser_set_current_folder")]
92 fn set_current_folder(&self, file: Option<&impl IsA<gio::File>>) -> Result<bool, glib::Error> {
93 unsafe {
94 let mut error = std::ptr::null_mut();
95 let result = from_glib(ffi::gtk_file_chooser_set_current_folder(
96 self.as_ref().to_glib_none().0,
97 file.map(|p| p.as_ref()).to_glib_none().0,
98 &mut error,
99 ));
100 if error.is_null() {
101 Ok(result)
102 } else {
103 Err(from_glib_full(error))
104 }
105 }
106 }
107}
108
109impl<O: IsA<FileChooser>> FileChooserExtManual for O {}