gtk4/auto/file_chooser.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, FileChooserAction, FileFilter};
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 /// Use [`FileDialog`][crate::FileDialog] instead
16 /// [`FileChooser`][crate::FileChooser] is an interface that can be implemented by file
17 /// selection widgets.
18 ///
19 /// In GTK, the main objects that implement this interface are
20 /// [`FileChooserWidget`][crate::FileChooserWidget] and [`FileChooserDialog`][crate::FileChooserDialog].
21 ///
22 /// You do not need to write an object that implements the [`FileChooser`][crate::FileChooser]
23 /// interface unless you are trying to adapt an existing file selector to
24 /// expose a standard programming interface.
25 ///
26 /// [`FileChooser`][crate::FileChooser] allows for shortcuts to various places in the filesystem.
27 /// In the default implementation these are displayed in the left pane. It
28 /// may be a bit confusing at first that these shortcuts come from various
29 /// sources and in various flavours, so lets explain the terminology here:
30 ///
31 /// - Bookmarks: are created by the user, by dragging folders from the
32 /// right pane to the left pane, or by using the “Add”. Bookmarks
33 /// can be renamed and deleted by the user.
34 ///
35 /// - Shortcuts: can be provided by the application. For example, a Paint
36 /// program may want to add a shortcut for a Clipart folder. Shortcuts
37 /// cannot be modified by the user.
38 ///
39 /// - Volumes: are provided by the underlying filesystem abstraction. They are
40 /// the “roots” of the filesystem.
41 ///
42 /// # File Names and Encodings
43 ///
44 /// When the user is finished selecting files in a [`FileChooser`][crate::FileChooser], your
45 /// program can get the selected filenames as `GFile`s.
46 ///
47 /// # Adding options
48 ///
49 /// You can add extra widgets to a file chooser to provide options
50 /// that are not present in the default design, by using
51 /// [`FileChooserExtManual::add_choice()`][crate::prelude::FileChooserExtManual::add_choice()]. Each choice has an identifier and
52 /// a user visible label; additionally, each choice can have multiple
53 /// options. If a choice has no option, it will be rendered as a
54 /// check button with the given label; if a choice has options, it will
55 /// be rendered as a combo box.
56 ///
57 /// ## Properties
58 ///
59 ///
60 /// #### `action`
61 /// The type of operation that the file chooser is performing.
62 ///
63 /// Readable | Writeable
64 ///
65 ///
66 /// #### `create-folders`
67 /// Whether a file chooser not in [`FileChooserAction::Open`][crate::FileChooserAction::Open] mode
68 /// will offer the user to create new folders.
69 ///
70 /// Readable | Writeable
71 ///
72 ///
73 /// #### `filter`
74 /// The current filter for selecting files that are displayed.
75 ///
76 /// Readable | Writeable
77 ///
78 ///
79 /// #### `filters`
80 /// A `GListModel` containing the filters that have been
81 /// added with gtk_file_chooser_add_filter().
82 ///
83 /// The returned object should not be modified. It may
84 /// or may not be updated for later changes.
85 ///
86 /// Readable
87 ///
88 ///
89 /// #### `select-multiple`
90 /// Whether to allow multiple files to be selected.
91 ///
92 /// Readable | Writeable
93 ///
94 ///
95 /// #### `shortcut-folders`
96 /// A `GListModel` containing the shortcut folders that have been
97 /// added with gtk_file_chooser_add_shortcut_folder().
98 ///
99 /// The returned object should not be modified. It may
100 /// or may not be updated for later changes.
101 ///
102 /// Readable
103 ///
104 /// # Implements
105 ///
106 /// [`FileChooserExt`][trait@crate::prelude::FileChooserExt], [`FileChooserExtManual`][trait@crate::prelude::FileChooserExtManual]
107 #[doc(alias = "GtkFileChooser")]
108 pub struct FileChooser(Interface<ffi::GtkFileChooser>);
109
110 match fn {
111 type_ => || ffi::gtk_file_chooser_get_type(),
112 }
113}
114
115impl FileChooser {
116 pub const NONE: Option<&'static FileChooser> = None;
117}
118
119/// Trait containing all [`struct@FileChooser`] methods.
120///
121/// # Implementors
122///
123/// [`FileChooserDialog`][struct@crate::FileChooserDialog], [`FileChooserNative`][struct@crate::FileChooserNative], [`FileChooserWidget`][struct@crate::FileChooserWidget], [`FileChooser`][struct@crate::FileChooser]
124pub trait FileChooserExt: IsA<FileChooser> + 'static {
125 /// Adds @filter to the list of filters that the user can select between.
126 ///
127 /// When a filter is selected, only files that are passed by that
128 /// filter are displayed.
129 ///
130 /// Note that the @self takes ownership of the filter if it is floating,
131 /// so you have to ref and sink it if you want to keep a reference.
132 ///
133 /// # Deprecated since 4.10
134 ///
135 /// Use [`FileDialog`][crate::FileDialog] instead
136 /// ## `filter`
137 /// a [`FileFilter`][crate::FileFilter]
138 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
139 #[allow(deprecated)]
140 #[doc(alias = "gtk_file_chooser_add_filter")]
141 fn add_filter(&self, filter: &FileFilter) {
142 unsafe {
143 ffi::gtk_file_chooser_add_filter(
144 self.as_ref().to_glib_none().0,
145 filter.to_glib_none().0,
146 );
147 }
148 }
149
150 /// Adds a folder to be displayed with the shortcut folders
151 /// in a file chooser.
152 ///
153 /// # Deprecated since 4.10
154 ///
155 /// Use [`FileDialog`][crate::FileDialog] instead
156 /// ## `folder`
157 /// a `GFile` for the folder to add
158 ///
159 /// # Returns
160 ///
161 /// [`true`] if the folder could be added successfully,
162 /// [`false`] otherwise.
163 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
164 #[allow(deprecated)]
165 #[doc(alias = "gtk_file_chooser_add_shortcut_folder")]
166 fn add_shortcut_folder(&self, folder: &impl IsA<gio::File>) -> Result<(), glib::Error> {
167 unsafe {
168 let mut error = std::ptr::null_mut();
169 let is_ok = ffi::gtk_file_chooser_add_shortcut_folder(
170 self.as_ref().to_glib_none().0,
171 folder.as_ref().to_glib_none().0,
172 &mut error,
173 );
174 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
175 if error.is_null() {
176 Ok(())
177 } else {
178 Err(from_glib_full(error))
179 }
180 }
181 }
182
183 /// Gets the type of operation that the file chooser is performing.
184 ///
185 /// # Deprecated since 4.10
186 ///
187 /// Use [`FileDialog`][crate::FileDialog] instead
188 ///
189 /// # Returns
190 ///
191 /// the action that the file selector is performing
192 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
193 #[allow(deprecated)]
194 #[doc(alias = "gtk_file_chooser_get_action")]
195 #[doc(alias = "get_action")]
196 fn action(&self) -> FileChooserAction {
197 unsafe {
198 from_glib(ffi::gtk_file_chooser_get_action(
199 self.as_ref().to_glib_none().0,
200 ))
201 }
202 }
203
204 /// Gets the currently selected option in the 'choice' with the given ID.
205 ///
206 /// # Deprecated since 4.10
207 ///
208 /// Use [`FileDialog`][crate::FileDialog] instead
209 /// ## `id`
210 /// the ID of the choice to get
211 ///
212 /// # Returns
213 ///
214 /// the ID of the currently selected option
215 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
216 #[allow(deprecated)]
217 #[doc(alias = "gtk_file_chooser_get_choice")]
218 #[doc(alias = "get_choice")]
219 fn choice(&self, id: &str) -> Option<glib::GString> {
220 unsafe {
221 from_glib_none(ffi::gtk_file_chooser_get_choice(
222 self.as_ref().to_glib_none().0,
223 id.to_glib_none().0,
224 ))
225 }
226 }
227
228 /// Gets whether file chooser will offer to create new folders.
229 ///
230 /// # Deprecated since 4.10
231 ///
232 /// Use [`FileDialog`][crate::FileDialog] instead
233 ///
234 /// # Returns
235 ///
236 /// [`true`] if the Create Folder button should be displayed.
237 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
238 #[allow(deprecated)]
239 #[doc(alias = "gtk_file_chooser_get_create_folders")]
240 #[doc(alias = "get_create_folders")]
241 #[doc(alias = "create-folders")]
242 fn creates_folders(&self) -> bool {
243 unsafe {
244 from_glib(ffi::gtk_file_chooser_get_create_folders(
245 self.as_ref().to_glib_none().0,
246 ))
247 }
248 }
249
250 /// Gets the current folder of @self as `GFile`.
251 ///
252 /// # Deprecated since 4.10
253 ///
254 /// Use [`FileDialog`][crate::FileDialog] instead
255 ///
256 /// # Returns
257 ///
258 /// the `GFile` for the current folder.
259 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
260 #[allow(deprecated)]
261 #[doc(alias = "gtk_file_chooser_get_current_folder")]
262 #[doc(alias = "get_current_folder")]
263 fn current_folder(&self) -> Option<gio::File> {
264 unsafe {
265 from_glib_full(ffi::gtk_file_chooser_get_current_folder(
266 self.as_ref().to_glib_none().0,
267 ))
268 }
269 }
270
271 /// Gets the current name in the file selector, as entered by the user.
272 ///
273 /// This is meant to be used in save dialogs, to get the currently typed
274 /// filename when the file itself does not exist yet.
275 ///
276 /// # Deprecated since 4.10
277 ///
278 /// Use [`FileDialog`][crate::FileDialog] instead
279 ///
280 /// # Returns
281 ///
282 /// The raw text from the file chooser’s “Name” entry. Free with
283 /// g_free(). Note that this string is not a full pathname or URI; it is
284 /// whatever the contents of the entry are. Note also that this string is
285 /// in UTF-8 encoding, which is not necessarily the system’s encoding for
286 /// filenames.
287 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
288 #[allow(deprecated)]
289 #[doc(alias = "gtk_file_chooser_get_current_name")]
290 #[doc(alias = "get_current_name")]
291 fn current_name(&self) -> Option<glib::GString> {
292 unsafe {
293 from_glib_full(ffi::gtk_file_chooser_get_current_name(
294 self.as_ref().to_glib_none().0,
295 ))
296 }
297 }
298
299 /// Gets the `GFile` for the currently selected file in
300 /// the file selector.
301 ///
302 /// If multiple files are selected, one of the files will be
303 /// returned at random.
304 ///
305 /// If the file chooser is in folder mode, this function returns
306 /// the selected folder.
307 ///
308 /// # Deprecated since 4.10
309 ///
310 /// Use [`FileDialog`][crate::FileDialog] instead
311 ///
312 /// # Returns
313 ///
314 /// a selected `GFile`. You own the
315 /// returned file; use g_object_unref() to release it.
316 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
317 #[allow(deprecated)]
318 #[doc(alias = "gtk_file_chooser_get_file")]
319 #[doc(alias = "get_file")]
320 fn file(&self) -> Option<gio::File> {
321 unsafe {
322 from_glib_full(ffi::gtk_file_chooser_get_file(
323 self.as_ref().to_glib_none().0,
324 ))
325 }
326 }
327
328 /// Lists all the selected files and subfolders in the current folder
329 /// of @self as `GFile`.
330 ///
331 /// # Deprecated since 4.10
332 ///
333 /// Use [`FileDialog`][crate::FileDialog] instead
334 ///
335 /// # Returns
336 ///
337 /// a list model containing a `GFile` for each
338 /// selected file and subfolder in the current folder. Free the returned
339 /// list with g_object_unref().
340 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
341 #[allow(deprecated)]
342 #[doc(alias = "gtk_file_chooser_get_files")]
343 #[doc(alias = "get_files")]
344 fn files(&self) -> gio::ListModel {
345 unsafe {
346 from_glib_full(ffi::gtk_file_chooser_get_files(
347 self.as_ref().to_glib_none().0,
348 ))
349 }
350 }
351
352 /// Gets the current filter.
353 ///
354 /// # Deprecated since 4.10
355 ///
356 /// Use [`FileDialog`][crate::FileDialog] instead
357 ///
358 /// # Returns
359 ///
360 /// the current filter
361 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
362 #[allow(deprecated)]
363 #[doc(alias = "gtk_file_chooser_get_filter")]
364 #[doc(alias = "get_filter")]
365 fn filter(&self) -> Option<FileFilter> {
366 unsafe {
367 from_glib_none(ffi::gtk_file_chooser_get_filter(
368 self.as_ref().to_glib_none().0,
369 ))
370 }
371 }
372
373 /// Gets the current set of user-selectable filters, as a list model.
374 ///
375 /// See [`add_filter()`][Self::add_filter()] and
376 /// [`remove_filter()`][Self::remove_filter()] for changing individual filters.
377 ///
378 /// You should not modify the returned list model. Future changes to
379 /// @self may or may not affect the returned model.
380 ///
381 /// # Deprecated since 4.10
382 ///
383 /// Use [`FileDialog`][crate::FileDialog] instead
384 ///
385 /// # Returns
386 ///
387 /// a `GListModel` containing the current set
388 /// of user-selectable filters.
389 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
390 #[allow(deprecated)]
391 #[doc(alias = "gtk_file_chooser_get_filters")]
392 #[doc(alias = "get_filters")]
393 fn filters(&self) -> gio::ListModel {
394 unsafe {
395 from_glib_full(ffi::gtk_file_chooser_get_filters(
396 self.as_ref().to_glib_none().0,
397 ))
398 }
399 }
400
401 /// Gets whether multiple files can be selected in the file
402 /// chooser.
403 ///
404 /// # Deprecated since 4.10
405 ///
406 /// Use [`FileDialog`][crate::FileDialog] instead
407 ///
408 /// # Returns
409 ///
410 /// [`true`] if multiple files can be selected.
411 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
412 #[allow(deprecated)]
413 #[doc(alias = "gtk_file_chooser_get_select_multiple")]
414 #[doc(alias = "get_select_multiple")]
415 #[doc(alias = "select-multiple")]
416 fn selects_multiple(&self) -> bool {
417 unsafe {
418 from_glib(ffi::gtk_file_chooser_get_select_multiple(
419 self.as_ref().to_glib_none().0,
420 ))
421 }
422 }
423
424 /// Queries the list of shortcut folders in the file chooser.
425 ///
426 /// You should not modify the returned list model. Future changes to
427 /// @self may or may not affect the returned model.
428 ///
429 /// # Deprecated since 4.10
430 ///
431 /// Use [`FileDialog`][crate::FileDialog] instead
432 ///
433 /// # Returns
434 ///
435 /// A list model of `GFile`s
436 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
437 #[allow(deprecated)]
438 #[doc(alias = "gtk_file_chooser_get_shortcut_folders")]
439 #[doc(alias = "get_shortcut_folders")]
440 #[doc(alias = "shortcut-folders")]
441 fn shortcut_folders(&self) -> gio::ListModel {
442 unsafe {
443 from_glib_full(ffi::gtk_file_chooser_get_shortcut_folders(
444 self.as_ref().to_glib_none().0,
445 ))
446 }
447 }
448
449 /// Removes a 'choice' that has been added with gtk_file_chooser_add_choice().
450 ///
451 /// # Deprecated since 4.10
452 ///
453 /// Use [`FileDialog`][crate::FileDialog] instead
454 /// ## `id`
455 /// the ID of the choice to remove
456 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
457 #[allow(deprecated)]
458 #[doc(alias = "gtk_file_chooser_remove_choice")]
459 fn remove_choice(&self, id: &str) {
460 unsafe {
461 ffi::gtk_file_chooser_remove_choice(
462 self.as_ref().to_glib_none().0,
463 id.to_glib_none().0,
464 );
465 }
466 }
467
468 /// Removes @filter from the list of filters that the user can select between.
469 ///
470 /// # Deprecated since 4.10
471 ///
472 /// Use [`FileDialog`][crate::FileDialog] instead
473 /// ## `filter`
474 /// a [`FileFilter`][crate::FileFilter]
475 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
476 #[allow(deprecated)]
477 #[doc(alias = "gtk_file_chooser_remove_filter")]
478 fn remove_filter(&self, filter: &FileFilter) {
479 unsafe {
480 ffi::gtk_file_chooser_remove_filter(
481 self.as_ref().to_glib_none().0,
482 filter.to_glib_none().0,
483 );
484 }
485 }
486
487 /// Removes a folder from the shortcut folders in a file chooser.
488 ///
489 /// # Deprecated since 4.10
490 ///
491 /// Use [`FileDialog`][crate::FileDialog] instead
492 /// ## `folder`
493 /// a `GFile` for the folder to remove
494 ///
495 /// # Returns
496 ///
497 /// [`true`] if the folder could be removed successfully,
498 /// [`false`] otherwise.
499 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
500 #[allow(deprecated)]
501 #[doc(alias = "gtk_file_chooser_remove_shortcut_folder")]
502 fn remove_shortcut_folder(&self, folder: &impl IsA<gio::File>) -> Result<(), glib::Error> {
503 unsafe {
504 let mut error = std::ptr::null_mut();
505 let is_ok = ffi::gtk_file_chooser_remove_shortcut_folder(
506 self.as_ref().to_glib_none().0,
507 folder.as_ref().to_glib_none().0,
508 &mut error,
509 );
510 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
511 if error.is_null() {
512 Ok(())
513 } else {
514 Err(from_glib_full(error))
515 }
516 }
517 }
518
519 /// Sets the type of operation that the chooser is performing.
520 ///
521 /// The user interface is adapted to suit the selected action.
522 ///
523 /// For example, an option to create a new folder might be shown
524 /// if the action is [`FileChooserAction::Save`][crate::FileChooserAction::Save] but not if the
525 /// action is [`FileChooserAction::Open`][crate::FileChooserAction::Open].
526 ///
527 /// # Deprecated since 4.10
528 ///
529 /// Use [`FileDialog`][crate::FileDialog] instead
530 /// ## `action`
531 /// the action that the file selector is performing
532 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
533 #[allow(deprecated)]
534 #[doc(alias = "gtk_file_chooser_set_action")]
535 #[doc(alias = "action")]
536 fn set_action(&self, action: FileChooserAction) {
537 unsafe {
538 ffi::gtk_file_chooser_set_action(self.as_ref().to_glib_none().0, action.into_glib());
539 }
540 }
541
542 /// Selects an option in a 'choice' that has been added with
543 /// gtk_file_chooser_add_choice().
544 ///
545 /// For a boolean choice, the possible options are "true" and "false".
546 ///
547 /// # Deprecated since 4.10
548 ///
549 /// Use [`FileDialog`][crate::FileDialog] instead
550 /// ## `id`
551 /// the ID of the choice to set
552 /// ## `option`
553 /// the ID of the option to select
554 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
555 #[allow(deprecated)]
556 #[doc(alias = "gtk_file_chooser_set_choice")]
557 fn set_choice(&self, id: &str, option: &str) {
558 unsafe {
559 ffi::gtk_file_chooser_set_choice(
560 self.as_ref().to_glib_none().0,
561 id.to_glib_none().0,
562 option.to_glib_none().0,
563 );
564 }
565 }
566
567 /// Sets whether file chooser will offer to create new folders.
568 ///
569 /// This is only relevant if the action is not set to be
570 /// [`FileChooserAction::Open`][crate::FileChooserAction::Open].
571 ///
572 /// # Deprecated since 4.10
573 ///
574 /// Use [`FileDialog`][crate::FileDialog] instead
575 /// ## `create_folders`
576 /// [`true`] if the Create Folder button should be displayed
577 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
578 #[allow(deprecated)]
579 #[doc(alias = "gtk_file_chooser_set_create_folders")]
580 #[doc(alias = "create-folders")]
581 fn set_create_folders(&self, create_folders: bool) {
582 unsafe {
583 ffi::gtk_file_chooser_set_create_folders(
584 self.as_ref().to_glib_none().0,
585 create_folders.into_glib(),
586 );
587 }
588 }
589
590 /// Sets the current name in the file selector, as if entered
591 /// by the user.
592 ///
593 /// Note that the name passed in here is a UTF-8 string rather
594 /// than a filename. This function is meant for such uses as a
595 /// suggested name in a “Save As...” dialog. You can pass
596 /// “Untitled.doc” or a similarly suitable suggestion for the @name.
597 ///
598 /// If you want to preselect a particular existing file, you should
599 /// use [`set_file()`][Self::set_file()] instead.
600 ///
601 /// Please see the documentation for those functions for an example
602 /// of using [`set_current_name()`][Self::set_current_name()] as well.
603 ///
604 /// # Deprecated since 4.10
605 ///
606 /// Use [`FileDialog`][crate::FileDialog] instead
607 /// ## `name`
608 /// the filename to use, as a UTF-8 string
609 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
610 #[allow(deprecated)]
611 #[doc(alias = "gtk_file_chooser_set_current_name")]
612 fn set_current_name(&self, name: &str) {
613 unsafe {
614 ffi::gtk_file_chooser_set_current_name(
615 self.as_ref().to_glib_none().0,
616 name.to_glib_none().0,
617 );
618 }
619 }
620
621 /// Sets @file as the current filename for the file chooser.
622 ///
623 /// This includes changing to the file’s parent folder and actually selecting
624 /// the file in list. If the @self is in [`FileChooserAction::Save`][crate::FileChooserAction::Save] mode,
625 /// the file’s base name will also appear in the dialog’s file name entry.
626 ///
627 /// If the file name isn’t in the current folder of @self, then the current
628 /// folder of @self will be changed to the folder containing @file.
629 ///
630 /// Note that the file must exist, or nothing will be done except
631 /// for the directory change.
632 ///
633 /// If you are implementing a save dialog, you should use this function if
634 /// you already have a file name to which the user may save; for example,
635 /// when the user opens an existing file and then does “Save As…”. If you
636 /// don’t have a file name already — for example, if the user just created
637 /// a new file and is saving it for the first time, do not call this function.
638 ///
639 /// Instead, use something similar to this:
640 ///
641 /// **⚠️ The following code is in c ⚠️**
642 ///
643 /// ```c
644 /// static void
645 /// prepare_file_chooser (GtkFileChooser *chooser,
646 /// GFile *existing_file)
647 /// {
648 /// gboolean document_is_new = (existing_file == NULL);
649 ///
650 /// if (document_is_new)
651 /// {
652 /// GFile *default_file_for_saving = g_file_new_for_path ("./out.txt");
653 /// // the user just created a new document
654 /// gtk_file_chooser_set_current_folder (chooser, default_file_for_saving, NULL);
655 /// gtk_file_chooser_set_current_name (chooser, "Untitled document");
656 /// g_object_unref (default_file_for_saving);
657 /// }
658 /// else
659 /// {
660 /// // the user edited an existing document
661 /// gtk_file_chooser_set_file (chooser, existing_file, NULL);
662 /// }
663 /// }
664 /// ```
665 ///
666 /// # Deprecated since 4.10
667 ///
668 /// Use [`FileDialog`][crate::FileDialog] instead
669 /// ## `file`
670 /// the `GFile` to set as current
671 ///
672 /// # Returns
673 ///
674 /// Not useful
675 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
676 #[allow(deprecated)]
677 #[doc(alias = "gtk_file_chooser_set_file")]
678 fn set_file(&self, file: &impl IsA<gio::File>) -> Result<(), glib::Error> {
679 unsafe {
680 let mut error = std::ptr::null_mut();
681 let is_ok = ffi::gtk_file_chooser_set_file(
682 self.as_ref().to_glib_none().0,
683 file.as_ref().to_glib_none().0,
684 &mut error,
685 );
686 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
687 if error.is_null() {
688 Ok(())
689 } else {
690 Err(from_glib_full(error))
691 }
692 }
693 }
694
695 /// Sets the current filter.
696 ///
697 /// Only the files that pass the filter will be displayed.
698 /// If the user-selectable list of filters is non-empty, then
699 /// the filter should be one of the filters in that list.
700 ///
701 /// Setting the current filter when the list of filters is
702 /// empty is useful if you want to restrict the displayed
703 /// set of files without letting the user change it.
704 ///
705 /// # Deprecated since 4.10
706 ///
707 /// Use [`FileDialog`][crate::FileDialog] instead
708 /// ## `filter`
709 /// a [`FileFilter`][crate::FileFilter]
710 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
711 #[allow(deprecated)]
712 #[doc(alias = "gtk_file_chooser_set_filter")]
713 #[doc(alias = "filter")]
714 fn set_filter(&self, filter: &FileFilter) {
715 unsafe {
716 ffi::gtk_file_chooser_set_filter(
717 self.as_ref().to_glib_none().0,
718 filter.to_glib_none().0,
719 );
720 }
721 }
722
723 /// Sets whether multiple files can be selected in the file chooser.
724 ///
725 /// This is only relevant if the action is set to be
726 /// [`FileChooserAction::Open`][crate::FileChooserAction::Open] or
727 /// [`FileChooserAction::SelectFolder`][crate::FileChooserAction::SelectFolder].
728 ///
729 /// # Deprecated since 4.10
730 ///
731 /// Use [`FileDialog`][crate::FileDialog] instead
732 /// ## `select_multiple`
733 /// [`true`] if multiple files can be selected.
734 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
735 #[allow(deprecated)]
736 #[doc(alias = "gtk_file_chooser_set_select_multiple")]
737 #[doc(alias = "select-multiple")]
738 fn set_select_multiple(&self, select_multiple: bool) {
739 unsafe {
740 ffi::gtk_file_chooser_set_select_multiple(
741 self.as_ref().to_glib_none().0,
742 select_multiple.into_glib(),
743 );
744 }
745 }
746
747 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
748 #[doc(alias = "action")]
749 fn connect_action_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
750 unsafe extern "C" fn notify_action_trampoline<P: IsA<FileChooser>, F: Fn(&P) + 'static>(
751 this: *mut ffi::GtkFileChooser,
752 _param_spec: glib::ffi::gpointer,
753 f: glib::ffi::gpointer,
754 ) {
755 let f: &F = &*(f as *const F);
756 f(FileChooser::from_glib_borrow(this).unsafe_cast_ref())
757 }
758 unsafe {
759 let f: Box_<F> = Box_::new(f);
760 connect_raw(
761 self.as_ptr() as *mut _,
762 c"notify::action".as_ptr() as *const _,
763 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
764 notify_action_trampoline::<Self, F> as *const (),
765 )),
766 Box_::into_raw(f),
767 )
768 }
769 }
770
771 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
772 #[doc(alias = "create-folders")]
773 fn connect_create_folders_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
774 unsafe extern "C" fn notify_create_folders_trampoline<
775 P: IsA<FileChooser>,
776 F: Fn(&P) + 'static,
777 >(
778 this: *mut ffi::GtkFileChooser,
779 _param_spec: glib::ffi::gpointer,
780 f: glib::ffi::gpointer,
781 ) {
782 let f: &F = &*(f as *const F);
783 f(FileChooser::from_glib_borrow(this).unsafe_cast_ref())
784 }
785 unsafe {
786 let f: Box_<F> = Box_::new(f);
787 connect_raw(
788 self.as_ptr() as *mut _,
789 c"notify::create-folders".as_ptr() as *const _,
790 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
791 notify_create_folders_trampoline::<Self, F> as *const (),
792 )),
793 Box_::into_raw(f),
794 )
795 }
796 }
797
798 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
799 #[doc(alias = "filter")]
800 fn connect_filter_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
801 unsafe extern "C" fn notify_filter_trampoline<P: IsA<FileChooser>, F: Fn(&P) + 'static>(
802 this: *mut ffi::GtkFileChooser,
803 _param_spec: glib::ffi::gpointer,
804 f: glib::ffi::gpointer,
805 ) {
806 let f: &F = &*(f as *const F);
807 f(FileChooser::from_glib_borrow(this).unsafe_cast_ref())
808 }
809 unsafe {
810 let f: Box_<F> = Box_::new(f);
811 connect_raw(
812 self.as_ptr() as *mut _,
813 c"notify::filter".as_ptr() as *const _,
814 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
815 notify_filter_trampoline::<Self, F> as *const (),
816 )),
817 Box_::into_raw(f),
818 )
819 }
820 }
821
822 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
823 #[doc(alias = "filters")]
824 fn connect_filters_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
825 unsafe extern "C" fn notify_filters_trampoline<P: IsA<FileChooser>, F: Fn(&P) + 'static>(
826 this: *mut ffi::GtkFileChooser,
827 _param_spec: glib::ffi::gpointer,
828 f: glib::ffi::gpointer,
829 ) {
830 let f: &F = &*(f as *const F);
831 f(FileChooser::from_glib_borrow(this).unsafe_cast_ref())
832 }
833 unsafe {
834 let f: Box_<F> = Box_::new(f);
835 connect_raw(
836 self.as_ptr() as *mut _,
837 c"notify::filters".as_ptr() as *const _,
838 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
839 notify_filters_trampoline::<Self, F> as *const (),
840 )),
841 Box_::into_raw(f),
842 )
843 }
844 }
845
846 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
847 #[doc(alias = "select-multiple")]
848 fn connect_select_multiple_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
849 unsafe extern "C" fn notify_select_multiple_trampoline<
850 P: IsA<FileChooser>,
851 F: Fn(&P) + 'static,
852 >(
853 this: *mut ffi::GtkFileChooser,
854 _param_spec: glib::ffi::gpointer,
855 f: glib::ffi::gpointer,
856 ) {
857 let f: &F = &*(f as *const F);
858 f(FileChooser::from_glib_borrow(this).unsafe_cast_ref())
859 }
860 unsafe {
861 let f: Box_<F> = Box_::new(f);
862 connect_raw(
863 self.as_ptr() as *mut _,
864 c"notify::select-multiple".as_ptr() as *const _,
865 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
866 notify_select_multiple_trampoline::<Self, F> as *const (),
867 )),
868 Box_::into_raw(f),
869 )
870 }
871 }
872
873 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
874 #[doc(alias = "shortcut-folders")]
875 fn connect_shortcut_folders_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
876 unsafe extern "C" fn notify_shortcut_folders_trampoline<
877 P: IsA<FileChooser>,
878 F: Fn(&P) + 'static,
879 >(
880 this: *mut ffi::GtkFileChooser,
881 _param_spec: glib::ffi::gpointer,
882 f: glib::ffi::gpointer,
883 ) {
884 let f: &F = &*(f as *const F);
885 f(FileChooser::from_glib_borrow(this).unsafe_cast_ref())
886 }
887 unsafe {
888 let f: Box_<F> = Box_::new(f);
889 connect_raw(
890 self.as_ptr() as *mut _,
891 c"notify::shortcut-folders".as_ptr() as *const _,
892 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
893 notify_shortcut_folders_trampoline::<Self, F> as *const (),
894 )),
895 Box_::into_raw(f),
896 )
897 }
898 }
899}
900
901impl<O: IsA<FileChooser>> FileChooserExt for O {}