gtk/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
5use crate::{FileChooserAction, FileChooserConfirmation, FileFilter, Widget};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem::transmute, ptr};
12
13glib::wrapper! {
14 /// [`FileChooser`][crate::FileChooser] is an interface that can be implemented by file
15 /// selection widgets. In GTK+, the main objects that implement this
16 /// interface are [`FileChooserWidget`][crate::FileChooserWidget], [`FileChooserDialog`][crate::FileChooserDialog], and
17 /// [`FileChooserButton`][crate::FileChooserButton]. You do not need to write an object that
18 /// implements the [`FileChooser`][crate::FileChooser] interface unless you are trying to
19 /// adapt an existing file selector to expose a standard programming
20 /// interface.
21 ///
22 /// [`FileChooser`][crate::FileChooser] allows for shortcuts to various places in the filesystem.
23 /// In the default implementation these are displayed in the left pane. It
24 /// may be a bit confusing at first that these shortcuts come from various
25 /// sources and in various flavours, so lets explain the terminology here:
26 ///
27 /// - Bookmarks: are created by the user, by dragging folders from the
28 /// right pane to the left pane, or by using the “Add”. Bookmarks
29 /// can be renamed and deleted by the user.
30 ///
31 /// - Shortcuts: can be provided by the application. For example, a Paint
32 /// program may want to add a shortcut for a Clipart folder. Shortcuts
33 /// cannot be modified by the user.
34 ///
35 /// - Volumes: are provided by the underlying filesystem abstraction. They are
36 /// the “roots” of the filesystem.
37 ///
38 /// # File Names and Encodings
39 ///
40 /// When the user is finished selecting files in a
41 /// [`FileChooser`][crate::FileChooser], your program can get the selected names
42 /// either as filenames or as URIs. For URIs, the normal escaping
43 /// rules are applied if the URI contains non-ASCII characters.
44 /// However, filenames are always returned in
45 /// the character set specified by the
46 /// `G_FILENAME_ENCODING` environment variable.
47 /// Please see the GLib documentation for more details about this
48 /// variable.
49 ///
50 /// This means that while you can pass the result of
51 /// [`FileChooserExt::filename()`][crate::prelude::FileChooserExt::filename()] to `g_open()` or `g_fopen()`,
52 /// you may not be able to directly set it as the text of a
53 /// [`Label`][crate::Label] widget unless you convert it first to UTF-8,
54 /// which all GTK+ widgets expect. You should use `g_filename_to_utf8()`
55 /// to convert filenames into strings that can be passed to GTK+
56 /// widgets.
57 ///
58 /// # Adding a Preview Widget
59 ///
60 /// You can add a custom preview widget to a file chooser and then
61 /// get notification about when the preview needs to be updated.
62 /// To install a preview widget, use
63 /// [`FileChooserExt::set_preview_widget()`][crate::prelude::FileChooserExt::set_preview_widget()]. Then, connect to the
64 /// [`update-preview`][struct@crate::FileChooser#update-preview] signal to get notified when
65 /// you need to update the contents of the preview.
66 ///
67 /// Your callback should use
68 /// [`FileChooserExt::preview_filename()`][crate::prelude::FileChooserExt::preview_filename()] to see what needs
69 /// previewing. Once you have generated the preview for the
70 /// corresponding file, you must call
71 /// [`FileChooserExt::set_preview_widget_active()`][crate::prelude::FileChooserExt::set_preview_widget_active()] with a boolean
72 /// flag that indicates whether your callback could successfully
73 /// generate a preview.
74 ///
75 /// ## Example: Using a Preview Widget ## {`gtkfilechooser`-preview}
76 ///
77 ///
78 /// **⚠️ The following code is in C ⚠️**
79 ///
80 /// ```C
81 /// {
82 /// GtkImage *preview;
83 ///
84 /// ...
85 ///
86 /// preview = gtk_image_new ();
87 ///
88 /// gtk_file_chooser_set_preview_widget (my_file_chooser, preview);
89 /// g_signal_connect (my_file_chooser, "update-preview",
90 /// G_CALLBACK (update_preview_cb), preview);
91 /// }
92 ///
93 /// static void
94 /// update_preview_cb (GtkFileChooser *file_chooser, gpointer data)
95 /// {
96 /// GtkWidget *preview;
97 /// char *filename;
98 /// GdkPixbuf *pixbuf;
99 /// gboolean have_preview;
100 ///
101 /// preview = GTK_WIDGET (data);
102 /// filename = gtk_file_chooser_get_preview_filename (file_chooser);
103 ///
104 /// pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 128, 128, NULL);
105 /// have_preview = (pixbuf != NULL);
106 /// g_free (filename);
107 ///
108 /// gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf);
109 /// if (pixbuf)
110 /// g_object_unref (pixbuf);
111 ///
112 /// gtk_file_chooser_set_preview_widget_active (file_chooser, have_preview);
113 /// }
114 /// ```
115 ///
116 /// # Adding Extra Widgets
117 ///
118 /// You can add extra widgets to a file chooser to provide options
119 /// that are not present in the default design. For example, you
120 /// can add a toggle button to give the user the option to open a
121 /// file in read-only mode. You can use
122 /// [`FileChooserExt::set_extra_widget()`][crate::prelude::FileChooserExt::set_extra_widget()] to insert additional
123 /// widgets in a file chooser.
124 ///
125 /// An example for adding extra widgets:
126 ///
127 ///
128 /// **⚠️ The following code is in C ⚠️**
129 ///
130 /// ```C
131 ///
132 /// GtkWidget *toggle;
133 ///
134 /// ...
135 ///
136 /// toggle = gtk_check_button_new_with_label ("Open file read-only");
137 /// gtk_widget_show (toggle);
138 /// gtk_file_chooser_set_extra_widget (my_file_chooser, toggle);
139 /// }
140 /// ```
141 ///
142 /// If you want to set more than one extra widget in the file
143 /// chooser, you can a container such as a [`Box`][crate::Box] or a [`Grid`][crate::Grid]
144 /// and include your widgets in it. Then, set the container as
145 /// the whole extra widget.
146 ///
147 /// ## Properties
148 ///
149 ///
150 /// #### `action`
151 /// Readable | Writeable
152 ///
153 ///
154 /// #### `create-folders`
155 /// Whether a file chooser not in [`FileChooserAction::Open`][crate::FileChooserAction::Open] mode
156 /// will offer the user to create new folders.
157 ///
158 /// Readable | Writeable
159 ///
160 ///
161 /// #### `do-overwrite-confirmation`
162 /// Whether a file chooser in [`FileChooserAction::Save`][crate::FileChooserAction::Save] mode
163 /// will present an overwrite confirmation dialog if the user
164 /// selects a file name that already exists.
165 ///
166 /// Readable | Writeable
167 ///
168 ///
169 /// #### `extra-widget`
170 /// Readable | Writeable
171 ///
172 ///
173 /// #### `filter`
174 /// Readable | Writeable
175 ///
176 ///
177 /// #### `local-only`
178 /// Readable | Writeable
179 ///
180 ///
181 /// #### `preview-widget`
182 /// Readable | Writeable
183 ///
184 ///
185 /// #### `preview-widget-active`
186 /// Readable | Writeable
187 ///
188 ///
189 /// #### `select-multiple`
190 /// Readable | Writeable
191 ///
192 ///
193 /// #### `show-hidden`
194 /// Readable | Writeable
195 ///
196 ///
197 /// #### `use-preview-label`
198 /// Readable | Writeable
199 ///
200 /// ## Signals
201 ///
202 ///
203 /// #### `confirm-overwrite`
204 /// This signal gets emitted whenever it is appropriate to present a
205 /// confirmation dialog when the user has selected a file name that
206 /// already exists. The signal only gets emitted when the file
207 /// chooser is in [`FileChooserAction::Save`][crate::FileChooserAction::Save] mode.
208 ///
209 /// Most applications just need to turn on the
210 /// [`do-overwrite-confirmation`][struct@crate::FileChooser#do-overwrite-confirmation] property (or call the
211 /// [`FileChooserExt::set_do_overwrite_confirmation()`][crate::prelude::FileChooserExt::set_do_overwrite_confirmation()] function), and
212 /// they will automatically get a stock confirmation dialog.
213 /// Applications which need to customize this behavior should do
214 /// that, and also connect to the [`confirm-overwrite`][struct@crate::FileChooser#confirm-overwrite]
215 /// signal.
216 ///
217 /// A signal handler for this signal must return a
218 /// [`FileChooserConfirmation`][crate::FileChooserConfirmation] value, which indicates the action to
219 /// take. If the handler determines that the user wants to select a
220 /// different filename, it should return
221 /// [`FileChooserConfirmation::SelectAgain`][crate::FileChooserConfirmation::SelectAgain]. If it determines
222 /// that the user is satisfied with his choice of file name, it
223 /// should return [`FileChooserConfirmation::AcceptFilename`][crate::FileChooserConfirmation::AcceptFilename].
224 /// On the other hand, if it determines that the stock confirmation
225 /// dialog should be used, it should return
226 /// [`FileChooserConfirmation::Confirm`][crate::FileChooserConfirmation::Confirm]. The following example
227 /// illustrates this.
228 ///
229 /// ## Custom confirmation ## {`gtkfilechooser`-confirmation}
230 ///
231 ///
232 ///
233 /// **⚠️ The following code is in C ⚠️**
234 ///
235 /// ```C
236 /// static GtkFileChooserConfirmation
237 /// confirm_overwrite_callback (GtkFileChooser *chooser, gpointer data)
238 /// {
239 /// char *uri;
240 ///
241 /// uri = gtk_file_chooser_get_uri (chooser);
242 ///
243 /// if (is_uri_read_only (uri))
244 /// {
245 /// if (user_wants_to_replace_read_only_file (uri))
246 /// return GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME;
247 /// else
248 /// return GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN;
249 /// } else
250 /// return GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM; // fall back to the default dialog
251 /// }
252 ///
253 /// ...
254 ///
255 /// chooser = gtk_file_chooser_dialog_new (...);
256 ///
257 /// gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
258 /// g_signal_connect (chooser, "confirm-overwrite",
259 /// G_CALLBACK (confirm_overwrite_callback), NULL);
260 ///
261 /// if (gtk_dialog_run (chooser) == GTK_RESPONSE_ACCEPT)
262 /// save_to_file (gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
263 ///
264 /// gtk_widget_destroy (chooser);
265 /// ```
266 ///
267 ///
268 ///
269 ///
270 /// #### `current-folder-changed`
271 /// This signal is emitted when the current folder in a [`FileChooser`][crate::FileChooser]
272 /// changes. This can happen due to the user performing some action that
273 /// changes folders, such as selecting a bookmark or visiting a folder on the
274 /// file list. It can also happen as a result of calling a function to
275 /// explicitly change the current folder in a file chooser.
276 ///
277 /// Normally you do not need to connect to this signal, unless you need to keep
278 /// track of which folder a file chooser is showing.
279 ///
280 /// See also: [`FileChooserExt::set_current_folder()`][crate::prelude::FileChooserExt::set_current_folder()],
281 /// [`FileChooserExt::current_folder()`][crate::prelude::FileChooserExt::current_folder()],
282 /// [`FileChooserExt::set_current_folder_uri()`][crate::prelude::FileChooserExt::set_current_folder_uri()],
283 /// [`FileChooserExt::current_folder_uri()`][crate::prelude::FileChooserExt::current_folder_uri()].
284 ///
285 ///
286 ///
287 ///
288 /// #### `file-activated`
289 /// This signal is emitted when the user "activates" a file in the file
290 /// chooser. This can happen by double-clicking on a file in the file list, or
291 /// by pressing `Enter`.
292 ///
293 /// Normally you do not need to connect to this signal. It is used internally
294 /// by [`FileChooserDialog`][crate::FileChooserDialog] to know when to activate the default button in the
295 /// dialog.
296 ///
297 /// See also: [`FileChooserExt::filename()`][crate::prelude::FileChooserExt::filename()],
298 /// [`FileChooserExt::filenames()`][crate::prelude::FileChooserExt::filenames()], [`FileChooserExt::uri()`][crate::prelude::FileChooserExt::uri()],
299 /// [`FileChooserExt::uris()`][crate::prelude::FileChooserExt::uris()].
300 ///
301 ///
302 ///
303 ///
304 /// #### `selection-changed`
305 /// This signal is emitted when there is a change in the set of selected files
306 /// in a [`FileChooser`][crate::FileChooser]. This can happen when the user modifies the selection
307 /// with the mouse or the keyboard, or when explicitly calling functions to
308 /// change the selection.
309 ///
310 /// Normally you do not need to connect to this signal, as it is easier to wait
311 /// for the file chooser to finish running, and then to get the list of
312 /// selected files using the functions mentioned below.
313 ///
314 /// See also: [`FileChooserExt::select_filename()`][crate::prelude::FileChooserExt::select_filename()],
315 /// [`FileChooserExt::unselect_filename()`][crate::prelude::FileChooserExt::unselect_filename()], [`FileChooserExt::filename()`][crate::prelude::FileChooserExt::filename()],
316 /// [`FileChooserExt::filenames()`][crate::prelude::FileChooserExt::filenames()], [`FileChooserExt::select_uri()`][crate::prelude::FileChooserExt::select_uri()],
317 /// [`FileChooserExt::unselect_uri()`][crate::prelude::FileChooserExt::unselect_uri()], [`FileChooserExt::uri()`][crate::prelude::FileChooserExt::uri()],
318 /// [`FileChooserExt::uris()`][crate::prelude::FileChooserExt::uris()].
319 ///
320 ///
321 ///
322 ///
323 /// #### `update-preview`
324 /// This signal is emitted when the preview in a file chooser should be
325 /// regenerated. For example, this can happen when the currently selected file
326 /// changes. You should use this signal if you want your file chooser to have
327 /// a preview widget.
328 ///
329 /// Once you have installed a preview widget with
330 /// [`FileChooserExt::set_preview_widget()`][crate::prelude::FileChooserExt::set_preview_widget()], you should update it when this
331 /// signal is emitted. You can use the functions
332 /// [`FileChooserExt::preview_filename()`][crate::prelude::FileChooserExt::preview_filename()] or
333 /// [`FileChooserExt::preview_uri()`][crate::prelude::FileChooserExt::preview_uri()] to get the name of the file to preview.
334 /// Your widget may not be able to preview all kinds of files; your callback
335 /// must call [`FileChooserExt::set_preview_widget_active()`][crate::prelude::FileChooserExt::set_preview_widget_active()] to inform the file
336 /// chooser about whether the preview was generated successfully or not.
337 ///
338 /// Please see the example code in
339 /// [Using a Preview Widget][gtkfilechooser-preview].
340 ///
341 /// See also: [`FileChooserExt::set_preview_widget()`][crate::prelude::FileChooserExt::set_preview_widget()],
342 /// [`FileChooserExt::set_preview_widget_active()`][crate::prelude::FileChooserExt::set_preview_widget_active()],
343 /// [`FileChooserExt::set_use_preview_label()`][crate::prelude::FileChooserExt::set_use_preview_label()],
344 /// [`FileChooserExt::preview_filename()`][crate::prelude::FileChooserExt::preview_filename()],
345 /// [`FileChooserExt::preview_uri()`][crate::prelude::FileChooserExt::preview_uri()].
346 ///
347 ///
348 ///
349 /// # Implements
350 ///
351 /// [`FileChooserExt`][trait@crate::prelude::FileChooserExt], [`FileChooserExtManual`][trait@crate::prelude::FileChooserExtManual]
352 #[doc(alias = "GtkFileChooser")]
353 pub struct FileChooser(Interface<ffi::GtkFileChooser>);
354
355 match fn {
356 type_ => || ffi::gtk_file_chooser_get_type(),
357 }
358}
359
360impl FileChooser {
361 pub const NONE: Option<&'static FileChooser> = None;
362}
363
364mod sealed {
365 pub trait Sealed {}
366 impl<T: super::IsA<super::FileChooser>> Sealed for T {}
367}
368
369/// Trait containing all [`struct@FileChooser`] methods.
370///
371/// # Implementors
372///
373/// [`FileChooserButton`][struct@crate::FileChooserButton], [`FileChooserDialog`][struct@crate::FileChooserDialog], [`FileChooserNative`][struct@crate::FileChooserNative], [`FileChooserWidget`][struct@crate::FileChooserWidget], [`FileChooser`][struct@crate::FileChooser]
374pub trait FileChooserExt: IsA<FileChooser> + sealed::Sealed + 'static {
375 /// Adds `filter` to the list of filters that the user can select between.
376 /// When a filter is selected, only files that are passed by that
377 /// filter are displayed.
378 ///
379 /// Note that the `self` takes ownership of the filter, so you have to
380 /// ref and sink it if you want to keep a reference.
381 /// ## `filter`
382 /// a [`FileFilter`][crate::FileFilter]
383 #[doc(alias = "gtk_file_chooser_add_filter")]
384 fn add_filter(&self, filter: FileFilter) {
385 unsafe {
386 ffi::gtk_file_chooser_add_filter(
387 self.as_ref().to_glib_none().0,
388 filter.into_glib_ptr(),
389 );
390 }
391 }
392
393 /// Adds a folder to be displayed with the shortcut folders in a file chooser.
394 /// Note that shortcut folders do not get saved, as they are provided by the
395 /// application. For example, you can use this to add a
396 /// “/usr/share/mydrawprogram/Clipart” folder to the volume list.
397 /// ## `folder`
398 /// filename of the folder to add
399 ///
400 /// # Returns
401 ///
402 /// [`true`] if the folder could be added successfully, [`false`]
403 /// otherwise. In the latter case, the `error` will be set as appropriate.
404 #[doc(alias = "gtk_file_chooser_add_shortcut_folder")]
405 fn add_shortcut_folder(&self, folder: impl AsRef<std::path::Path>) -> Result<(), glib::Error> {
406 unsafe {
407 let mut error = ptr::null_mut();
408 let is_ok = ffi::gtk_file_chooser_add_shortcut_folder(
409 self.as_ref().to_glib_none().0,
410 folder.as_ref().to_glib_none().0,
411 &mut error,
412 );
413 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
414 if error.is_null() {
415 Ok(())
416 } else {
417 Err(from_glib_full(error))
418 }
419 }
420 }
421
422 /// Adds a folder URI to be displayed with the shortcut folders in a file
423 /// chooser. Note that shortcut folders do not get saved, as they are provided
424 /// by the application. For example, you can use this to add a
425 /// “file:///usr/share/mydrawprogram/Clipart” folder to the volume list.
426 /// ## `uri`
427 /// URI of the folder to add
428 ///
429 /// # Returns
430 ///
431 /// [`true`] if the folder could be added successfully, [`false`]
432 /// otherwise. In the latter case, the `error` will be set as appropriate.
433 #[doc(alias = "gtk_file_chooser_add_shortcut_folder_uri")]
434 fn add_shortcut_folder_uri(&self, uri: &str) -> Result<(), glib::Error> {
435 unsafe {
436 let mut error = ptr::null_mut();
437 let is_ok = ffi::gtk_file_chooser_add_shortcut_folder_uri(
438 self.as_ref().to_glib_none().0,
439 uri.to_glib_none().0,
440 &mut error,
441 );
442 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
443 if error.is_null() {
444 Ok(())
445 } else {
446 Err(from_glib_full(error))
447 }
448 }
449 }
450
451 /// Gets the type of operation that the file chooser is performing; see
452 /// [`set_action()`][Self::set_action()].
453 ///
454 /// # Returns
455 ///
456 /// the action that the file selector is performing
457 #[doc(alias = "gtk_file_chooser_get_action")]
458 #[doc(alias = "get_action")]
459 fn action(&self) -> FileChooserAction {
460 unsafe {
461 from_glib(ffi::gtk_file_chooser_get_action(
462 self.as_ref().to_glib_none().0,
463 ))
464 }
465 }
466
467 /// Gets the currently selected option in the 'choice' with the given ID.
468 /// ## `id`
469 /// the ID of the choice to get
470 ///
471 /// # Returns
472 ///
473 /// the ID of the currenly selected option
474 #[doc(alias = "gtk_file_chooser_get_choice")]
475 #[doc(alias = "get_choice")]
476 fn choice(&self, id: &str) -> Option<glib::GString> {
477 unsafe {
478 from_glib_none(ffi::gtk_file_chooser_get_choice(
479 self.as_ref().to_glib_none().0,
480 id.to_glib_none().0,
481 ))
482 }
483 }
484
485 /// Gets whether file choser will offer to create new folders.
486 /// See [`set_create_folders()`][Self::set_create_folders()].
487 ///
488 /// # Returns
489 ///
490 /// [`true`] if the Create Folder button should be displayed.
491 #[doc(alias = "gtk_file_chooser_get_create_folders")]
492 #[doc(alias = "get_create_folders")]
493 fn creates_folders(&self) -> bool {
494 unsafe {
495 from_glib(ffi::gtk_file_chooser_get_create_folders(
496 self.as_ref().to_glib_none().0,
497 ))
498 }
499 }
500
501 /// Gets the current folder of `self` as a local filename.
502 /// See [`set_current_folder()`][Self::set_current_folder()].
503 ///
504 /// Note that this is the folder that the file chooser is currently displaying
505 /// (e.g. "/home/username/Documents"), which is not the same
506 /// as the currently-selected folder if the chooser is in
507 /// [`FileChooserAction::SelectFolder`][crate::FileChooserAction::SelectFolder] mode
508 /// (e.g. "/home/username/Documents/selected-folder/". To get the
509 /// currently-selected folder in that mode, use [`uri()`][Self::uri()] as the
510 /// usual way to get the selection.
511 ///
512 /// # Returns
513 ///
514 /// the full path of the current
515 /// folder, or [`None`] if the current path cannot be represented as a local
516 /// filename. Free with `g_free()`. This function will also return
517 /// [`None`] if the file chooser was unable to load the last folder that
518 /// was requested from it; for example, as would be for calling
519 /// [`set_current_folder()`][Self::set_current_folder()] on a nonexistent folder.
520 #[doc(alias = "gtk_file_chooser_get_current_folder")]
521 #[doc(alias = "get_current_folder")]
522 fn current_folder(&self) -> Option<std::path::PathBuf> {
523 unsafe {
524 from_glib_full(ffi::gtk_file_chooser_get_current_folder(
525 self.as_ref().to_glib_none().0,
526 ))
527 }
528 }
529
530 /// Gets the current folder of `self` as [`gio::File`][crate::gio::File].
531 /// See [`current_folder_uri()`][Self::current_folder_uri()].
532 ///
533 /// # Returns
534 ///
535 /// the [`gio::File`][crate::gio::File] for the current folder.
536 #[doc(alias = "gtk_file_chooser_get_current_folder_file")]
537 #[doc(alias = "get_current_folder_file")]
538 fn current_folder_file(&self) -> Option<gio::File> {
539 unsafe {
540 from_glib_full(ffi::gtk_file_chooser_get_current_folder_file(
541 self.as_ref().to_glib_none().0,
542 ))
543 }
544 }
545
546 /// Gets the current folder of `self` as an URI.
547 /// See [`set_current_folder_uri()`][Self::set_current_folder_uri()].
548 ///
549 /// Note that this is the folder that the file chooser is currently displaying
550 /// (e.g. "file:///home/username/Documents"), which is not the same
551 /// as the currently-selected folder if the chooser is in
552 /// [`FileChooserAction::SelectFolder`][crate::FileChooserAction::SelectFolder] mode
553 /// (e.g. "file:///home/username/Documents/selected-folder/". To get the
554 /// currently-selected folder in that mode, use [`uri()`][Self::uri()] as the
555 /// usual way to get the selection.
556 ///
557 /// # Returns
558 ///
559 /// the URI for the current folder.
560 /// Free with `g_free()`. This function will also return [`None`] if the file chooser
561 /// was unable to load the last folder that was requested from it; for example,
562 /// as would be for calling [`set_current_folder_uri()`][Self::set_current_folder_uri()] on a
563 /// nonexistent folder.
564 #[doc(alias = "gtk_file_chooser_get_current_folder_uri")]
565 #[doc(alias = "get_current_folder_uri")]
566 fn current_folder_uri(&self) -> Option<glib::GString> {
567 unsafe {
568 from_glib_full(ffi::gtk_file_chooser_get_current_folder_uri(
569 self.as_ref().to_glib_none().0,
570 ))
571 }
572 }
573
574 /// Gets the current name in the file selector, as entered by the user in the
575 /// text entry for “Name”.
576 ///
577 /// This is meant to be used in save dialogs, to get the currently typed filename
578 /// when the file itself does not exist yet. For example, an application that
579 /// adds a custom extra widget to the file chooser for “file format” may want to
580 /// change the extension of the typed filename based on the chosen format, say,
581 /// from “.jpg” to “.png”.
582 ///
583 /// # Returns
584 ///
585 /// The raw text from the file chooser’s “Name” entry. Free this with
586 /// `g_free()`. Note that this string is not a full pathname or URI; it is
587 /// whatever the contents of the entry are. Note also that this string is in
588 /// UTF-8 encoding, which is not necessarily the system’s encoding for filenames.
589 #[doc(alias = "gtk_file_chooser_get_current_name")]
590 #[doc(alias = "get_current_name")]
591 fn current_name(&self) -> Option<glib::GString> {
592 unsafe {
593 from_glib_full(ffi::gtk_file_chooser_get_current_name(
594 self.as_ref().to_glib_none().0,
595 ))
596 }
597 }
598
599 /// Queries whether a file chooser is set to confirm for overwriting when the user
600 /// types a file name that already exists.
601 ///
602 /// # Returns
603 ///
604 /// [`true`] if the file chooser will present a confirmation dialog;
605 /// [`false`] otherwise.
606 #[doc(alias = "gtk_file_chooser_get_do_overwrite_confirmation")]
607 #[doc(alias = "get_do_overwrite_confirmation")]
608 fn does_overwrite_confirmation(&self) -> bool {
609 unsafe {
610 from_glib(ffi::gtk_file_chooser_get_do_overwrite_confirmation(
611 self.as_ref().to_glib_none().0,
612 ))
613 }
614 }
615
616 /// Gets the current extra widget; see
617 /// [`set_extra_widget()`][Self::set_extra_widget()].
618 ///
619 /// # Returns
620 ///
621 /// the current extra widget, or [`None`]
622 #[doc(alias = "gtk_file_chooser_get_extra_widget")]
623 #[doc(alias = "get_extra_widget")]
624 fn extra_widget(&self) -> Option<Widget> {
625 unsafe {
626 from_glib_none(ffi::gtk_file_chooser_get_extra_widget(
627 self.as_ref().to_glib_none().0,
628 ))
629 }
630 }
631
632 /// Gets the [`gio::File`][crate::gio::File] for the currently selected file in
633 /// the file selector. If multiple files are selected,
634 /// one of the files will be returned at random.
635 ///
636 /// If the file chooser is in folder mode, this function returns the selected
637 /// folder.
638 ///
639 /// # Returns
640 ///
641 /// a selected [`gio::File`][crate::gio::File]. You own the returned file;
642 /// use `g_object_unref()` to release it.
643 #[doc(alias = "gtk_file_chooser_get_file")]
644 #[doc(alias = "get_file")]
645 fn file(&self) -> Option<gio::File> {
646 unsafe {
647 from_glib_full(ffi::gtk_file_chooser_get_file(
648 self.as_ref().to_glib_none().0,
649 ))
650 }
651 }
652
653 /// Gets the filename for the currently selected file in
654 /// the file selector. The filename is returned as an absolute path. If
655 /// multiple files are selected, one of the filenames will be returned at
656 /// random.
657 ///
658 /// If the file chooser is in folder mode, this function returns the selected
659 /// folder.
660 ///
661 /// # Returns
662 ///
663 /// The currently selected filename,
664 /// or [`None`] if no file is selected, or the selected file can't
665 /// be represented with a local filename. Free with `g_free()`.
666 #[doc(alias = "gtk_file_chooser_get_filename")]
667 #[doc(alias = "get_filename")]
668 fn filename(&self) -> Option<std::path::PathBuf> {
669 unsafe {
670 from_glib_full(ffi::gtk_file_chooser_get_filename(
671 self.as_ref().to_glib_none().0,
672 ))
673 }
674 }
675
676 /// Lists all the selected files and subfolders in the current folder of
677 /// `self`. The returned names are full absolute paths. If files in the current
678 /// folder cannot be represented as local filenames they will be ignored. (See
679 /// [`uris()`][Self::uris()])
680 ///
681 /// # Returns
682 ///
683 /// a `GSList`
684 /// containing the filenames of all selected files and subfolders in
685 /// the current folder. Free the returned list with `g_slist_free()`,
686 /// and the filenames with `g_free()`.
687 #[doc(alias = "gtk_file_chooser_get_filenames")]
688 #[doc(alias = "get_filenames")]
689 fn filenames(&self) -> Vec<std::path::PathBuf> {
690 unsafe {
691 FromGlibPtrContainer::from_glib_full(ffi::gtk_file_chooser_get_filenames(
692 self.as_ref().to_glib_none().0,
693 ))
694 }
695 }
696
697 /// Lists all the selected files and subfolders in the current folder of `self`
698 /// as [`gio::File`][crate::gio::File]. An internal function, see [`uris()`][Self::uris()].
699 ///
700 /// # Returns
701 ///
702 /// a `GSList`
703 /// containing a [`gio::File`][crate::gio::File] for each selected file and subfolder in the
704 /// current folder. Free the returned list with `g_slist_free()`, and
705 /// the files with `g_object_unref()`.
706 #[doc(alias = "gtk_file_chooser_get_files")]
707 #[doc(alias = "get_files")]
708 fn files(&self) -> Vec<gio::File> {
709 unsafe {
710 FromGlibPtrContainer::from_glib_full(ffi::gtk_file_chooser_get_files(
711 self.as_ref().to_glib_none().0,
712 ))
713 }
714 }
715
716 /// Gets the current filter; see [`set_filter()`][Self::set_filter()].
717 ///
718 /// # Returns
719 ///
720 /// the current filter, or [`None`]
721 #[doc(alias = "gtk_file_chooser_get_filter")]
722 #[doc(alias = "get_filter")]
723 fn filter(&self) -> Option<FileFilter> {
724 unsafe {
725 from_glib_none(ffi::gtk_file_chooser_get_filter(
726 self.as_ref().to_glib_none().0,
727 ))
728 }
729 }
730
731 /// Gets whether only local files can be selected in the
732 /// file selector. See [`set_local_only()`][Self::set_local_only()]
733 ///
734 /// # Returns
735 ///
736 /// [`true`] if only local files can be selected.
737 #[doc(alias = "gtk_file_chooser_get_local_only")]
738 #[doc(alias = "get_local_only")]
739 fn is_local_only(&self) -> bool {
740 unsafe {
741 from_glib(ffi::gtk_file_chooser_get_local_only(
742 self.as_ref().to_glib_none().0,
743 ))
744 }
745 }
746
747 /// Gets the [`gio::File`][crate::gio::File] that should be previewed in a custom preview
748 /// Internal function, see [`preview_uri()`][Self::preview_uri()].
749 ///
750 /// # Returns
751 ///
752 /// the [`gio::File`][crate::gio::File] for the file to preview,
753 /// or [`None`] if no file is selected. Free with `g_object_unref()`.
754 #[doc(alias = "gtk_file_chooser_get_preview_file")]
755 #[doc(alias = "get_preview_file")]
756 fn preview_file(&self) -> Option<gio::File> {
757 unsafe {
758 from_glib_full(ffi::gtk_file_chooser_get_preview_file(
759 self.as_ref().to_glib_none().0,
760 ))
761 }
762 }
763
764 /// Gets the filename that should be previewed in a custom preview
765 /// widget. See [`set_preview_widget()`][Self::set_preview_widget()].
766 ///
767 /// # Returns
768 ///
769 /// the filename to preview, or [`None`] if
770 /// no file is selected, or if the selected file cannot be represented
771 /// as a local filename. Free with `g_free()`
772 #[doc(alias = "gtk_file_chooser_get_preview_filename")]
773 #[doc(alias = "get_preview_filename")]
774 fn preview_filename(&self) -> Option<std::path::PathBuf> {
775 unsafe {
776 from_glib_full(ffi::gtk_file_chooser_get_preview_filename(
777 self.as_ref().to_glib_none().0,
778 ))
779 }
780 }
781
782 /// Gets the URI that should be previewed in a custom preview
783 /// widget. See [`set_preview_widget()`][Self::set_preview_widget()].
784 ///
785 /// # Returns
786 ///
787 /// the URI for the file to preview,
788 /// or [`None`] if no file is selected. Free with `g_free()`.
789 #[doc(alias = "gtk_file_chooser_get_preview_uri")]
790 #[doc(alias = "get_preview_uri")]
791 fn preview_uri(&self) -> Option<glib::GString> {
792 unsafe {
793 from_glib_full(ffi::gtk_file_chooser_get_preview_uri(
794 self.as_ref().to_glib_none().0,
795 ))
796 }
797 }
798
799 /// Gets the current preview widget; see
800 /// [`set_preview_widget()`][Self::set_preview_widget()].
801 ///
802 /// # Returns
803 ///
804 /// the current preview widget, or [`None`]
805 #[doc(alias = "gtk_file_chooser_get_preview_widget")]
806 #[doc(alias = "get_preview_widget")]
807 fn preview_widget(&self) -> Option<Widget> {
808 unsafe {
809 from_glib_none(ffi::gtk_file_chooser_get_preview_widget(
810 self.as_ref().to_glib_none().0,
811 ))
812 }
813 }
814
815 /// Gets whether the preview widget set by [`set_preview_widget()`][Self::set_preview_widget()]
816 /// should be shown for the current filename. See
817 /// [`set_preview_widget_active()`][Self::set_preview_widget_active()].
818 ///
819 /// # Returns
820 ///
821 /// [`true`] if the preview widget is active for the current filename.
822 #[doc(alias = "gtk_file_chooser_get_preview_widget_active")]
823 #[doc(alias = "get_preview_widget_active")]
824 fn is_preview_widget_active(&self) -> bool {
825 unsafe {
826 from_glib(ffi::gtk_file_chooser_get_preview_widget_active(
827 self.as_ref().to_glib_none().0,
828 ))
829 }
830 }
831
832 /// Gets whether multiple files can be selected in the file
833 /// selector. See [`set_select_multiple()`][Self::set_select_multiple()].
834 ///
835 /// # Returns
836 ///
837 /// [`true`] if multiple files can be selected.
838 #[doc(alias = "gtk_file_chooser_get_select_multiple")]
839 #[doc(alias = "get_select_multiple")]
840 fn selects_multiple(&self) -> bool {
841 unsafe {
842 from_glib(ffi::gtk_file_chooser_get_select_multiple(
843 self.as_ref().to_glib_none().0,
844 ))
845 }
846 }
847
848 /// Gets whether hidden files and folders are displayed in the file selector.
849 /// See [`set_show_hidden()`][Self::set_show_hidden()].
850 ///
851 /// # Returns
852 ///
853 /// [`true`] if hidden files and folders are displayed.
854 #[doc(alias = "gtk_file_chooser_get_show_hidden")]
855 #[doc(alias = "get_show_hidden")]
856 fn shows_hidden(&self) -> bool {
857 unsafe {
858 from_glib(ffi::gtk_file_chooser_get_show_hidden(
859 self.as_ref().to_glib_none().0,
860 ))
861 }
862 }
863
864 /// Gets the URI for the currently selected file in
865 /// the file selector. If multiple files are selected,
866 /// one of the filenames will be returned at random.
867 ///
868 /// If the file chooser is in folder mode, this function returns the selected
869 /// folder.
870 ///
871 /// # Returns
872 ///
873 /// The currently selected URI, or [`None`]
874 /// if no file is selected. If [`set_local_only()`][Self::set_local_only()] is set to
875 /// [`true`] (the default) a local URI will be returned for any FUSE locations.
876 /// Free with `g_free()`
877 #[doc(alias = "gtk_file_chooser_get_uri")]
878 #[doc(alias = "get_uri")]
879 fn uri(&self) -> Option<glib::GString> {
880 unsafe {
881 from_glib_full(ffi::gtk_file_chooser_get_uri(
882 self.as_ref().to_glib_none().0,
883 ))
884 }
885 }
886
887 /// Lists all the selected files and subfolders in the current folder of
888 /// `self`. The returned names are full absolute URIs.
889 ///
890 /// # Returns
891 ///
892 /// a `GSList` containing the URIs of all selected
893 /// files and subfolders in the current folder. Free the returned list
894 /// with `g_slist_free()`, and the filenames with `g_free()`.
895 #[doc(alias = "gtk_file_chooser_get_uris")]
896 #[doc(alias = "get_uris")]
897 fn uris(&self) -> Vec<glib::GString> {
898 unsafe {
899 FromGlibPtrContainer::from_glib_full(ffi::gtk_file_chooser_get_uris(
900 self.as_ref().to_glib_none().0,
901 ))
902 }
903 }
904
905 /// Gets whether a stock label should be drawn with the name of the previewed
906 /// file. See [`set_use_preview_label()`][Self::set_use_preview_label()].
907 ///
908 /// # Returns
909 ///
910 /// [`true`] if the file chooser is set to display a label with the
911 /// name of the previewed file, [`false`] otherwise.
912 #[doc(alias = "gtk_file_chooser_get_use_preview_label")]
913 #[doc(alias = "get_use_preview_label")]
914 fn uses_preview_label(&self) -> bool {
915 unsafe {
916 from_glib(ffi::gtk_file_chooser_get_use_preview_label(
917 self.as_ref().to_glib_none().0,
918 ))
919 }
920 }
921
922 /// Lists the current set of user-selectable filters; see
923 /// [`add_filter()`][Self::add_filter()], [`remove_filter()`][Self::remove_filter()].
924 ///
925 /// # Returns
926 ///
927 /// a
928 /// `GSList` containing the current set of user selectable filters. The
929 /// contents of the list are owned by GTK+, but you must free the list
930 /// itself with `g_slist_free()` when you are done with it.
931 #[doc(alias = "gtk_file_chooser_list_filters")]
932 fn list_filters(&self) -> Vec<FileFilter> {
933 unsafe {
934 FromGlibPtrContainer::from_glib_container(ffi::gtk_file_chooser_list_filters(
935 self.as_ref().to_glib_none().0,
936 ))
937 }
938 }
939
940 /// Queries the list of shortcut folders in the file chooser, as set by
941 /// [`add_shortcut_folder_uri()`][Self::add_shortcut_folder_uri()].
942 ///
943 /// # Returns
944 ///
945 /// A list of
946 /// folder URIs, or [`None`] if there are no shortcut folders. Free the
947 /// returned list with `g_slist_free()`, and the URIs with `g_free()`.
948 #[doc(alias = "gtk_file_chooser_list_shortcut_folder_uris")]
949 fn list_shortcut_folder_uris(&self) -> Vec<glib::GString> {
950 unsafe {
951 FromGlibPtrContainer::from_glib_full(ffi::gtk_file_chooser_list_shortcut_folder_uris(
952 self.as_ref().to_glib_none().0,
953 ))
954 }
955 }
956
957 /// Queries the list of shortcut folders in the file chooser, as set by
958 /// [`add_shortcut_folder()`][Self::add_shortcut_folder()].
959 ///
960 /// # Returns
961 ///
962 /// A list
963 /// of folder filenames, or [`None`] if there are no shortcut folders.
964 /// Free the returned list with `g_slist_free()`, and the filenames with
965 /// `g_free()`.
966 #[doc(alias = "gtk_file_chooser_list_shortcut_folders")]
967 fn list_shortcut_folders(&self) -> Vec<std::path::PathBuf> {
968 unsafe {
969 FromGlibPtrContainer::from_glib_full(ffi::gtk_file_chooser_list_shortcut_folders(
970 self.as_ref().to_glib_none().0,
971 ))
972 }
973 }
974
975 /// Removes a 'choice' that has been added with [`FileChooserExtManual::add_choice()`][crate::prelude::FileChooserExtManual::add_choice()].
976 /// ## `id`
977 /// the ID of the choice to remove
978 #[doc(alias = "gtk_file_chooser_remove_choice")]
979 fn remove_choice(&self, id: &str) {
980 unsafe {
981 ffi::gtk_file_chooser_remove_choice(
982 self.as_ref().to_glib_none().0,
983 id.to_glib_none().0,
984 );
985 }
986 }
987
988 /// Removes `filter` from the list of filters that the user can select between.
989 /// ## `filter`
990 /// a [`FileFilter`][crate::FileFilter]
991 #[doc(alias = "gtk_file_chooser_remove_filter")]
992 fn remove_filter(&self, filter: &FileFilter) {
993 unsafe {
994 ffi::gtk_file_chooser_remove_filter(
995 self.as_ref().to_glib_none().0,
996 filter.to_glib_none().0,
997 );
998 }
999 }
1000
1001 /// Removes a folder from a file chooser’s list of shortcut folders.
1002 /// ## `folder`
1003 /// filename of the folder to remove
1004 ///
1005 /// # Returns
1006 ///
1007 /// [`true`] if the operation succeeds, [`false`] otherwise.
1008 /// In the latter case, the `error` will be set as appropriate.
1009 ///
1010 /// See also: [`add_shortcut_folder()`][Self::add_shortcut_folder()]
1011 #[doc(alias = "gtk_file_chooser_remove_shortcut_folder")]
1012 fn remove_shortcut_folder(
1013 &self,
1014 folder: impl AsRef<std::path::Path>,
1015 ) -> Result<(), glib::Error> {
1016 unsafe {
1017 let mut error = ptr::null_mut();
1018 let is_ok = ffi::gtk_file_chooser_remove_shortcut_folder(
1019 self.as_ref().to_glib_none().0,
1020 folder.as_ref().to_glib_none().0,
1021 &mut error,
1022 );
1023 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
1024 if error.is_null() {
1025 Ok(())
1026 } else {
1027 Err(from_glib_full(error))
1028 }
1029 }
1030 }
1031
1032 /// Removes a folder URI from a file chooser’s list of shortcut folders.
1033 /// ## `uri`
1034 /// URI of the folder to remove
1035 ///
1036 /// # Returns
1037 ///
1038 /// [`true`] if the operation succeeds, [`false`] otherwise.
1039 /// In the latter case, the `error` will be set as appropriate.
1040 ///
1041 /// See also: [`add_shortcut_folder_uri()`][Self::add_shortcut_folder_uri()]
1042 #[doc(alias = "gtk_file_chooser_remove_shortcut_folder_uri")]
1043 fn remove_shortcut_folder_uri(&self, uri: &str) -> Result<(), glib::Error> {
1044 unsafe {
1045 let mut error = ptr::null_mut();
1046 let is_ok = ffi::gtk_file_chooser_remove_shortcut_folder_uri(
1047 self.as_ref().to_glib_none().0,
1048 uri.to_glib_none().0,
1049 &mut error,
1050 );
1051 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
1052 if error.is_null() {
1053 Ok(())
1054 } else {
1055 Err(from_glib_full(error))
1056 }
1057 }
1058 }
1059
1060 /// Selects all the files in the current folder of a file chooser.
1061 #[doc(alias = "gtk_file_chooser_select_all")]
1062 fn select_all(&self) {
1063 unsafe {
1064 ffi::gtk_file_chooser_select_all(self.as_ref().to_glib_none().0);
1065 }
1066 }
1067
1068 /// Selects the file referred to by `file`. An internal function. See
1069 /// `_gtk_file_chooser_select_uri()`.
1070 /// ## `file`
1071 /// the file to select
1072 ///
1073 /// # Returns
1074 ///
1075 /// Not useful.
1076 #[doc(alias = "gtk_file_chooser_select_file")]
1077 fn select_file(&self, file: &impl IsA<gio::File>) -> Result<(), glib::Error> {
1078 unsafe {
1079 let mut error = ptr::null_mut();
1080 let is_ok = ffi::gtk_file_chooser_select_file(
1081 self.as_ref().to_glib_none().0,
1082 file.as_ref().to_glib_none().0,
1083 &mut error,
1084 );
1085 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
1086 if error.is_null() {
1087 Ok(())
1088 } else {
1089 Err(from_glib_full(error))
1090 }
1091 }
1092 }
1093
1094 /// Selects a filename. If the file name isn’t in the current
1095 /// folder of `self`, then the current folder of `self` will
1096 /// be changed to the folder containing `filename`.
1097 /// ## `filename`
1098 /// the filename to select
1099 ///
1100 /// # Returns
1101 ///
1102 /// Not useful.
1103 ///
1104 /// See also: [`set_filename()`][Self::set_filename()]
1105 #[doc(alias = "gtk_file_chooser_select_filename")]
1106 fn select_filename(&self, filename: impl AsRef<std::path::Path>) -> bool {
1107 unsafe {
1108 from_glib(ffi::gtk_file_chooser_select_filename(
1109 self.as_ref().to_glib_none().0,
1110 filename.as_ref().to_glib_none().0,
1111 ))
1112 }
1113 }
1114
1115 /// Selects the file to by `uri`. If the URI doesn’t refer to a
1116 /// file in the current folder of `self`, then the current folder of
1117 /// `self` will be changed to the folder containing `filename`.
1118 /// ## `uri`
1119 /// the URI to select
1120 ///
1121 /// # Returns
1122 ///
1123 /// Not useful.
1124 #[doc(alias = "gtk_file_chooser_select_uri")]
1125 fn select_uri(&self, uri: &str) -> bool {
1126 unsafe {
1127 from_glib(ffi::gtk_file_chooser_select_uri(
1128 self.as_ref().to_glib_none().0,
1129 uri.to_glib_none().0,
1130 ))
1131 }
1132 }
1133
1134 /// Sets the type of operation that the chooser is performing; the
1135 /// user interface is adapted to suit the selected action. For example,
1136 /// an option to create a new folder might be shown if the action is
1137 /// [`FileChooserAction::Save`][crate::FileChooserAction::Save] but not if the action is
1138 /// [`FileChooserAction::Open`][crate::FileChooserAction::Open].
1139 /// ## `action`
1140 /// the action that the file selector is performing
1141 #[doc(alias = "gtk_file_chooser_set_action")]
1142 fn set_action(&self, action: FileChooserAction) {
1143 unsafe {
1144 ffi::gtk_file_chooser_set_action(self.as_ref().to_glib_none().0, action.into_glib());
1145 }
1146 }
1147
1148 /// Selects an option in a 'choice' that has been added with
1149 /// [`FileChooserExtManual::add_choice()`][crate::prelude::FileChooserExtManual::add_choice()]. For a boolean choice, the
1150 /// possible options are "true" and "false".
1151 /// ## `id`
1152 /// the ID of the choice to set
1153 /// ## `option`
1154 /// the ID of the option to select
1155 #[doc(alias = "gtk_file_chooser_set_choice")]
1156 fn set_choice(&self, id: &str, option: &str) {
1157 unsafe {
1158 ffi::gtk_file_chooser_set_choice(
1159 self.as_ref().to_glib_none().0,
1160 id.to_glib_none().0,
1161 option.to_glib_none().0,
1162 );
1163 }
1164 }
1165
1166 /// Sets whether file choser will offer to create new folders.
1167 /// This is only relevant if the action is not set to be
1168 /// [`FileChooserAction::Open`][crate::FileChooserAction::Open].
1169 /// ## `create_folders`
1170 /// [`true`] if the Create Folder button should be displayed
1171 #[doc(alias = "gtk_file_chooser_set_create_folders")]
1172 fn set_create_folders(&self, create_folders: bool) {
1173 unsafe {
1174 ffi::gtk_file_chooser_set_create_folders(
1175 self.as_ref().to_glib_none().0,
1176 create_folders.into_glib(),
1177 );
1178 }
1179 }
1180
1181 /// Sets the current folder for `self` from a local filename.
1182 /// The user will be shown the full contents of the current folder,
1183 /// plus user interface elements for navigating to other folders.
1184 ///
1185 /// In general, you should not use this function. See the
1186 /// [section on setting up a file chooser dialog][gtkfilechooserdialog-setting-up]
1187 /// for the rationale behind this.
1188 /// ## `filename`
1189 /// the full path of the new current folder
1190 ///
1191 /// # Returns
1192 ///
1193 /// Not useful.
1194 #[doc(alias = "gtk_file_chooser_set_current_folder")]
1195 fn set_current_folder(&self, filename: impl AsRef<std::path::Path>) -> bool {
1196 unsafe {
1197 from_glib(ffi::gtk_file_chooser_set_current_folder(
1198 self.as_ref().to_glib_none().0,
1199 filename.as_ref().to_glib_none().0,
1200 ))
1201 }
1202 }
1203
1204 /// Sets the current folder for `self` from a [`gio::File`][crate::gio::File].
1205 /// Internal function, see [`set_current_folder_uri()`][Self::set_current_folder_uri()].
1206 /// ## `file`
1207 /// the [`gio::File`][crate::gio::File] for the new folder
1208 ///
1209 /// # Returns
1210 ///
1211 /// [`true`] if the folder could be changed successfully, [`false`]
1212 /// otherwise.
1213 #[doc(alias = "gtk_file_chooser_set_current_folder_file")]
1214 fn set_current_folder_file(&self, file: &impl IsA<gio::File>) -> Result<(), glib::Error> {
1215 unsafe {
1216 let mut error = ptr::null_mut();
1217 let is_ok = ffi::gtk_file_chooser_set_current_folder_file(
1218 self.as_ref().to_glib_none().0,
1219 file.as_ref().to_glib_none().0,
1220 &mut error,
1221 );
1222 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
1223 if error.is_null() {
1224 Ok(())
1225 } else {
1226 Err(from_glib_full(error))
1227 }
1228 }
1229 }
1230
1231 /// Sets the current folder for `self` from an URI.
1232 /// The user will be shown the full contents of the current folder,
1233 /// plus user interface elements for navigating to other folders.
1234 ///
1235 /// In general, you should not use this function. See the
1236 /// [section on setting up a file chooser dialog][gtkfilechooserdialog-setting-up]
1237 /// for the rationale behind this.
1238 /// ## `uri`
1239 /// the URI for the new current folder
1240 ///
1241 /// # Returns
1242 ///
1243 /// [`true`] if the folder could be changed successfully, [`false`]
1244 /// otherwise.
1245 #[doc(alias = "gtk_file_chooser_set_current_folder_uri")]
1246 fn set_current_folder_uri(&self, uri: &str) -> bool {
1247 unsafe {
1248 from_glib(ffi::gtk_file_chooser_set_current_folder_uri(
1249 self.as_ref().to_glib_none().0,
1250 uri.to_glib_none().0,
1251 ))
1252 }
1253 }
1254
1255 /// Sets the current name in the file selector, as if entered
1256 /// by the user. Note that the name passed in here is a UTF-8
1257 /// string rather than a filename. This function is meant for
1258 /// such uses as a suggested name in a “Save As...” dialog. You can
1259 /// pass “Untitled.doc” or a similarly suitable suggestion for the `name`.
1260 ///
1261 /// If you want to preselect a particular existing file, you should use
1262 /// [`set_filename()`][Self::set_filename()] or [`set_uri()`][Self::set_uri()] instead.
1263 /// Please see the documentation for those functions for an example of using
1264 /// [`set_current_name()`][Self::set_current_name()] as well.
1265 /// ## `name`
1266 /// the filename to use, as a UTF-8 string
1267 #[doc(alias = "gtk_file_chooser_set_current_name")]
1268 fn set_current_name(&self, name: &str) {
1269 unsafe {
1270 ffi::gtk_file_chooser_set_current_name(
1271 self.as_ref().to_glib_none().0,
1272 name.to_glib_none().0,
1273 );
1274 }
1275 }
1276
1277 /// Sets whether a file chooser in [`FileChooserAction::Save`][crate::FileChooserAction::Save] mode will present
1278 /// a confirmation dialog if the user types a file name that already exists. This
1279 /// is [`false`] by default.
1280 ///
1281 /// If set to [`true`], the `self` will emit the
1282 /// [`confirm-overwrite`][struct@crate::FileChooser#confirm-overwrite] signal when appropriate.
1283 ///
1284 /// If all you need is the stock confirmation dialog, set this property to [`true`].
1285 /// You can override the way confirmation is done by actually handling the
1286 /// [`confirm-overwrite`][struct@crate::FileChooser#confirm-overwrite] signal; please refer to its documentation
1287 /// for the details.
1288 /// ## `do_overwrite_confirmation`
1289 /// whether to confirm overwriting in save mode
1290 #[doc(alias = "gtk_file_chooser_set_do_overwrite_confirmation")]
1291 fn set_do_overwrite_confirmation(&self, do_overwrite_confirmation: bool) {
1292 unsafe {
1293 ffi::gtk_file_chooser_set_do_overwrite_confirmation(
1294 self.as_ref().to_glib_none().0,
1295 do_overwrite_confirmation.into_glib(),
1296 );
1297 }
1298 }
1299
1300 /// Sets an application-supplied widget to provide extra options to the user.
1301 /// ## `extra_widget`
1302 /// widget for extra options
1303 #[doc(alias = "gtk_file_chooser_set_extra_widget")]
1304 fn set_extra_widget(&self, extra_widget: &impl IsA<Widget>) {
1305 unsafe {
1306 ffi::gtk_file_chooser_set_extra_widget(
1307 self.as_ref().to_glib_none().0,
1308 extra_widget.as_ref().to_glib_none().0,
1309 );
1310 }
1311 }
1312
1313 /// Sets `file` as the current filename for the file chooser, by changing
1314 /// to the file’s parent folder and actually selecting the file in list. If
1315 /// the `self` is in [`FileChooserAction::Save`][crate::FileChooserAction::Save] mode, the file’s base name
1316 /// will also appear in the dialog’s file name entry.
1317 ///
1318 /// If the file name isn’t in the current folder of `self`, then the current
1319 /// folder of `self` will be changed to the folder containing `filename`. This
1320 /// is equivalent to a sequence of [`unselect_all()`][Self::unselect_all()] followed by
1321 /// [`select_filename()`][Self::select_filename()].
1322 ///
1323 /// Note that the file must exist, or nothing will be done except
1324 /// for the directory change.
1325 ///
1326 /// If you are implementing a save dialog,
1327 /// you should use this function if you already have a file name to which the
1328 /// user may save; for example, when the user opens an existing file and then
1329 /// does Save As... If you don’t have
1330 /// a file name already — for example, if the user just created a new
1331 /// file and is saving it for the first time, do not call this function.
1332 /// Instead, use something similar to this:
1333 ///
1334 ///
1335 /// **⚠️ The following code is in C ⚠️**
1336 ///
1337 /// ```C
1338 /// if (document_is_new)
1339 /// {
1340 /// // the user just created a new document
1341 /// gtk_file_chooser_set_current_folder_file (chooser, default_file_for_saving);
1342 /// gtk_file_chooser_set_current_name (chooser, "Untitled document");
1343 /// }
1344 /// else
1345 /// {
1346 /// // the user edited an existing document
1347 /// gtk_file_chooser_set_file (chooser, existing_file);
1348 /// }
1349 /// ```
1350 /// ## `file`
1351 /// the [`gio::File`][crate::gio::File] to set as current
1352 ///
1353 /// # Returns
1354 ///
1355 /// Not useful.
1356 #[doc(alias = "gtk_file_chooser_set_file")]
1357 fn set_file(&self, file: &impl IsA<gio::File>) -> Result<(), glib::Error> {
1358 unsafe {
1359 let mut error = ptr::null_mut();
1360 let is_ok = ffi::gtk_file_chooser_set_file(
1361 self.as_ref().to_glib_none().0,
1362 file.as_ref().to_glib_none().0,
1363 &mut error,
1364 );
1365 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
1366 if error.is_null() {
1367 Ok(())
1368 } else {
1369 Err(from_glib_full(error))
1370 }
1371 }
1372 }
1373
1374 /// Sets `filename` as the current filename for the file chooser, by changing to
1375 /// the file’s parent folder and actually selecting the file in list; all other
1376 /// files will be unselected. If the `self` is in
1377 /// [`FileChooserAction::Save`][crate::FileChooserAction::Save] mode, the file’s base name will also appear in
1378 /// the dialog’s file name entry.
1379 ///
1380 /// Note that the file must exist, or nothing will be done except
1381 /// for the directory change.
1382 ///
1383 /// You should use this function only when implementing a save
1384 /// dialog for which you already have a file name to which
1385 /// the user may save. For example, when the user opens an existing file and
1386 /// then does Save As... to save a copy or
1387 /// a modified version. If you don’t have a file name already — for
1388 /// example, if the user just created a new file and is saving it for the first
1389 /// time, do not call this function. Instead, use something similar to this:
1390 ///
1391 ///
1392 /// **⚠️ The following code is in C ⚠️**
1393 ///
1394 /// ```C
1395 /// if (document_is_new)
1396 /// {
1397 /// // the user just created a new document
1398 /// gtk_file_chooser_set_current_name (chooser, "Untitled document");
1399 /// }
1400 /// else
1401 /// {
1402 /// // the user edited an existing document
1403 /// gtk_file_chooser_set_filename (chooser, existing_filename);
1404 /// }
1405 /// ```
1406 ///
1407 /// In the first case, the file chooser will present the user with useful suggestions
1408 /// as to where to save his new file. In the second case, the file’s existing location
1409 /// is already known, so the file chooser will use it.
1410 /// ## `filename`
1411 /// the filename to set as current
1412 ///
1413 /// # Returns
1414 ///
1415 /// Not useful.
1416 #[doc(alias = "gtk_file_chooser_set_filename")]
1417 fn set_filename(&self, filename: impl AsRef<std::path::Path>) -> bool {
1418 unsafe {
1419 from_glib(ffi::gtk_file_chooser_set_filename(
1420 self.as_ref().to_glib_none().0,
1421 filename.as_ref().to_glib_none().0,
1422 ))
1423 }
1424 }
1425
1426 /// Sets the current filter; only the files that pass the
1427 /// filter will be displayed. If the user-selectable list of filters
1428 /// is non-empty, then the filter should be one of the filters
1429 /// in that list. Setting the current filter when the list of
1430 /// filters is empty is useful if you want to restrict the displayed
1431 /// set of files without letting the user change it.
1432 /// ## `filter`
1433 /// a [`FileFilter`][crate::FileFilter]
1434 #[doc(alias = "gtk_file_chooser_set_filter")]
1435 fn set_filter(&self, filter: &FileFilter) {
1436 unsafe {
1437 ffi::gtk_file_chooser_set_filter(
1438 self.as_ref().to_glib_none().0,
1439 filter.to_glib_none().0,
1440 );
1441 }
1442 }
1443
1444 /// Sets whether only local files can be selected in the
1445 /// file selector. If `local_only` is [`true`] (the default),
1446 /// then the selected file or files are guaranteed to be
1447 /// accessible through the operating systems native file
1448 /// system and therefore the application only
1449 /// needs to worry about the filename functions in
1450 /// [`FileChooser`][crate::FileChooser], like [`filename()`][Self::filename()],
1451 /// rather than the URI functions like
1452 /// [`uri()`][Self::uri()],
1453 ///
1454 /// On some systems non-native files may still be
1455 /// available using the native filesystem via a userspace
1456 /// filesystem (FUSE).
1457 /// ## `local_only`
1458 /// [`true`] if only local files can be selected
1459 #[doc(alias = "gtk_file_chooser_set_local_only")]
1460 fn set_local_only(&self, local_only: bool) {
1461 unsafe {
1462 ffi::gtk_file_chooser_set_local_only(
1463 self.as_ref().to_glib_none().0,
1464 local_only.into_glib(),
1465 );
1466 }
1467 }
1468
1469 /// Sets an application-supplied widget to use to display a custom preview
1470 /// of the currently selected file. To implement a preview, after setting the
1471 /// preview widget, you connect to the [`update-preview`][struct@crate::FileChooser#update-preview]
1472 /// signal, and call [`preview_filename()`][Self::preview_filename()] or
1473 /// [`preview_uri()`][Self::preview_uri()] on each change. If you can
1474 /// display a preview of the new file, update your widget and
1475 /// set the preview active using [`set_preview_widget_active()`][Self::set_preview_widget_active()].
1476 /// Otherwise, set the preview inactive.
1477 ///
1478 /// When there is no application-supplied preview widget, or the
1479 /// application-supplied preview widget is not active, the file chooser
1480 /// will display no preview at all.
1481 /// ## `preview_widget`
1482 /// widget for displaying preview.
1483 #[doc(alias = "gtk_file_chooser_set_preview_widget")]
1484 fn set_preview_widget(&self, preview_widget: &impl IsA<Widget>) {
1485 unsafe {
1486 ffi::gtk_file_chooser_set_preview_widget(
1487 self.as_ref().to_glib_none().0,
1488 preview_widget.as_ref().to_glib_none().0,
1489 );
1490 }
1491 }
1492
1493 /// Sets whether the preview widget set by
1494 /// [`set_preview_widget()`][Self::set_preview_widget()] should be shown for the
1495 /// current filename. When `active` is set to false, the file chooser
1496 /// may display an internally generated preview of the current file
1497 /// or it may display no preview at all. See
1498 /// [`set_preview_widget()`][Self::set_preview_widget()] for more details.
1499 /// ## `active`
1500 /// whether to display the user-specified preview widget
1501 #[doc(alias = "gtk_file_chooser_set_preview_widget_active")]
1502 fn set_preview_widget_active(&self, active: bool) {
1503 unsafe {
1504 ffi::gtk_file_chooser_set_preview_widget_active(
1505 self.as_ref().to_glib_none().0,
1506 active.into_glib(),
1507 );
1508 }
1509 }
1510
1511 /// Sets whether multiple files can be selected in the file selector. This is
1512 /// only relevant if the action is set to be [`FileChooserAction::Open`][crate::FileChooserAction::Open] or
1513 /// [`FileChooserAction::SelectFolder`][crate::FileChooserAction::SelectFolder].
1514 /// ## `select_multiple`
1515 /// [`true`] if multiple files can be selected.
1516 #[doc(alias = "gtk_file_chooser_set_select_multiple")]
1517 fn set_select_multiple(&self, select_multiple: bool) {
1518 unsafe {
1519 ffi::gtk_file_chooser_set_select_multiple(
1520 self.as_ref().to_glib_none().0,
1521 select_multiple.into_glib(),
1522 );
1523 }
1524 }
1525
1526 /// Sets whether hidden files and folders are displayed in the file selector.
1527 /// ## `show_hidden`
1528 /// [`true`] if hidden files and folders should be displayed.
1529 #[doc(alias = "gtk_file_chooser_set_show_hidden")]
1530 fn set_show_hidden(&self, show_hidden: bool) {
1531 unsafe {
1532 ffi::gtk_file_chooser_set_show_hidden(
1533 self.as_ref().to_glib_none().0,
1534 show_hidden.into_glib(),
1535 );
1536 }
1537 }
1538
1539 /// Sets the file referred to by `uri` as the current file for the file chooser,
1540 /// by changing to the URI’s parent folder and actually selecting the URI in the
1541 /// list. If the `self` is [`FileChooserAction::Save`][crate::FileChooserAction::Save] mode, the URI’s base
1542 /// name will also appear in the dialog’s file name entry.
1543 ///
1544 /// Note that the URI must exist, or nothing will be done except for the
1545 /// directory change.
1546 ///
1547 /// You should use this function only when implementing a save
1548 /// dialog for which you already have a file name to which
1549 /// the user may save. For example, when the user opens an existing file and then
1550 /// does Save As... to save a copy or a
1551 /// modified version. If you don’t have a file name already — for example,
1552 /// if the user just created a new file and is saving it for the first time, do
1553 /// not call this function. Instead, use something similar to this:
1554 ///
1555 ///
1556 /// **⚠️ The following code is in C ⚠️**
1557 ///
1558 /// ```C
1559 /// if (document_is_new)
1560 /// {
1561 /// // the user just created a new document
1562 /// gtk_file_chooser_set_current_name (chooser, "Untitled document");
1563 /// }
1564 /// else
1565 /// {
1566 /// // the user edited an existing document
1567 /// gtk_file_chooser_set_uri (chooser, existing_uri);
1568 /// }
1569 /// ```
1570 ///
1571 ///
1572 /// In the first case, the file chooser will present the user with useful suggestions
1573 /// as to where to save his new file. In the second case, the file’s existing location
1574 /// is already known, so the file chooser will use it.
1575 /// ## `uri`
1576 /// the URI to set as current
1577 ///
1578 /// # Returns
1579 ///
1580 /// Not useful.
1581 #[doc(alias = "gtk_file_chooser_set_uri")]
1582 fn set_uri(&self, uri: &str) -> bool {
1583 unsafe {
1584 from_glib(ffi::gtk_file_chooser_set_uri(
1585 self.as_ref().to_glib_none().0,
1586 uri.to_glib_none().0,
1587 ))
1588 }
1589 }
1590
1591 /// Sets whether the file chooser should display a stock label with the name of
1592 /// the file that is being previewed; the default is [`true`]. Applications that
1593 /// want to draw the whole preview area themselves should set this to [`false`] and
1594 /// display the name themselves in their preview widget.
1595 ///
1596 /// See also: [`set_preview_widget()`][Self::set_preview_widget()]
1597 /// ## `use_label`
1598 /// whether to display a stock label with the name of the previewed file
1599 #[doc(alias = "gtk_file_chooser_set_use_preview_label")]
1600 fn set_use_preview_label(&self, use_label: bool) {
1601 unsafe {
1602 ffi::gtk_file_chooser_set_use_preview_label(
1603 self.as_ref().to_glib_none().0,
1604 use_label.into_glib(),
1605 );
1606 }
1607 }
1608
1609 /// Unselects all the files in the current folder of a file chooser.
1610 #[doc(alias = "gtk_file_chooser_unselect_all")]
1611 fn unselect_all(&self) {
1612 unsafe {
1613 ffi::gtk_file_chooser_unselect_all(self.as_ref().to_glib_none().0);
1614 }
1615 }
1616
1617 /// Unselects the file referred to by `file`. If the file is not in the current
1618 /// directory, does not exist, or is otherwise not currently selected, does nothing.
1619 /// ## `file`
1620 /// a [`gio::File`][crate::gio::File]
1621 #[doc(alias = "gtk_file_chooser_unselect_file")]
1622 fn unselect_file(&self, file: &impl IsA<gio::File>) {
1623 unsafe {
1624 ffi::gtk_file_chooser_unselect_file(
1625 self.as_ref().to_glib_none().0,
1626 file.as_ref().to_glib_none().0,
1627 );
1628 }
1629 }
1630
1631 /// Unselects a currently selected filename. If the filename
1632 /// is not in the current directory, does not exist, or
1633 /// is otherwise not currently selected, does nothing.
1634 /// ## `filename`
1635 /// the filename to unselect
1636 #[doc(alias = "gtk_file_chooser_unselect_filename")]
1637 fn unselect_filename(&self, filename: impl AsRef<std::path::Path>) {
1638 unsafe {
1639 ffi::gtk_file_chooser_unselect_filename(
1640 self.as_ref().to_glib_none().0,
1641 filename.as_ref().to_glib_none().0,
1642 );
1643 }
1644 }
1645
1646 /// Unselects the file referred to by `uri`. If the file
1647 /// is not in the current directory, does not exist, or
1648 /// is otherwise not currently selected, does nothing.
1649 /// ## `uri`
1650 /// the URI to unselect
1651 #[doc(alias = "gtk_file_chooser_unselect_uri")]
1652 fn unselect_uri(&self, uri: &str) {
1653 unsafe {
1654 ffi::gtk_file_chooser_unselect_uri(
1655 self.as_ref().to_glib_none().0,
1656 uri.to_glib_none().0,
1657 );
1658 }
1659 }
1660
1661 /// This signal gets emitted whenever it is appropriate to present a
1662 /// confirmation dialog when the user has selected a file name that
1663 /// already exists. The signal only gets emitted when the file
1664 /// chooser is in [`FileChooserAction::Save`][crate::FileChooserAction::Save] mode.
1665 ///
1666 /// Most applications just need to turn on the
1667 /// [`do-overwrite-confirmation`][struct@crate::FileChooser#do-overwrite-confirmation] property (or call the
1668 /// [`set_do_overwrite_confirmation()`][Self::set_do_overwrite_confirmation()] function), and
1669 /// they will automatically get a stock confirmation dialog.
1670 /// Applications which need to customize this behavior should do
1671 /// that, and also connect to the [`confirm-overwrite`][struct@crate::FileChooser#confirm-overwrite]
1672 /// signal.
1673 ///
1674 /// A signal handler for this signal must return a
1675 /// [`FileChooserConfirmation`][crate::FileChooserConfirmation] value, which indicates the action to
1676 /// take. If the handler determines that the user wants to select a
1677 /// different filename, it should return
1678 /// [`FileChooserConfirmation::SelectAgain`][crate::FileChooserConfirmation::SelectAgain]. If it determines
1679 /// that the user is satisfied with his choice of file name, it
1680 /// should return [`FileChooserConfirmation::AcceptFilename`][crate::FileChooserConfirmation::AcceptFilename].
1681 /// On the other hand, if it determines that the stock confirmation
1682 /// dialog should be used, it should return
1683 /// [`FileChooserConfirmation::Confirm`][crate::FileChooserConfirmation::Confirm]. The following example
1684 /// illustrates this.
1685 ///
1686 /// ## Custom confirmation ## {`gtkfilechooser`-confirmation}
1687 ///
1688 ///
1689 ///
1690 /// **⚠️ The following code is in C ⚠️**
1691 ///
1692 /// ```C
1693 /// static GtkFileChooserConfirmation
1694 /// confirm_overwrite_callback (GtkFileChooser *chooser, gpointer data)
1695 /// {
1696 /// char *uri;
1697 ///
1698 /// uri = gtk_file_chooser_get_uri (chooser);
1699 ///
1700 /// if (is_uri_read_only (uri))
1701 /// {
1702 /// if (user_wants_to_replace_read_only_file (uri))
1703 /// return GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME;
1704 /// else
1705 /// return GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN;
1706 /// } else
1707 /// return GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM; // fall back to the default dialog
1708 /// }
1709 ///
1710 /// ...
1711 ///
1712 /// chooser = gtk_file_chooser_dialog_new (...);
1713 ///
1714 /// gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
1715 /// g_signal_connect (chooser, "confirm-overwrite",
1716 /// G_CALLBACK (confirm_overwrite_callback), NULL);
1717 ///
1718 /// if (gtk_dialog_run (chooser) == GTK_RESPONSE_ACCEPT)
1719 /// save_to_file (gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
1720 ///
1721 /// gtk_widget_destroy (chooser);
1722 /// ```
1723 ///
1724 /// # Returns
1725 ///
1726 /// a [`FileChooserConfirmation`][crate::FileChooserConfirmation] value that indicates which
1727 /// action to take after emitting the signal.
1728 #[doc(alias = "confirm-overwrite")]
1729 fn connect_confirm_overwrite<F: Fn(&Self) -> FileChooserConfirmation + 'static>(
1730 &self,
1731 f: F,
1732 ) -> SignalHandlerId {
1733 unsafe extern "C" fn confirm_overwrite_trampoline<
1734 P: IsA<FileChooser>,
1735 F: Fn(&P) -> FileChooserConfirmation + 'static,
1736 >(
1737 this: *mut ffi::GtkFileChooser,
1738 f: glib::ffi::gpointer,
1739 ) -> ffi::GtkFileChooserConfirmation {
1740 let f: &F = &*(f as *const F);
1741 f(FileChooser::from_glib_borrow(this).unsafe_cast_ref()).into_glib()
1742 }
1743 unsafe {
1744 let f: Box_<F> = Box_::new(f);
1745 connect_raw(
1746 self.as_ptr() as *mut _,
1747 b"confirm-overwrite\0".as_ptr() as *const _,
1748 Some(transmute::<_, unsafe extern "C" fn()>(
1749 confirm_overwrite_trampoline::<Self, F> as *const (),
1750 )),
1751 Box_::into_raw(f),
1752 )
1753 }
1754 }
1755
1756 /// This signal is emitted when the current folder in a [`FileChooser`][crate::FileChooser]
1757 /// changes. This can happen due to the user performing some action that
1758 /// changes folders, such as selecting a bookmark or visiting a folder on the
1759 /// file list. It can also happen as a result of calling a function to
1760 /// explicitly change the current folder in a file chooser.
1761 ///
1762 /// Normally you do not need to connect to this signal, unless you need to keep
1763 /// track of which folder a file chooser is showing.
1764 ///
1765 /// See also: [`set_current_folder()`][Self::set_current_folder()],
1766 /// [`current_folder()`][Self::current_folder()],
1767 /// [`set_current_folder_uri()`][Self::set_current_folder_uri()],
1768 /// [`current_folder_uri()`][Self::current_folder_uri()].
1769 #[doc(alias = "current-folder-changed")]
1770 fn connect_current_folder_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1771 unsafe extern "C" fn current_folder_changed_trampoline<
1772 P: IsA<FileChooser>,
1773 F: Fn(&P) + 'static,
1774 >(
1775 this: *mut ffi::GtkFileChooser,
1776 f: glib::ffi::gpointer,
1777 ) {
1778 let f: &F = &*(f as *const F);
1779 f(FileChooser::from_glib_borrow(this).unsafe_cast_ref())
1780 }
1781 unsafe {
1782 let f: Box_<F> = Box_::new(f);
1783 connect_raw(
1784 self.as_ptr() as *mut _,
1785 b"current-folder-changed\0".as_ptr() as *const _,
1786 Some(transmute::<_, unsafe extern "C" fn()>(
1787 current_folder_changed_trampoline::<Self, F> as *const (),
1788 )),
1789 Box_::into_raw(f),
1790 )
1791 }
1792 }
1793
1794 /// This signal is emitted when the user "activates" a file in the file
1795 /// chooser. This can happen by double-clicking on a file in the file list, or
1796 /// by pressing `Enter`.
1797 ///
1798 /// Normally you do not need to connect to this signal. It is used internally
1799 /// by [`FileChooserDialog`][crate::FileChooserDialog] to know when to activate the default button in the
1800 /// dialog.
1801 ///
1802 /// See also: [`filename()`][Self::filename()],
1803 /// [`filenames()`][Self::filenames()], [`uri()`][Self::uri()],
1804 /// [`uris()`][Self::uris()].
1805 #[doc(alias = "file-activated")]
1806 fn connect_file_activated<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1807 unsafe extern "C" fn file_activated_trampoline<P: IsA<FileChooser>, F: Fn(&P) + 'static>(
1808 this: *mut ffi::GtkFileChooser,
1809 f: glib::ffi::gpointer,
1810 ) {
1811 let f: &F = &*(f as *const F);
1812 f(FileChooser::from_glib_borrow(this).unsafe_cast_ref())
1813 }
1814 unsafe {
1815 let f: Box_<F> = Box_::new(f);
1816 connect_raw(
1817 self.as_ptr() as *mut _,
1818 b"file-activated\0".as_ptr() as *const _,
1819 Some(transmute::<_, unsafe extern "C" fn()>(
1820 file_activated_trampoline::<Self, F> as *const (),
1821 )),
1822 Box_::into_raw(f),
1823 )
1824 }
1825 }
1826
1827 /// This signal is emitted when there is a change in the set of selected files
1828 /// in a [`FileChooser`][crate::FileChooser]. This can happen when the user modifies the selection
1829 /// with the mouse or the keyboard, or when explicitly calling functions to
1830 /// change the selection.
1831 ///
1832 /// Normally you do not need to connect to this signal, as it is easier to wait
1833 /// for the file chooser to finish running, and then to get the list of
1834 /// selected files using the functions mentioned below.
1835 ///
1836 /// See also: [`select_filename()`][Self::select_filename()],
1837 /// [`unselect_filename()`][Self::unselect_filename()], [`filename()`][Self::filename()],
1838 /// [`filenames()`][Self::filenames()], [`select_uri()`][Self::select_uri()],
1839 /// [`unselect_uri()`][Self::unselect_uri()], [`uri()`][Self::uri()],
1840 /// [`uris()`][Self::uris()].
1841 #[doc(alias = "selection-changed")]
1842 fn connect_selection_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1843 unsafe extern "C" fn selection_changed_trampoline<
1844 P: IsA<FileChooser>,
1845 F: Fn(&P) + 'static,
1846 >(
1847 this: *mut ffi::GtkFileChooser,
1848 f: glib::ffi::gpointer,
1849 ) {
1850 let f: &F = &*(f as *const F);
1851 f(FileChooser::from_glib_borrow(this).unsafe_cast_ref())
1852 }
1853 unsafe {
1854 let f: Box_<F> = Box_::new(f);
1855 connect_raw(
1856 self.as_ptr() as *mut _,
1857 b"selection-changed\0".as_ptr() as *const _,
1858 Some(transmute::<_, unsafe extern "C" fn()>(
1859 selection_changed_trampoline::<Self, F> as *const (),
1860 )),
1861 Box_::into_raw(f),
1862 )
1863 }
1864 }
1865
1866 /// This signal is emitted when the preview in a file chooser should be
1867 /// regenerated. For example, this can happen when the currently selected file
1868 /// changes. You should use this signal if you want your file chooser to have
1869 /// a preview widget.
1870 ///
1871 /// Once you have installed a preview widget with
1872 /// [`set_preview_widget()`][Self::set_preview_widget()], you should update it when this
1873 /// signal is emitted. You can use the functions
1874 /// [`preview_filename()`][Self::preview_filename()] or
1875 /// [`preview_uri()`][Self::preview_uri()] to get the name of the file to preview.
1876 /// Your widget may not be able to preview all kinds of files; your callback
1877 /// must call [`set_preview_widget_active()`][Self::set_preview_widget_active()] to inform the file
1878 /// chooser about whether the preview was generated successfully or not.
1879 ///
1880 /// Please see the example code in
1881 /// [Using a Preview Widget][gtkfilechooser-preview].
1882 ///
1883 /// See also: [`set_preview_widget()`][Self::set_preview_widget()],
1884 /// [`set_preview_widget_active()`][Self::set_preview_widget_active()],
1885 /// [`set_use_preview_label()`][Self::set_use_preview_label()],
1886 /// [`preview_filename()`][Self::preview_filename()],
1887 /// [`preview_uri()`][Self::preview_uri()].
1888 #[doc(alias = "update-preview")]
1889 fn connect_update_preview<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1890 unsafe extern "C" fn update_preview_trampoline<P: IsA<FileChooser>, F: Fn(&P) + 'static>(
1891 this: *mut ffi::GtkFileChooser,
1892 f: glib::ffi::gpointer,
1893 ) {
1894 let f: &F = &*(f as *const F);
1895 f(FileChooser::from_glib_borrow(this).unsafe_cast_ref())
1896 }
1897 unsafe {
1898 let f: Box_<F> = Box_::new(f);
1899 connect_raw(
1900 self.as_ptr() as *mut _,
1901 b"update-preview\0".as_ptr() as *const _,
1902 Some(transmute::<_, unsafe extern "C" fn()>(
1903 update_preview_trampoline::<Self, F> as *const (),
1904 )),
1905 Box_::into_raw(f),
1906 )
1907 }
1908 }
1909
1910 #[doc(alias = "action")]
1911 fn connect_action_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1912 unsafe extern "C" fn notify_action_trampoline<P: IsA<FileChooser>, F: Fn(&P) + 'static>(
1913 this: *mut ffi::GtkFileChooser,
1914 _param_spec: glib::ffi::gpointer,
1915 f: glib::ffi::gpointer,
1916 ) {
1917 let f: &F = &*(f as *const F);
1918 f(FileChooser::from_glib_borrow(this).unsafe_cast_ref())
1919 }
1920 unsafe {
1921 let f: Box_<F> = Box_::new(f);
1922 connect_raw(
1923 self.as_ptr() as *mut _,
1924 b"notify::action\0".as_ptr() as *const _,
1925 Some(transmute::<_, unsafe extern "C" fn()>(
1926 notify_action_trampoline::<Self, F> as *const (),
1927 )),
1928 Box_::into_raw(f),
1929 )
1930 }
1931 }
1932
1933 #[doc(alias = "create-folders")]
1934 fn connect_create_folders_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1935 unsafe extern "C" fn notify_create_folders_trampoline<
1936 P: IsA<FileChooser>,
1937 F: Fn(&P) + 'static,
1938 >(
1939 this: *mut ffi::GtkFileChooser,
1940 _param_spec: glib::ffi::gpointer,
1941 f: glib::ffi::gpointer,
1942 ) {
1943 let f: &F = &*(f as *const F);
1944 f(FileChooser::from_glib_borrow(this).unsafe_cast_ref())
1945 }
1946 unsafe {
1947 let f: Box_<F> = Box_::new(f);
1948 connect_raw(
1949 self.as_ptr() as *mut _,
1950 b"notify::create-folders\0".as_ptr() as *const _,
1951 Some(transmute::<_, unsafe extern "C" fn()>(
1952 notify_create_folders_trampoline::<Self, F> as *const (),
1953 )),
1954 Box_::into_raw(f),
1955 )
1956 }
1957 }
1958
1959 #[doc(alias = "do-overwrite-confirmation")]
1960 fn connect_do_overwrite_confirmation_notify<F: Fn(&Self) + 'static>(
1961 &self,
1962 f: F,
1963 ) -> SignalHandlerId {
1964 unsafe extern "C" fn notify_do_overwrite_confirmation_trampoline<
1965 P: IsA<FileChooser>,
1966 F: Fn(&P) + 'static,
1967 >(
1968 this: *mut ffi::GtkFileChooser,
1969 _param_spec: glib::ffi::gpointer,
1970 f: glib::ffi::gpointer,
1971 ) {
1972 let f: &F = &*(f as *const F);
1973 f(FileChooser::from_glib_borrow(this).unsafe_cast_ref())
1974 }
1975 unsafe {
1976 let f: Box_<F> = Box_::new(f);
1977 connect_raw(
1978 self.as_ptr() as *mut _,
1979 b"notify::do-overwrite-confirmation\0".as_ptr() as *const _,
1980 Some(transmute::<_, unsafe extern "C" fn()>(
1981 notify_do_overwrite_confirmation_trampoline::<Self, F> as *const (),
1982 )),
1983 Box_::into_raw(f),
1984 )
1985 }
1986 }
1987
1988 #[doc(alias = "extra-widget")]
1989 fn connect_extra_widget_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1990 unsafe extern "C" fn notify_extra_widget_trampoline<
1991 P: IsA<FileChooser>,
1992 F: Fn(&P) + 'static,
1993 >(
1994 this: *mut ffi::GtkFileChooser,
1995 _param_spec: glib::ffi::gpointer,
1996 f: glib::ffi::gpointer,
1997 ) {
1998 let f: &F = &*(f as *const F);
1999 f(FileChooser::from_glib_borrow(this).unsafe_cast_ref())
2000 }
2001 unsafe {
2002 let f: Box_<F> = Box_::new(f);
2003 connect_raw(
2004 self.as_ptr() as *mut _,
2005 b"notify::extra-widget\0".as_ptr() as *const _,
2006 Some(transmute::<_, unsafe extern "C" fn()>(
2007 notify_extra_widget_trampoline::<Self, F> as *const (),
2008 )),
2009 Box_::into_raw(f),
2010 )
2011 }
2012 }
2013
2014 #[doc(alias = "filter")]
2015 fn connect_filter_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2016 unsafe extern "C" fn notify_filter_trampoline<P: IsA<FileChooser>, F: Fn(&P) + 'static>(
2017 this: *mut ffi::GtkFileChooser,
2018 _param_spec: glib::ffi::gpointer,
2019 f: glib::ffi::gpointer,
2020 ) {
2021 let f: &F = &*(f as *const F);
2022 f(FileChooser::from_glib_borrow(this).unsafe_cast_ref())
2023 }
2024 unsafe {
2025 let f: Box_<F> = Box_::new(f);
2026 connect_raw(
2027 self.as_ptr() as *mut _,
2028 b"notify::filter\0".as_ptr() as *const _,
2029 Some(transmute::<_, unsafe extern "C" fn()>(
2030 notify_filter_trampoline::<Self, F> as *const (),
2031 )),
2032 Box_::into_raw(f),
2033 )
2034 }
2035 }
2036
2037 #[doc(alias = "local-only")]
2038 fn connect_local_only_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2039 unsafe extern "C" fn notify_local_only_trampoline<
2040 P: IsA<FileChooser>,
2041 F: Fn(&P) + 'static,
2042 >(
2043 this: *mut ffi::GtkFileChooser,
2044 _param_spec: glib::ffi::gpointer,
2045 f: glib::ffi::gpointer,
2046 ) {
2047 let f: &F = &*(f as *const F);
2048 f(FileChooser::from_glib_borrow(this).unsafe_cast_ref())
2049 }
2050 unsafe {
2051 let f: Box_<F> = Box_::new(f);
2052 connect_raw(
2053 self.as_ptr() as *mut _,
2054 b"notify::local-only\0".as_ptr() as *const _,
2055 Some(transmute::<_, unsafe extern "C" fn()>(
2056 notify_local_only_trampoline::<Self, F> as *const (),
2057 )),
2058 Box_::into_raw(f),
2059 )
2060 }
2061 }
2062
2063 #[doc(alias = "preview-widget")]
2064 fn connect_preview_widget_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2065 unsafe extern "C" fn notify_preview_widget_trampoline<
2066 P: IsA<FileChooser>,
2067 F: Fn(&P) + 'static,
2068 >(
2069 this: *mut ffi::GtkFileChooser,
2070 _param_spec: glib::ffi::gpointer,
2071 f: glib::ffi::gpointer,
2072 ) {
2073 let f: &F = &*(f as *const F);
2074 f(FileChooser::from_glib_borrow(this).unsafe_cast_ref())
2075 }
2076 unsafe {
2077 let f: Box_<F> = Box_::new(f);
2078 connect_raw(
2079 self.as_ptr() as *mut _,
2080 b"notify::preview-widget\0".as_ptr() as *const _,
2081 Some(transmute::<_, unsafe extern "C" fn()>(
2082 notify_preview_widget_trampoline::<Self, F> as *const (),
2083 )),
2084 Box_::into_raw(f),
2085 )
2086 }
2087 }
2088
2089 #[doc(alias = "preview-widget-active")]
2090 fn connect_preview_widget_active_notify<F: Fn(&Self) + 'static>(
2091 &self,
2092 f: F,
2093 ) -> SignalHandlerId {
2094 unsafe extern "C" fn notify_preview_widget_active_trampoline<
2095 P: IsA<FileChooser>,
2096 F: Fn(&P) + 'static,
2097 >(
2098 this: *mut ffi::GtkFileChooser,
2099 _param_spec: glib::ffi::gpointer,
2100 f: glib::ffi::gpointer,
2101 ) {
2102 let f: &F = &*(f as *const F);
2103 f(FileChooser::from_glib_borrow(this).unsafe_cast_ref())
2104 }
2105 unsafe {
2106 let f: Box_<F> = Box_::new(f);
2107 connect_raw(
2108 self.as_ptr() as *mut _,
2109 b"notify::preview-widget-active\0".as_ptr() as *const _,
2110 Some(transmute::<_, unsafe extern "C" fn()>(
2111 notify_preview_widget_active_trampoline::<Self, F> as *const (),
2112 )),
2113 Box_::into_raw(f),
2114 )
2115 }
2116 }
2117
2118 #[doc(alias = "select-multiple")]
2119 fn connect_select_multiple_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2120 unsafe extern "C" fn notify_select_multiple_trampoline<
2121 P: IsA<FileChooser>,
2122 F: Fn(&P) + 'static,
2123 >(
2124 this: *mut ffi::GtkFileChooser,
2125 _param_spec: glib::ffi::gpointer,
2126 f: glib::ffi::gpointer,
2127 ) {
2128 let f: &F = &*(f as *const F);
2129 f(FileChooser::from_glib_borrow(this).unsafe_cast_ref())
2130 }
2131 unsafe {
2132 let f: Box_<F> = Box_::new(f);
2133 connect_raw(
2134 self.as_ptr() as *mut _,
2135 b"notify::select-multiple\0".as_ptr() as *const _,
2136 Some(transmute::<_, unsafe extern "C" fn()>(
2137 notify_select_multiple_trampoline::<Self, F> as *const (),
2138 )),
2139 Box_::into_raw(f),
2140 )
2141 }
2142 }
2143
2144 #[doc(alias = "show-hidden")]
2145 fn connect_show_hidden_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2146 unsafe extern "C" fn notify_show_hidden_trampoline<
2147 P: IsA<FileChooser>,
2148 F: Fn(&P) + 'static,
2149 >(
2150 this: *mut ffi::GtkFileChooser,
2151 _param_spec: glib::ffi::gpointer,
2152 f: glib::ffi::gpointer,
2153 ) {
2154 let f: &F = &*(f as *const F);
2155 f(FileChooser::from_glib_borrow(this).unsafe_cast_ref())
2156 }
2157 unsafe {
2158 let f: Box_<F> = Box_::new(f);
2159 connect_raw(
2160 self.as_ptr() as *mut _,
2161 b"notify::show-hidden\0".as_ptr() as *const _,
2162 Some(transmute::<_, unsafe extern "C" fn()>(
2163 notify_show_hidden_trampoline::<Self, F> as *const (),
2164 )),
2165 Box_::into_raw(f),
2166 )
2167 }
2168 }
2169
2170 #[doc(alias = "use-preview-label")]
2171 fn connect_use_preview_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2172 unsafe extern "C" fn notify_use_preview_label_trampoline<
2173 P: IsA<FileChooser>,
2174 F: Fn(&P) + 'static,
2175 >(
2176 this: *mut ffi::GtkFileChooser,
2177 _param_spec: glib::ffi::gpointer,
2178 f: glib::ffi::gpointer,
2179 ) {
2180 let f: &F = &*(f as *const F);
2181 f(FileChooser::from_glib_borrow(this).unsafe_cast_ref())
2182 }
2183 unsafe {
2184 let f: Box_<F> = Box_::new(f);
2185 connect_raw(
2186 self.as_ptr() as *mut _,
2187 b"notify::use-preview-label\0".as_ptr() as *const _,
2188 Some(transmute::<_, unsafe extern "C" fn()>(
2189 notify_use_preview_label_trampoline::<Self, F> as *const (),
2190 )),
2191 Box_::into_raw(f),
2192 )
2193 }
2194 }
2195}
2196
2197impl<O: IsA<FileChooser>> FileChooserExt for O {}
2198
2199impl fmt::Display for FileChooser {
2200 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2201 f.write_str("FileChooser")
2202 }
2203}