1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::FileChooser;
use glib::translate::*;
use glib::IsA;

// rustdoc-stripper-ignore-next
/// Trait containing manually implemented methods of [`FileChooser`](crate::FileChooser).
#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
pub trait FileChooserExtManual: 'static {
    /// Adds a 'choice' to the file chooser.
    ///
    /// This is typically implemented as a combobox or, for boolean choices,
    /// as a checkbutton. You can select a value using
    /// [`FileChooserExt::set_choice()`][crate::prelude::FileChooserExt::set_choice()] before the dialog is shown,
    /// and you can obtain the user-selected value in the
    /// `signal::Dialog::response` signal handler using
    /// [`FileChooserExt::choice()`][crate::prelude::FileChooserExt::choice()].
    ///
    /// # Deprecated since 4.10
    ///
    /// Use [`FileDialog`][crate::FileDialog] instead
    /// ## `id`
    /// id for the added choice
    /// ## `label`
    /// user-visible label for the added choice
    /// ## `options`
    /// ids for the options of the choice, or [`None`] for a boolean choice
    /// ## `option_labels`
    /// user-visible labels for the options, must be the same length as @options
    #[doc(alias = "gtk_file_chooser_add_choice")]
    fn add_choice(&self, id: &str, label: &str, options: &[(&str, &str)]);

    /// Sets the current folder for @self from a `GFile`.
    ///
    /// # Deprecated since 4.10
    ///
    /// Use [`FileDialog`][crate::FileDialog] instead
    /// ## `file`
    /// the `GFile` for the new folder
    ///
    /// # Returns
    ///
    /// [`true`] if the folder could be changed successfully, [`false`]
    ///   otherwise.
    #[doc(alias = "gtk_file_chooser_set_current_folder")]
    fn set_current_folder(&self, file: Option<&impl IsA<gio::File>>) -> Result<bool, glib::Error>;
}

impl<O: IsA<FileChooser>> FileChooserExtManual for O {
    fn add_choice(&self, id: &str, label: &str, options: &[(&str, &str)]) {
        unsafe {
            let stashes_ids = options
                .iter()
                .map(|o| o.0.to_glib_none())
                .collect::<Vec<_>>();
            let stashes_labels = options
                .iter()
                .map(|o| o.1.to_glib_none())
                .collect::<Vec<_>>();
            let (options_ids, options_labels) = (
                stashes_ids
                    .iter()
                    .map(|o| o.0)
                    .collect::<Vec<*const libc::c_char>>()
                    .as_ptr(),
                stashes_labels
                    .iter()
                    .map(|o| o.0)
                    .collect::<Vec<*const libc::c_char>>()
                    .as_ptr(),
            );

            ffi::gtk_file_chooser_add_choice(
                self.as_ref().to_glib_none().0,
                id.to_glib_none().0,
                label.to_glib_none().0,
                mut_override(options_ids),
                mut_override(options_labels),
            );
        }
    }

    fn set_current_folder(&self, file: Option<&impl IsA<gio::File>>) -> Result<bool, glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let result = from_glib(ffi::gtk_file_chooser_set_current_folder(
                self.as_ref().to_glib_none().0,
                file.map(|p| p.as_ref()).to_glib_none().0,
                &mut error,
            ));
            if error.is_null() {
                Ok(result)
            } else {
                Err(from_glib_full(error))
            }
        }
    }
}