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 5 use crate::FileChooser; 6 use crate::FileChooserAction; 7 use crate::FileFilter; 8 use crate::NativeDialog; 9 use crate::Widget; 10 use crate::Window; 11 use glib::object::Cast; 12 use glib::object::IsA; 13 use glib::object::ObjectType as ObjectType_; 14 use glib::signal::connect_raw; 15 use glib::signal::SignalHandlerId; 16 use glib::translate::*; 17 use glib::StaticType; 18 use glib::ToValue; 19 use std::boxed::Box as Box_; 20 use std::fmt; 21 use std::mem::transmute; 22 23 glib::wrapper! { 24 #[doc(alias = "GtkFileChooserNative")] 25 pub struct FileChooserNative(Object<ffi::GtkFileChooserNative, ffi::GtkFileChooserNativeClass>) @extends NativeDialog, @implements FileChooser; 26 27 match fn { 28 type_ => || ffi::gtk_file_chooser_native_get_type(), 29 } 30 } 31 32 impl FileChooserNative { 33 #[doc(alias = "gtk_file_chooser_native_new")] new<P: IsA<Window>>( title: Option<&str>, parent: Option<&P>, action: FileChooserAction, accept_label: Option<&str>, cancel_label: Option<&str>, ) -> FileChooserNative34 pub fn new<P: IsA<Window>>( 35 title: Option<&str>, 36 parent: Option<&P>, 37 action: FileChooserAction, 38 accept_label: Option<&str>, 39 cancel_label: Option<&str>, 40 ) -> FileChooserNative { 41 assert_initialized_main_thread!(); 42 unsafe { 43 from_glib_full(ffi::gtk_file_chooser_native_new( 44 title.to_glib_none().0, 45 parent.map(|p| p.as_ref()).to_glib_none().0, 46 action.into_glib(), 47 accept_label.to_glib_none().0, 48 cancel_label.to_glib_none().0, 49 )) 50 } 51 } 52 53 // rustdoc-stripper-ignore-next 54 /// Creates a new builder-pattern struct instance to construct [`FileChooserNative`] objects. 55 /// 56 /// This method returns an instance of [`FileChooserNativeBuilder`] which can be used to create [`FileChooserNative`] objects. builder() -> FileChooserNativeBuilder57 pub fn builder() -> FileChooserNativeBuilder { 58 FileChooserNativeBuilder::default() 59 } 60 61 #[doc(alias = "gtk_file_chooser_native_get_accept_label")] 62 #[doc(alias = "get_accept_label")] accept_label(&self) -> Option<glib::GString>63 pub fn accept_label(&self) -> Option<glib::GString> { 64 unsafe { 65 from_glib_none(ffi::gtk_file_chooser_native_get_accept_label( 66 self.to_glib_none().0, 67 )) 68 } 69 } 70 71 #[doc(alias = "gtk_file_chooser_native_get_cancel_label")] 72 #[doc(alias = "get_cancel_label")] cancel_label(&self) -> Option<glib::GString>73 pub fn cancel_label(&self) -> Option<glib::GString> { 74 unsafe { 75 from_glib_none(ffi::gtk_file_chooser_native_get_cancel_label( 76 self.to_glib_none().0, 77 )) 78 } 79 } 80 81 #[doc(alias = "gtk_file_chooser_native_set_accept_label")] set_accept_label(&self, accept_label: Option<&str>)82 pub fn set_accept_label(&self, accept_label: Option<&str>) { 83 unsafe { 84 ffi::gtk_file_chooser_native_set_accept_label( 85 self.to_glib_none().0, 86 accept_label.to_glib_none().0, 87 ); 88 } 89 } 90 91 #[doc(alias = "gtk_file_chooser_native_set_cancel_label")] set_cancel_label(&self, cancel_label: Option<&str>)92 pub fn set_cancel_label(&self, cancel_label: Option<&str>) { 93 unsafe { 94 ffi::gtk_file_chooser_native_set_cancel_label( 95 self.to_glib_none().0, 96 cancel_label.to_glib_none().0, 97 ); 98 } 99 } 100 101 #[doc(alias = "accept-label")] get_property_accept_label(&self) -> Option<glib::GString>102 pub fn get_property_accept_label(&self) -> Option<glib::GString> { 103 unsafe { 104 let mut value = glib::Value::from_type(<glib::GString as StaticType>::static_type()); 105 glib::gobject_ffi::g_object_get_property( 106 self.as_ptr() as *mut glib::gobject_ffi::GObject, 107 b"accept-label\0".as_ptr() as *const _, 108 value.to_glib_none_mut().0, 109 ); 110 value 111 .get() 112 .expect("Return Value for property `accept-label` getter") 113 } 114 } 115 116 #[doc(alias = "accept-label")] set_property_accept_label(&self, accept_label: Option<&str>)117 pub fn set_property_accept_label(&self, accept_label: Option<&str>) { 118 unsafe { 119 glib::gobject_ffi::g_object_set_property( 120 self.as_ptr() as *mut glib::gobject_ffi::GObject, 121 b"accept-label\0".as_ptr() as *const _, 122 accept_label.to_value().to_glib_none().0, 123 ); 124 } 125 } 126 127 #[doc(alias = "cancel-label")] get_property_cancel_label(&self) -> Option<glib::GString>128 pub fn get_property_cancel_label(&self) -> Option<glib::GString> { 129 unsafe { 130 let mut value = glib::Value::from_type(<glib::GString as StaticType>::static_type()); 131 glib::gobject_ffi::g_object_get_property( 132 self.as_ptr() as *mut glib::gobject_ffi::GObject, 133 b"cancel-label\0".as_ptr() as *const _, 134 value.to_glib_none_mut().0, 135 ); 136 value 137 .get() 138 .expect("Return Value for property `cancel-label` getter") 139 } 140 } 141 142 #[doc(alias = "cancel-label")] set_property_cancel_label(&self, cancel_label: Option<&str>)143 pub fn set_property_cancel_label(&self, cancel_label: Option<&str>) { 144 unsafe { 145 glib::gobject_ffi::g_object_set_property( 146 self.as_ptr() as *mut glib::gobject_ffi::GObject, 147 b"cancel-label\0".as_ptr() as *const _, 148 cancel_label.to_value().to_glib_none().0, 149 ); 150 } 151 } 152 153 #[doc(alias = "accept-label")] connect_accept_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId154 pub fn connect_accept_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 155 unsafe extern "C" fn notify_accept_label_trampoline<F: Fn(&FileChooserNative) + 'static>( 156 this: *mut ffi::GtkFileChooserNative, 157 _param_spec: glib::ffi::gpointer, 158 f: glib::ffi::gpointer, 159 ) { 160 let f: &F = &*(f as *const F); 161 f(&from_glib_borrow(this)) 162 } 163 unsafe { 164 let f: Box_<F> = Box_::new(f); 165 connect_raw( 166 self.as_ptr() as *mut _, 167 b"notify::accept-label\0".as_ptr() as *const _, 168 Some(transmute::<_, unsafe extern "C" fn()>( 169 notify_accept_label_trampoline::<F> as *const (), 170 )), 171 Box_::into_raw(f), 172 ) 173 } 174 } 175 176 #[doc(alias = "cancel-label")] connect_cancel_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId177 pub fn connect_cancel_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 178 unsafe extern "C" fn notify_cancel_label_trampoline<F: Fn(&FileChooserNative) + 'static>( 179 this: *mut ffi::GtkFileChooserNative, 180 _param_spec: glib::ffi::gpointer, 181 f: glib::ffi::gpointer, 182 ) { 183 let f: &F = &*(f as *const F); 184 f(&from_glib_borrow(this)) 185 } 186 unsafe { 187 let f: Box_<F> = Box_::new(f); 188 connect_raw( 189 self.as_ptr() as *mut _, 190 b"notify::cancel-label\0".as_ptr() as *const _, 191 Some(transmute::<_, unsafe extern "C" fn()>( 192 notify_cancel_label_trampoline::<F> as *const (), 193 )), 194 Box_::into_raw(f), 195 ) 196 } 197 } 198 } 199 200 #[derive(Clone, Default)] 201 // rustdoc-stripper-ignore-next 202 /// A [builder-pattern] type to construct [`FileChooserNative`] objects. 203 /// 204 /// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html 205 pub struct FileChooserNativeBuilder { 206 accept_label: Option<String>, 207 cancel_label: Option<String>, 208 #[cfg(any(feature = "v3_20", feature = "dox"))] 209 #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_20")))] 210 modal: Option<bool>, 211 #[cfg(any(feature = "v3_20", feature = "dox"))] 212 #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_20")))] 213 title: Option<String>, 214 #[cfg(any(feature = "v3_20", feature = "dox"))] 215 #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_20")))] 216 transient_for: Option<Window>, 217 #[cfg(any(feature = "v3_20", feature = "dox"))] 218 #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_20")))] 219 visible: Option<bool>, 220 action: Option<FileChooserAction>, 221 create_folders: Option<bool>, 222 do_overwrite_confirmation: Option<bool>, 223 extra_widget: Option<Widget>, 224 filter: Option<FileFilter>, 225 local_only: Option<bool>, 226 preview_widget: Option<Widget>, 227 preview_widget_active: Option<bool>, 228 select_multiple: Option<bool>, 229 show_hidden: Option<bool>, 230 use_preview_label: Option<bool>, 231 } 232 233 impl FileChooserNativeBuilder { 234 // rustdoc-stripper-ignore-next 235 /// Create a new [`FileChooserNativeBuilder`]. new() -> Self236 pub fn new() -> Self { 237 Self::default() 238 } 239 240 // rustdoc-stripper-ignore-next 241 /// Build the [`FileChooserNative`]. build(self) -> FileChooserNative242 pub fn build(self) -> FileChooserNative { 243 let mut properties: Vec<(&str, &dyn ToValue)> = vec![]; 244 if let Some(ref accept_label) = self.accept_label { 245 properties.push(("accept-label", accept_label)); 246 } 247 if let Some(ref cancel_label) = self.cancel_label { 248 properties.push(("cancel-label", cancel_label)); 249 } 250 #[cfg(any(feature = "v3_20", feature = "dox"))] 251 if let Some(ref modal) = self.modal { 252 properties.push(("modal", modal)); 253 } 254 #[cfg(any(feature = "v3_20", feature = "dox"))] 255 if let Some(ref title) = self.title { 256 properties.push(("title", title)); 257 } 258 #[cfg(any(feature = "v3_20", feature = "dox"))] 259 if let Some(ref transient_for) = self.transient_for { 260 properties.push(("transient-for", transient_for)); 261 } 262 #[cfg(any(feature = "v3_20", feature = "dox"))] 263 if let Some(ref visible) = self.visible { 264 properties.push(("visible", visible)); 265 } 266 if let Some(ref action) = self.action { 267 properties.push(("action", action)); 268 } 269 if let Some(ref create_folders) = self.create_folders { 270 properties.push(("create-folders", create_folders)); 271 } 272 if let Some(ref do_overwrite_confirmation) = self.do_overwrite_confirmation { 273 properties.push(("do-overwrite-confirmation", do_overwrite_confirmation)); 274 } 275 if let Some(ref extra_widget) = self.extra_widget { 276 properties.push(("extra-widget", extra_widget)); 277 } 278 if let Some(ref filter) = self.filter { 279 properties.push(("filter", filter)); 280 } 281 if let Some(ref local_only) = self.local_only { 282 properties.push(("local-only", local_only)); 283 } 284 if let Some(ref preview_widget) = self.preview_widget { 285 properties.push(("preview-widget", preview_widget)); 286 } 287 if let Some(ref preview_widget_active) = self.preview_widget_active { 288 properties.push(("preview-widget-active", preview_widget_active)); 289 } 290 if let Some(ref select_multiple) = self.select_multiple { 291 properties.push(("select-multiple", select_multiple)); 292 } 293 if let Some(ref show_hidden) = self.show_hidden { 294 properties.push(("show-hidden", show_hidden)); 295 } 296 if let Some(ref use_preview_label) = self.use_preview_label { 297 properties.push(("use-preview-label", use_preview_label)); 298 } 299 glib::Object::new::<FileChooserNative>(&properties) 300 .expect("Failed to create an instance of FileChooserNative") 301 } 302 accept_label(mut self, accept_label: &str) -> Self303 pub fn accept_label(mut self, accept_label: &str) -> Self { 304 self.accept_label = Some(accept_label.to_string()); 305 self 306 } 307 cancel_label(mut self, cancel_label: &str) -> Self308 pub fn cancel_label(mut self, cancel_label: &str) -> Self { 309 self.cancel_label = Some(cancel_label.to_string()); 310 self 311 } 312 313 #[cfg(any(feature = "v3_20", feature = "dox"))] 314 #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_20")))] modal(mut self, modal: bool) -> Self315 pub fn modal(mut self, modal: bool) -> Self { 316 self.modal = Some(modal); 317 self 318 } 319 320 #[cfg(any(feature = "v3_20", feature = "dox"))] 321 #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_20")))] title(mut self, title: &str) -> Self322 pub fn title(mut self, title: &str) -> Self { 323 self.title = Some(title.to_string()); 324 self 325 } 326 327 #[cfg(any(feature = "v3_20", feature = "dox"))] 328 #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_20")))] transient_for<P: IsA<Window>>(mut self, transient_for: &P) -> Self329 pub fn transient_for<P: IsA<Window>>(mut self, transient_for: &P) -> Self { 330 self.transient_for = Some(transient_for.clone().upcast()); 331 self 332 } 333 334 #[cfg(any(feature = "v3_20", feature = "dox"))] 335 #[cfg_attr(feature = "dox", doc(cfg(feature = "v3_20")))] visible(mut self, visible: bool) -> Self336 pub fn visible(mut self, visible: bool) -> Self { 337 self.visible = Some(visible); 338 self 339 } 340 action(mut self, action: FileChooserAction) -> Self341 pub fn action(mut self, action: FileChooserAction) -> Self { 342 self.action = Some(action); 343 self 344 } 345 create_folders(mut self, create_folders: bool) -> Self346 pub fn create_folders(mut self, create_folders: bool) -> Self { 347 self.create_folders = Some(create_folders); 348 self 349 } 350 do_overwrite_confirmation(mut self, do_overwrite_confirmation: bool) -> Self351 pub fn do_overwrite_confirmation(mut self, do_overwrite_confirmation: bool) -> Self { 352 self.do_overwrite_confirmation = Some(do_overwrite_confirmation); 353 self 354 } 355 extra_widget<P: IsA<Widget>>(mut self, extra_widget: &P) -> Self356 pub fn extra_widget<P: IsA<Widget>>(mut self, extra_widget: &P) -> Self { 357 self.extra_widget = Some(extra_widget.clone().upcast()); 358 self 359 } 360 filter(mut self, filter: &FileFilter) -> Self361 pub fn filter(mut self, filter: &FileFilter) -> Self { 362 self.filter = Some(filter.clone()); 363 self 364 } 365 local_only(mut self, local_only: bool) -> Self366 pub fn local_only(mut self, local_only: bool) -> Self { 367 self.local_only = Some(local_only); 368 self 369 } 370 preview_widget<P: IsA<Widget>>(mut self, preview_widget: &P) -> Self371 pub fn preview_widget<P: IsA<Widget>>(mut self, preview_widget: &P) -> Self { 372 self.preview_widget = Some(preview_widget.clone().upcast()); 373 self 374 } 375 preview_widget_active(mut self, preview_widget_active: bool) -> Self376 pub fn preview_widget_active(mut self, preview_widget_active: bool) -> Self { 377 self.preview_widget_active = Some(preview_widget_active); 378 self 379 } 380 select_multiple(mut self, select_multiple: bool) -> Self381 pub fn select_multiple(mut self, select_multiple: bool) -> Self { 382 self.select_multiple = Some(select_multiple); 383 self 384 } 385 show_hidden(mut self, show_hidden: bool) -> Self386 pub fn show_hidden(mut self, show_hidden: bool) -> Self { 387 self.show_hidden = Some(show_hidden); 388 self 389 } 390 use_preview_label(mut self, use_preview_label: bool) -> Self391 pub fn use_preview_label(mut self, use_preview_label: bool) -> Self { 392 self.use_preview_label = Some(use_preview_label); 393 self 394 } 395 } 396 397 impl fmt::Display for FileChooserNative { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result398 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 399 f.write_str("FileChooserNative") 400 } 401 } 402