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 glib::object::Cast; 6 use glib::object::IsA; 7 use glib::signal::connect_raw; 8 use glib::signal::SignalHandlerId; 9 use glib::translate::*; 10 use glib::GString; 11 use glib::StaticType; 12 use glib::ToValue; 13 use glib::Value; 14 use glib_sys; 15 use gobject_sys; 16 use gtk_sys; 17 use std::boxed::Box as Box_; 18 use std::fmt; 19 use std::mem::transmute; 20 use FileChooser; 21 use FileChooserAction; 22 use FileFilter; 23 use NativeDialog; 24 use Widget; 25 #[cfg(any(feature = "v3_20", feature = "dox"))] 26 use Window; 27 28 glib_wrapper! { 29 pub struct FileChooserNative(Object<gtk_sys::GtkFileChooserNative, gtk_sys::GtkFileChooserNativeClass, FileChooserNativeClass>) @extends NativeDialog, @implements FileChooser; 30 31 match fn { 32 get_type => || gtk_sys::gtk_file_chooser_native_get_type(), 33 } 34 } 35 36 impl FileChooserNative { 37 #[cfg(any(feature = "v3_20", feature = "dox"))] new<P: IsA<Window>>( title: Option<&str>, parent: Option<&P>, action: FileChooserAction, accept_label: Option<&str>, cancel_label: Option<&str>, ) -> FileChooserNative38 pub fn new<P: IsA<Window>>( 39 title: Option<&str>, 40 parent: Option<&P>, 41 action: FileChooserAction, 42 accept_label: Option<&str>, 43 cancel_label: Option<&str>, 44 ) -> FileChooserNative { 45 assert_initialized_main_thread!(); 46 unsafe { 47 from_glib_full(gtk_sys::gtk_file_chooser_native_new( 48 title.to_glib_none().0, 49 parent.map(|p| p.as_ref()).to_glib_none().0, 50 action.to_glib(), 51 accept_label.to_glib_none().0, 52 cancel_label.to_glib_none().0, 53 )) 54 } 55 } 56 } 57 58 #[derive(Clone, Default)] 59 pub struct FileChooserNativeBuilder { 60 accept_label: Option<String>, 61 cancel_label: Option<String>, 62 #[cfg(any(feature = "v3_20", feature = "dox"))] 63 modal: Option<bool>, 64 #[cfg(any(feature = "v3_20", feature = "dox"))] 65 title: Option<String>, 66 #[cfg(any(feature = "v3_20", feature = "dox"))] 67 transient_for: Option<Window>, 68 #[cfg(any(feature = "v3_20", feature = "dox"))] 69 visible: Option<bool>, 70 action: Option<FileChooserAction>, 71 create_folders: Option<bool>, 72 do_overwrite_confirmation: Option<bool>, 73 extra_widget: Option<Widget>, 74 filter: Option<FileFilter>, 75 local_only: Option<bool>, 76 preview_widget: Option<Widget>, 77 preview_widget_active: Option<bool>, 78 select_multiple: Option<bool>, 79 show_hidden: Option<bool>, 80 use_preview_label: Option<bool>, 81 } 82 83 impl FileChooserNativeBuilder { new() -> Self84 pub fn new() -> Self { 85 Self::default() 86 } 87 build(self) -> FileChooserNative88 pub fn build(self) -> FileChooserNative { 89 let mut properties: Vec<(&str, &dyn ToValue)> = vec![]; 90 if let Some(ref accept_label) = self.accept_label { 91 properties.push(("accept-label", accept_label)); 92 } 93 if let Some(ref cancel_label) = self.cancel_label { 94 properties.push(("cancel-label", cancel_label)); 95 } 96 #[cfg(any(feature = "v3_20", feature = "dox"))] 97 { 98 if let Some(ref modal) = self.modal { 99 properties.push(("modal", modal)); 100 } 101 } 102 #[cfg(any(feature = "v3_20", feature = "dox"))] 103 { 104 if let Some(ref title) = self.title { 105 properties.push(("title", title)); 106 } 107 } 108 #[cfg(any(feature = "v3_20", feature = "dox"))] 109 { 110 if let Some(ref transient_for) = self.transient_for { 111 properties.push(("transient-for", transient_for)); 112 } 113 } 114 #[cfg(any(feature = "v3_20", feature = "dox"))] 115 { 116 if let Some(ref visible) = self.visible { 117 properties.push(("visible", visible)); 118 } 119 } 120 if let Some(ref action) = self.action { 121 properties.push(("action", action)); 122 } 123 if let Some(ref create_folders) = self.create_folders { 124 properties.push(("create-folders", create_folders)); 125 } 126 if let Some(ref do_overwrite_confirmation) = self.do_overwrite_confirmation { 127 properties.push(("do-overwrite-confirmation", do_overwrite_confirmation)); 128 } 129 if let Some(ref extra_widget) = self.extra_widget { 130 properties.push(("extra-widget", extra_widget)); 131 } 132 if let Some(ref filter) = self.filter { 133 properties.push(("filter", filter)); 134 } 135 if let Some(ref local_only) = self.local_only { 136 properties.push(("local-only", local_only)); 137 } 138 if let Some(ref preview_widget) = self.preview_widget { 139 properties.push(("preview-widget", preview_widget)); 140 } 141 if let Some(ref preview_widget_active) = self.preview_widget_active { 142 properties.push(("preview-widget-active", preview_widget_active)); 143 } 144 if let Some(ref select_multiple) = self.select_multiple { 145 properties.push(("select-multiple", select_multiple)); 146 } 147 if let Some(ref show_hidden) = self.show_hidden { 148 properties.push(("show-hidden", show_hidden)); 149 } 150 if let Some(ref use_preview_label) = self.use_preview_label { 151 properties.push(("use-preview-label", use_preview_label)); 152 } 153 glib::Object::new(FileChooserNative::static_type(), &properties) 154 .expect("object new") 155 .downcast() 156 .expect("downcast") 157 } 158 accept_label(mut self, accept_label: &str) -> Self159 pub fn accept_label(mut self, accept_label: &str) -> Self { 160 self.accept_label = Some(accept_label.to_string()); 161 self 162 } 163 cancel_label(mut self, cancel_label: &str) -> Self164 pub fn cancel_label(mut self, cancel_label: &str) -> Self { 165 self.cancel_label = Some(cancel_label.to_string()); 166 self 167 } 168 169 #[cfg(any(feature = "v3_20", feature = "dox"))] modal(mut self, modal: bool) -> Self170 pub fn modal(mut self, modal: bool) -> Self { 171 self.modal = Some(modal); 172 self 173 } 174 175 #[cfg(any(feature = "v3_20", feature = "dox"))] title(mut self, title: &str) -> Self176 pub fn title(mut self, title: &str) -> Self { 177 self.title = Some(title.to_string()); 178 self 179 } 180 181 #[cfg(any(feature = "v3_20", feature = "dox"))] transient_for<P: IsA<Window>>(mut self, transient_for: &P) -> Self182 pub fn transient_for<P: IsA<Window>>(mut self, transient_for: &P) -> Self { 183 self.transient_for = Some(transient_for.clone().upcast()); 184 self 185 } 186 187 #[cfg(any(feature = "v3_20", feature = "dox"))] visible(mut self, visible: bool) -> Self188 pub fn visible(mut self, visible: bool) -> Self { 189 self.visible = Some(visible); 190 self 191 } 192 action(mut self, action: FileChooserAction) -> Self193 pub fn action(mut self, action: FileChooserAction) -> Self { 194 self.action = Some(action); 195 self 196 } 197 create_folders(mut self, create_folders: bool) -> Self198 pub fn create_folders(mut self, create_folders: bool) -> Self { 199 self.create_folders = Some(create_folders); 200 self 201 } 202 do_overwrite_confirmation(mut self, do_overwrite_confirmation: bool) -> Self203 pub fn do_overwrite_confirmation(mut self, do_overwrite_confirmation: bool) -> Self { 204 self.do_overwrite_confirmation = Some(do_overwrite_confirmation); 205 self 206 } 207 extra_widget<P: IsA<Widget>>(mut self, extra_widget: &P) -> Self208 pub fn extra_widget<P: IsA<Widget>>(mut self, extra_widget: &P) -> Self { 209 self.extra_widget = Some(extra_widget.clone().upcast()); 210 self 211 } 212 filter(mut self, filter: &FileFilter) -> Self213 pub fn filter(mut self, filter: &FileFilter) -> Self { 214 self.filter = Some(filter.clone()); 215 self 216 } 217 local_only(mut self, local_only: bool) -> Self218 pub fn local_only(mut self, local_only: bool) -> Self { 219 self.local_only = Some(local_only); 220 self 221 } 222 preview_widget<P: IsA<Widget>>(mut self, preview_widget: &P) -> Self223 pub fn preview_widget<P: IsA<Widget>>(mut self, preview_widget: &P) -> Self { 224 self.preview_widget = Some(preview_widget.clone().upcast()); 225 self 226 } 227 preview_widget_active(mut self, preview_widget_active: bool) -> Self228 pub fn preview_widget_active(mut self, preview_widget_active: bool) -> Self { 229 self.preview_widget_active = Some(preview_widget_active); 230 self 231 } 232 select_multiple(mut self, select_multiple: bool) -> Self233 pub fn select_multiple(mut self, select_multiple: bool) -> Self { 234 self.select_multiple = Some(select_multiple); 235 self 236 } 237 show_hidden(mut self, show_hidden: bool) -> Self238 pub fn show_hidden(mut self, show_hidden: bool) -> Self { 239 self.show_hidden = Some(show_hidden); 240 self 241 } 242 use_preview_label(mut self, use_preview_label: bool) -> Self243 pub fn use_preview_label(mut self, use_preview_label: bool) -> Self { 244 self.use_preview_label = Some(use_preview_label); 245 self 246 } 247 } 248 249 pub const NONE_FILE_CHOOSER_NATIVE: Option<&FileChooserNative> = None; 250 251 pub trait FileChooserNativeExt: 'static { 252 #[cfg(any(feature = "v3_20", feature = "dox"))] get_accept_label(&self) -> Option<GString>253 fn get_accept_label(&self) -> Option<GString>; 254 255 #[cfg(any(feature = "v3_20", feature = "dox"))] get_cancel_label(&self) -> Option<GString>256 fn get_cancel_label(&self) -> Option<GString>; 257 258 #[cfg(any(feature = "v3_20", feature = "dox"))] set_accept_label(&self, accept_label: Option<&str>)259 fn set_accept_label(&self, accept_label: Option<&str>); 260 261 #[cfg(any(feature = "v3_20", feature = "dox"))] set_cancel_label(&self, cancel_label: Option<&str>)262 fn set_cancel_label(&self, cancel_label: Option<&str>); 263 get_property_accept_label(&self) -> Option<GString>264 fn get_property_accept_label(&self) -> Option<GString>; 265 set_property_accept_label(&self, accept_label: Option<&str>)266 fn set_property_accept_label(&self, accept_label: Option<&str>); 267 get_property_cancel_label(&self) -> Option<GString>268 fn get_property_cancel_label(&self) -> Option<GString>; 269 set_property_cancel_label(&self, cancel_label: Option<&str>)270 fn set_property_cancel_label(&self, cancel_label: Option<&str>); 271 connect_property_accept_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId272 fn connect_property_accept_label_notify<F: Fn(&Self) + 'static>(&self, f: F) 273 -> SignalHandlerId; 274 connect_property_cancel_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId275 fn connect_property_cancel_label_notify<F: Fn(&Self) + 'static>(&self, f: F) 276 -> SignalHandlerId; 277 } 278 279 impl<O: IsA<FileChooserNative>> FileChooserNativeExt for O { 280 #[cfg(any(feature = "v3_20", feature = "dox"))] get_accept_label(&self) -> Option<GString>281 fn get_accept_label(&self) -> Option<GString> { 282 unsafe { 283 from_glib_none(gtk_sys::gtk_file_chooser_native_get_accept_label( 284 self.as_ref().to_glib_none().0, 285 )) 286 } 287 } 288 289 #[cfg(any(feature = "v3_20", feature = "dox"))] get_cancel_label(&self) -> Option<GString>290 fn get_cancel_label(&self) -> Option<GString> { 291 unsafe { 292 from_glib_none(gtk_sys::gtk_file_chooser_native_get_cancel_label( 293 self.as_ref().to_glib_none().0, 294 )) 295 } 296 } 297 298 #[cfg(any(feature = "v3_20", feature = "dox"))] set_accept_label(&self, accept_label: Option<&str>)299 fn set_accept_label(&self, accept_label: Option<&str>) { 300 unsafe { 301 gtk_sys::gtk_file_chooser_native_set_accept_label( 302 self.as_ref().to_glib_none().0, 303 accept_label.to_glib_none().0, 304 ); 305 } 306 } 307 308 #[cfg(any(feature = "v3_20", feature = "dox"))] set_cancel_label(&self, cancel_label: Option<&str>)309 fn set_cancel_label(&self, cancel_label: Option<&str>) { 310 unsafe { 311 gtk_sys::gtk_file_chooser_native_set_cancel_label( 312 self.as_ref().to_glib_none().0, 313 cancel_label.to_glib_none().0, 314 ); 315 } 316 } 317 get_property_accept_label(&self) -> Option<GString>318 fn get_property_accept_label(&self) -> Option<GString> { 319 unsafe { 320 let mut value = Value::from_type(<GString as StaticType>::static_type()); 321 gobject_sys::g_object_get_property( 322 self.to_glib_none().0 as *mut gobject_sys::GObject, 323 b"accept-label\0".as_ptr() as *const _, 324 value.to_glib_none_mut().0, 325 ); 326 value 327 .get() 328 .expect("Return Value for property `accept-label` getter") 329 } 330 } 331 set_property_accept_label(&self, accept_label: Option<&str>)332 fn set_property_accept_label(&self, accept_label: Option<&str>) { 333 unsafe { 334 gobject_sys::g_object_set_property( 335 self.to_glib_none().0 as *mut gobject_sys::GObject, 336 b"accept-label\0".as_ptr() as *const _, 337 Value::from(accept_label).to_glib_none().0, 338 ); 339 } 340 } 341 get_property_cancel_label(&self) -> Option<GString>342 fn get_property_cancel_label(&self) -> Option<GString> { 343 unsafe { 344 let mut value = Value::from_type(<GString as StaticType>::static_type()); 345 gobject_sys::g_object_get_property( 346 self.to_glib_none().0 as *mut gobject_sys::GObject, 347 b"cancel-label\0".as_ptr() as *const _, 348 value.to_glib_none_mut().0, 349 ); 350 value 351 .get() 352 .expect("Return Value for property `cancel-label` getter") 353 } 354 } 355 set_property_cancel_label(&self, cancel_label: Option<&str>)356 fn set_property_cancel_label(&self, cancel_label: Option<&str>) { 357 unsafe { 358 gobject_sys::g_object_set_property( 359 self.to_glib_none().0 as *mut gobject_sys::GObject, 360 b"cancel-label\0".as_ptr() as *const _, 361 Value::from(cancel_label).to_glib_none().0, 362 ); 363 } 364 } 365 connect_property_accept_label_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId366 fn connect_property_accept_label_notify<F: Fn(&Self) + 'static>( 367 &self, 368 f: F, 369 ) -> SignalHandlerId { 370 unsafe extern "C" fn notify_accept_label_trampoline<P, F: Fn(&P) + 'static>( 371 this: *mut gtk_sys::GtkFileChooserNative, 372 _param_spec: glib_sys::gpointer, 373 f: glib_sys::gpointer, 374 ) where 375 P: IsA<FileChooserNative>, 376 { 377 let f: &F = &*(f as *const F); 378 f(&FileChooserNative::from_glib_borrow(this).unsafe_cast()) 379 } 380 unsafe { 381 let f: Box_<F> = Box_::new(f); 382 connect_raw( 383 self.as_ptr() as *mut _, 384 b"notify::accept-label\0".as_ptr() as *const _, 385 Some(transmute( 386 notify_accept_label_trampoline::<Self, F> as usize, 387 )), 388 Box_::into_raw(f), 389 ) 390 } 391 } 392 connect_property_cancel_label_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId393 fn connect_property_cancel_label_notify<F: Fn(&Self) + 'static>( 394 &self, 395 f: F, 396 ) -> SignalHandlerId { 397 unsafe extern "C" fn notify_cancel_label_trampoline<P, F: Fn(&P) + 'static>( 398 this: *mut gtk_sys::GtkFileChooserNative, 399 _param_spec: glib_sys::gpointer, 400 f: glib_sys::gpointer, 401 ) where 402 P: IsA<FileChooserNative>, 403 { 404 let f: &F = &*(f as *const F); 405 f(&FileChooserNative::from_glib_borrow(this).unsafe_cast()) 406 } 407 unsafe { 408 let f: Box_<F> = Box_::new(f); 409 connect_raw( 410 self.as_ptr() as *mut _, 411 b"notify::cancel-label\0".as_ptr() as *const _, 412 Some(transmute( 413 notify_cancel_label_trampoline::<Self, F> as usize, 414 )), 415 Box_::into_raw(f), 416 ) 417 } 418 } 419 } 420 421 impl fmt::Display for FileChooserNative { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result422 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 423 write!(f, "FileChooserNative") 424 } 425 } 426