gtk4/auto/
file_chooser_native.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4#![allow(deprecated)]
5
6use crate::{ffi, FileChooser, FileChooserAction, FileFilter, NativeDialog, Window};
7use glib::{
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    #[doc(alias = "GtkFileChooserNative")]
16    pub struct FileChooserNative(Object<ffi::GtkFileChooserNative, ffi::GtkFileChooserNativeClass>) @extends NativeDialog, @implements FileChooser;
17
18    match fn {
19        type_ => || ffi::gtk_file_chooser_native_get_type(),
20    }
21}
22
23impl FileChooserNative {
24    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
25    #[allow(deprecated)]
26    #[doc(alias = "gtk_file_chooser_native_new")]
27    pub fn new(
28        title: Option<&str>,
29        parent: Option<&impl IsA<Window>>,
30        action: FileChooserAction,
31        accept_label: Option<&str>,
32        cancel_label: Option<&str>,
33    ) -> FileChooserNative {
34        assert_initialized_main_thread!();
35        unsafe {
36            from_glib_full(ffi::gtk_file_chooser_native_new(
37                title.to_glib_none().0,
38                parent.map(|p| p.as_ref()).to_glib_none().0,
39                action.into_glib(),
40                accept_label.to_glib_none().0,
41                cancel_label.to_glib_none().0,
42            ))
43        }
44    }
45
46    // rustdoc-stripper-ignore-next
47    /// Creates a new builder-pattern struct instance to construct [`FileChooserNative`] objects.
48    ///
49    /// This method returns an instance of [`FileChooserNativeBuilder`](crate::builders::FileChooserNativeBuilder) which can be used to create [`FileChooserNative`] objects.
50    pub fn builder() -> FileChooserNativeBuilder {
51        FileChooserNativeBuilder::new()
52    }
53
54    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
55    #[allow(deprecated)]
56    #[doc(alias = "gtk_file_chooser_native_get_accept_label")]
57    #[doc(alias = "get_accept_label")]
58    #[doc(alias = "accept-label")]
59    pub fn accept_label(&self) -> Option<glib::GString> {
60        unsafe {
61            from_glib_none(ffi::gtk_file_chooser_native_get_accept_label(
62                self.to_glib_none().0,
63            ))
64        }
65    }
66
67    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
68    #[allow(deprecated)]
69    #[doc(alias = "gtk_file_chooser_native_get_cancel_label")]
70    #[doc(alias = "get_cancel_label")]
71    #[doc(alias = "cancel-label")]
72    pub fn cancel_label(&self) -> Option<glib::GString> {
73        unsafe {
74            from_glib_none(ffi::gtk_file_chooser_native_get_cancel_label(
75                self.to_glib_none().0,
76            ))
77        }
78    }
79
80    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
81    #[allow(deprecated)]
82    #[doc(alias = "gtk_file_chooser_native_set_accept_label")]
83    #[doc(alias = "accept-label")]
84    pub fn set_accept_label(&self, accept_label: Option<&str>) {
85        unsafe {
86            ffi::gtk_file_chooser_native_set_accept_label(
87                self.to_glib_none().0,
88                accept_label.to_glib_none().0,
89            );
90        }
91    }
92
93    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
94    #[allow(deprecated)]
95    #[doc(alias = "gtk_file_chooser_native_set_cancel_label")]
96    #[doc(alias = "cancel-label")]
97    pub fn set_cancel_label(&self, cancel_label: Option<&str>) {
98        unsafe {
99            ffi::gtk_file_chooser_native_set_cancel_label(
100                self.to_glib_none().0,
101                cancel_label.to_glib_none().0,
102            );
103        }
104    }
105
106    #[doc(alias = "accept-label")]
107    pub fn connect_accept_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
108        unsafe extern "C" fn notify_accept_label_trampoline<F: Fn(&FileChooserNative) + 'static>(
109            this: *mut ffi::GtkFileChooserNative,
110            _param_spec: glib::ffi::gpointer,
111            f: glib::ffi::gpointer,
112        ) {
113            let f: &F = &*(f as *const F);
114            f(&from_glib_borrow(this))
115        }
116        unsafe {
117            let f: Box_<F> = Box_::new(f);
118            connect_raw(
119                self.as_ptr() as *mut _,
120                c"notify::accept-label".as_ptr() as *const _,
121                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
122                    notify_accept_label_trampoline::<F> as *const (),
123                )),
124                Box_::into_raw(f),
125            )
126        }
127    }
128
129    #[doc(alias = "cancel-label")]
130    pub fn connect_cancel_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
131        unsafe extern "C" fn notify_cancel_label_trampoline<F: Fn(&FileChooserNative) + 'static>(
132            this: *mut ffi::GtkFileChooserNative,
133            _param_spec: glib::ffi::gpointer,
134            f: glib::ffi::gpointer,
135        ) {
136            let f: &F = &*(f as *const F);
137            f(&from_glib_borrow(this))
138        }
139        unsafe {
140            let f: Box_<F> = Box_::new(f);
141            connect_raw(
142                self.as_ptr() as *mut _,
143                c"notify::cancel-label".as_ptr() as *const _,
144                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
145                    notify_cancel_label_trampoline::<F> as *const (),
146                )),
147                Box_::into_raw(f),
148            )
149        }
150    }
151}
152
153impl Default for FileChooserNative {
154    fn default() -> Self {
155        glib::object::Object::new::<Self>()
156    }
157}
158
159// rustdoc-stripper-ignore-next
160/// A [builder-pattern] type to construct [`FileChooserNative`] objects.
161///
162/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
163#[must_use = "The builder must be built to be used"]
164pub struct FileChooserNativeBuilder {
165    builder: glib::object::ObjectBuilder<'static, FileChooserNative>,
166}
167
168impl FileChooserNativeBuilder {
169    fn new() -> Self {
170        Self {
171            builder: glib::object::Object::builder(),
172        }
173    }
174
175    pub fn accept_label(self, accept_label: impl Into<glib::GString>) -> Self {
176        Self {
177            builder: self.builder.property("accept-label", accept_label.into()),
178        }
179    }
180
181    pub fn cancel_label(self, cancel_label: impl Into<glib::GString>) -> Self {
182        Self {
183            builder: self.builder.property("cancel-label", cancel_label.into()),
184        }
185    }
186
187    pub fn modal(self, modal: bool) -> Self {
188        Self {
189            builder: self.builder.property("modal", modal),
190        }
191    }
192
193    pub fn title(self, title: impl Into<glib::GString>) -> Self {
194        Self {
195            builder: self.builder.property("title", title.into()),
196        }
197    }
198
199    pub fn transient_for(self, transient_for: &impl IsA<Window>) -> Self {
200        Self {
201            builder: self
202                .builder
203                .property("transient-for", transient_for.clone().upcast()),
204        }
205    }
206
207    pub fn visible(self, visible: bool) -> Self {
208        Self {
209            builder: self.builder.property("visible", visible),
210        }
211    }
212
213    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
214    pub fn action(self, action: FileChooserAction) -> Self {
215        Self {
216            builder: self.builder.property("action", action),
217        }
218    }
219
220    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
221    pub fn create_folders(self, create_folders: bool) -> Self {
222        Self {
223            builder: self.builder.property("create-folders", create_folders),
224        }
225    }
226
227    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
228    pub fn filter(self, filter: &FileFilter) -> Self {
229        Self {
230            builder: self.builder.property("filter", filter.clone()),
231        }
232    }
233
234    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
235    pub fn select_multiple(self, select_multiple: bool) -> Self {
236        Self {
237            builder: self.builder.property("select-multiple", select_multiple),
238        }
239    }
240
241    // rustdoc-stripper-ignore-next
242    /// Build the [`FileChooserNative`].
243    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
244    pub fn build(self) -> FileChooserNative {
245        assert_initialized_main_thread!();
246        self.builder.build()
247    }
248}