1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 File chooser interface used by GtkFileChooserWidget and GtkFileChooserDialog
7 <!-- ##### SECTION Long_Description ##### -->
9 #GtkFileChooser is an interface that can be implemented by file
10 selection widgets. In GTK+, the main objects that implement this
11 interface are #GtkFileChooserWidget, #GtkFileChooserDialog, and
12 #GtkFileChooserButton. You do not need to write an object that
13 implements the #GtkFileChooser interface unless you are trying to
14 adapt an existing file selector to expose a standard programming
19 #GtkFileChooser allows for shortcuts to various places in the filesystem.
20 In the default implementation these are displayed in the left pane. It
21 may be a bit confusing at first taht these shortcuts come from various
22 sources and in various flavours, so lets explain the terminology here:
26 <term>Bookmarks</term>
28 are created by the user, by dragging folders from the
29 right pane to the left pane, or by using the "Add". Bookmarks
30 can be renamed and deleted by the user.
34 <term>Shortcuts</term>
36 can be provided by the application or by the underlying filesystem
37 abstraction (e.g. both the gnome-vfs and the Windows filesystems
38 provide "Desktop" shortcuts). Shortcuts cannot be modified by the
45 are provided by the underlying filesystem abstraction. They are
46 the "roots" of the filesystem.
51 <refsect2 id="gtkfilechooser-encodings">
52 <title>File Names and Encodings</title>
55 When the user is finished selecting files in a
56 #GtkFileChooser, your program can get the selected names
57 either as filenames or as URIs. For URIs, the normal escaping
58 rules are applied if the URI contains non-ASCII characters.
59 However, filenames are <emphasis>always</emphasis> returned in
60 the character set specified by the
61 <envar>G_FILENAME_ENCODING</envar> environment variable.
62 Please see the Glib documentation for more details about this
68 This means that while you can pass the result of
69 gtk_file_chooser_get_filename() to
70 <function>open(2)</function> or
71 <function>fopen(3)</function>, you may not be able to
72 directly set it as the text of a #GtkLabel widget unless you
73 convert it first to UTF-8, which all GTK+ widgets expect.
74 You should use g_filename_to_utf8() to convert filenames
75 into strings that can be passed to GTK+ widgets.
80 <refsect2 id="gtkfilechooser-preview">
81 <title>Adding a Preview Widget</title>
84 You can add a custom preview widget to a file chooser and then
85 get notification about when the preview needs to be updated.
86 To install a preview widget, use
87 gtk_file_chooser_set_preview_widget(). Then, connect to the
88 #GtkFileChooser::update-preview signal to get notified when
89 you need to update the contents of the preview.
93 Your callback should use
94 gtk_file_chooser_get_preview_filename() to see what needs
95 previewing. Once you have generated the preview for the
96 corresponding file, you must call
97 gtk_file_chooser_set_preview_widget_active() with a boolean
98 flag that indicates whether your callback could successfully
102 <example id="example-gtkfilechooser-preview">
103 <title>Sample Usage</title>
111 preview = gtk_image_new (<!-- -->);
113 gtk_file_chooser_set_preview_widget (my_file_chooser, preview);
114 g_signal_connect (my_file_chooser, "update-preview",
115 G_CALLBACK (update_preview_cb), preview);
119 update_preview_cb (GtkFileChooser *file_chooser, gpointer data)
124 gboolean have_preview;
126 preview = GTK_WIDGET (data);
127 filename = gtk_file_chooser_get_preview_filename (file_chooser);
129 pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 128, 128, NULL);
130 have_preview = (pixbuf != NULL);
133 gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf);
135 gobject_unref (pixbuf);
137 gtk_file_chooser_set_preview_widget_active (file_chooser, have_preview);
143 <refsect2 id="gtkfilechooser-extra">
144 <title>Adding Extra Widgets</title>
147 You can add extra widgets to a file chooser to provide options
148 that are not present in the default design. For example, you
149 can add a toggle button to give the user the option to open a
150 file in read-only mode. You can use
151 gtk_file_chooser_set_extra_widget() to insert additional
152 widgets in a file chooser.
155 <example id="example-gtkfilechooser-extra">
156 <title>Sample Usage</title>
164 toggle = gtk_check_button_new_with_label ("Open file read-only");
165 gtk_widget_show (toggle);
166 gtk_file_chooser_set_extra_widget (my_file_chooser, toggle);
173 If you want to set more than one extra widget in the file
174 chooser, you can a container such as a GtkVBox or a GtkTable
175 and include your widgets in it. Then, set the container as
176 the whole extra widget.
181 <refsect2 id="gtkfilechooser-key-bindings">
182 <title>Key Bindings</title>
185 Internally, GTK+ implements a file chooser's graphical user
186 interface with the private
187 <classname>GtkFileChooserDefaultClass</classname>. This
188 widget has several <link linkend="gtk-Bindings">key
189 bindings</link> and their associated signals. This section
190 describes the available key binding signals.
193 <example id="gtkfilechooser-key-binding-example">
194 <title>GtkFileChooser key binding example</title>
197 The default keys that activate the key-binding signals in
198 <classname>GtkFileChooserDefaultClass</classname> are as
206 <entry>Signal name</entry>
207 <entry>Default key combinations</entry>
210 <entry>location-popup</entry>
212 <keycombo><keycap>Control</keycap><keycap>L</keycap></keycombo> (empty path);
213 <keycap>/</keycap> (path of "/")<footnote>
215 Both the individual <keycap>/</keycap> key and the
216 numeric keypad's "divide" key are supported.
219 <keycap>~</keycap> (path of "~")
223 <entry>up-folder</entry>
225 <keycombo><keycap>Alt</keycap><keycap>Up</keycap></keycombo><footnote>
227 Both the individual Up key and the numeric
228 keypad's Up key are supported.
232 <keycap>Backspace</keycap>
236 <entry>down-folder</entry>
237 <entry><keycombo><keycap>Alt</keycap><keycap>Down</keycap></keycombo></entry>
240 <entry>home-folder</entry>
241 <entry><keycombo><keycap>Alt</keycap><keycap>Home</keycap></keycombo></entry>
244 <entry>desktop-folder</entry>
245 <entry><keycombo><keycap>Alt</keycap><keycap>D</keycap></keycombo></entry>
248 <entry>quick-bookmark</entry>
249 <entry><keycombo><keycap>Alt</keycap><keycap>1</keycap></keycombo> through <keycombo><keycap>Alt</keycap><keycap>0</keycap></keycombo></entry>
256 You can change these defaults to something else. For
257 example, to add a <keycap>Shift</keycap> modifier to a few
258 of the default bindings, you can include the following
259 fragment in your <filename>.gtkrc-2.0</filename> file:
263 binding "my-own-gtkfilechooser-bindings" {
264 bind "<Alt><Shift>Up" {
267 bind "<Alt><Shift>Down" {
270 bind "<Alt><Shift>Home" {
275 class "GtkFileChooserDefault" binding "my-own-gtkfilechooser-bindings"
279 <refsect3 id="GtkFileChooserDefault-location-popup">
280 <title>The "GtkFileChooserDefault::location-popup" signal</title>
283 void user_function (GtkFileChooserDefault *chooser,
285 <link linkend="gpointer">gpointer</link> user_data);
289 This is used to make the file chooser show a "Location"
290 dialog which the user can use to manually type the name of
291 the file he wishes to select. The
292 <parameter>path</parameter> argument is a string that gets
293 put in the text entry for the file name. By default this is bound to
294 <keycombo><keycap>Control</keycap><keycap>L</keycap></keycombo>
295 with a <parameter>path</parameter> string of "" (the empty
296 string). It is also bound to <keycap>/</keycap> with a
297 <parameter>path</parameter> string of "<literal>/</literal>"
298 (a slash): this lets you type <keycap>/</keycap> and
299 immediately type a path name. On Unix systems, this is bound to
300 <keycap>~</keycap> (tilde) with a <parameter>path</parameter> string
301 of "~" itself for access to home directories.
304 <variablelist role="params">
306 <term><parameter>chooser</parameter> :</term>
309 the object which received the signal.
314 <term><parameter>path</parameter> :</term>
317 default contents for the text entry for the file name
322 <term><parameter>user_data</parameter> :</term>
325 user data set when the signal handler was connected.
333 You can create your own bindings for the
334 <symbol>location-popup</symbol> signal with custom
335 <parameter>path</parameter> strings, and have a crude form
336 of easily-to-type bookmarks. For example, say you access
337 the path <filename>/home/username/misc</filename> very
338 frequently. You could then create an <keycombo>
339 <keycap>Alt</keycap> <keycap>M</keycap> </keycombo>
340 shortcut by including the following in your
341 <filename>.gtkrc-2.0</filename>:
345 binding "misc-shortcut" {
346 bind "<Alt>M" {
347 "location-popup" ("/home/username/misc")
351 class "GtkFileChooserDefault" binding "misc-shortcut"
356 <refsect3 id="GtkFileChooserDefault-up-folder">
357 <title>The "GtkFileChooserDefault::up-folder" signal</title>
360 void user_function (GtkFileChooserDefault *chooser,
361 <link linkend="gpointer">gpointer</link> user_data);
365 This is used to make the file chooser go to the parent of
366 the current folder in the file hierarchy. By default this
367 is bound to <keycap>Backspace</keycap> and
368 <keycombo><keycap>Alt</keycap><keycap>Up</keycap></keycombo>
369 (the Up key in the numeric keypad also works).
372 <variablelist role="params">
374 <term><parameter>chooser</parameter> :</term>
377 the object which received the signal.
382 <term><parameter>user_data</parameter> :</term>
385 user data set when the signal handler was connected.
392 <refsect3 id="GtkFileChooserDefault-down-folder">
393 <title>The "GtkFileChooserDefault::down-folder" signal</title>
396 void user_function (GtkFileChooserDefault *chooser,
397 <link linkend="gpointer">gpointer</link> user_data);
401 This is used to make the file chooser go to a child of the
402 current folder in the file hierarchy. The subfolder that
403 will be used is displayed in the path bar widget of the file
404 chooser. For example, if the path bar is showing
405 "/foo/<emphasis>bar/</emphasis>baz", then this will cause
406 the file chooser to switch to the "baz" subfolder. By
407 default this is bound to
408 <keycombo><keycap>Alt</keycap><keycap>Down</keycap></keycombo>
409 (the Down key in the numeric keypad also works).
412 <variablelist role="params">
414 <term><parameter>chooser</parameter> :</term>
417 the object which received the signal.
422 <term><parameter>user_data</parameter> :</term>
425 user data set when the signal handler was connected.
432 <refsect3 id="GtkFileChooserDefault-home-folder">
433 <title>The "GtkFileChooserDefault::home-folder" signal</title>
436 void user_function (GtkFileChooserDefault *chooser,
437 <link linkend="gpointer">gpointer</link> user_data);
441 This is used to make the file chooser show the user's home
442 folder in the file list. By default this is bound to
443 <keycombo><keycap>Alt</keycap><keycap>Home</keycap></keycombo>
444 (the Home key in the numeric keypad also works).
447 <variablelist role="params">
449 <term><parameter>chooser</parameter> :</term>
452 the object which received the signal.
457 <term><parameter>user_data</parameter> :</term>
460 user data set when the signal handler was connected.
467 <refsect3 id="GtkFileChooserDefault-desktop-folder">
468 <title>The "GtkFileChooserDefault::desktop-folder" signal</title>
471 void user_function (GtkFileChooserDefault *chooser,
472 <link linkend="gpointer">gpointer</link> user_data);
476 This is used to make the file chooser show the user's Desktop
477 folder in the file list. By default this is bound to
478 <keycombo><keycap>Alt</keycap><keycap>D</keycap></keycombo>.
481 <variablelist role="params">
483 <term><parameter>chooser</parameter> :</term>
486 the object which received the signal.
491 <term><parameter>user_data</parameter> :</term>
494 user data set when the signal handler was connected.
501 <refsect3 id="GtkFileChooserDefault-quick-bookmark">
502 <title>The "GtkFileChooserDefault::quick-bookmark" signal</title>
505 void user_function (GtkFileChooserDefault *chooser,
507 <link linkend="gpointer">gpointer</link> user_data);
511 This is used to make the file chooser switch to the bookmark
512 specified in the <parameter>bookmark_index</parameter> parameter.
513 For example, if you have three bookmarks, you can pass 0, 1, 2 to
514 this signal to switch to each of them, respectively. By default this is bound to
515 <keycombo><keycap>Alt</keycap><keycap>1</keycap></keycombo>,
516 <keycombo><keycap>Alt</keycap><keycap>2</keycap></keycombo>,
518 <keycombo><keycap>Alt</keycap><keycap>0</keycap></keycombo>. Note
519 that in the default binding,
520 that <keycombo><keycap>Alt</keycap><keycap>1</keycap></keycombo> is
521 actually defined to switch to the bookmark at index 0, and so on
523 <keycombo><keycap>Alt</keycap><keycap>0</keycap></keycombo> is
524 defined to switch to the bookmark at index 10.
527 <variablelist role="params">
529 <term><parameter>chooser</parameter> :</term>
532 the object which received the signal.
537 <term><parameter>bookmark_indes</parameter> :</term>
540 index of the bookmark to switch to; the indices start at 0.
545 <term><parameter>user_data</parameter> :</term>
548 user data set when the signal handler was connected.
556 <!-- ##### SECTION See_Also ##### -->
558 #GtkFileChooserDialog, #GtkFileChooserWidget, #GtkFileChooserButton
561 <!-- ##### SECTION Stability_Level ##### -->
564 <!-- ##### STRUCT GtkFileChooser ##### -->
570 <!-- ##### SIGNAL GtkFileChooser::confirm-overwrite ##### -->
572 This signal gets emitted whenever it is appropriate to present a
573 confirmation dialog when the user has selected a file name that
574 already exists. The signal only gets emitted when the file
575 chooser is in #GTK_FILE_CHOOSER_ACTION_SAVE mode.
579 Most applications just need to turn on the <link
580 linkend="GtkFileChooser--do-overwrite-confirmation">do-overwrite-confirmation</link>
581 property (or call the
582 gtk_file_chooser_set_do_overwrite_confirmation() function), and
583 they will automatically get a stock confirmation dialog.
584 Applications which need to customize this behavior should do
585 that, and also connect to the <symbol>confirm-overwrite</symbol>
590 A signal handler for this signal must return a
591 #GtkFileChooserConfirmation value, which indicates the action to
592 take. If the handler determines that the user wants to select a
593 different filename, it should return
594 #GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN. If it determines
595 that the user is satisfied with his choice of file name, it
596 should return #GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME.
597 On the other hand, if it determines that the stock confirmation
598 dialog should be used, it should return
599 #GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM. The following example
603 <example id="gtkfilechooser-confirmation">
604 <title>Custom confirmation</title>
607 static GtkFileChooserConfirmation
608 confirm_overwrite_callback (GtkFileChooser *chooser, gpointer data)
612 uri = gtk_file_chooser_get_uri (chooser);
614 if (is_uri_read_only (uri))
616 if (user_wants_to_replace_read_only_file (uri))
617 return GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME;
619 return GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN;
621 return GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM; /* fall back to the default dialog */
626 chooser = gtk_file_chooser_dialog_new (...);
628 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
629 g_signal_connect (chooser, "confirm-overwrite",
630 G_CALLBACK (confirm_overwrite_callback), NULL);
632 if (gtk_dialog_run (chooser) == GTK_RESPONSE_ACCEPT)
633 save_to_file (gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
635 gtk_widget_destroy (chooser);
639 @filechooser: the object which received the signal.
640 @Returns: #GtkFileChooserConfirmation value that indicates which
641 action to take after emitting the signal.
647 <!-- ##### SIGNAL GtkFileChooser::current-folder-changed ##### -->
652 @filechooser: the object which received the signal.
654 <!-- ##### SIGNAL GtkFileChooser::file-activated ##### -->
659 @filechooser: the object which received the signal.
661 <!-- ##### SIGNAL GtkFileChooser::selection-changed ##### -->
666 @filechooser: the object which received the signal.
668 <!-- ##### SIGNAL GtkFileChooser::update-preview ##### -->
673 @filechooser: the object which received the signal.
675 <!-- ##### ARG GtkFileChooser:action ##### -->
680 <!-- ##### ARG GtkFileChooser:do-overwrite-confirmation ##### -->
685 <!-- ##### ARG GtkFileChooser:extra-widget ##### -->
690 <!-- ##### ARG GtkFileChooser:file-system-backend ##### -->
695 <!-- ##### ARG GtkFileChooser:filter ##### -->
700 <!-- ##### ARG GtkFileChooser:local-only ##### -->
705 <!-- ##### ARG GtkFileChooser:preview-widget ##### -->
710 <!-- ##### ARG GtkFileChooser:preview-widget-active ##### -->
715 <!-- ##### ARG GtkFileChooser:select-multiple ##### -->
720 <!-- ##### ARG GtkFileChooser:show-hidden ##### -->
725 <!-- ##### ARG GtkFileChooser:use-preview-label ##### -->
730 <!-- ##### ENUM GtkFileChooserAction ##### -->
732 Describes whether a #GtkFileChooser is being used to open
733 existing files or to save to a possibly new file.
736 @GTK_FILE_CHOOSER_ACTION_OPEN: Indicates open mode. The file chooser
737 will only let the user pick an existing file.
738 @GTK_FILE_CHOOSER_ACTION_SAVE: Indicates save mode. The file chooser
739 will let the user pick an existing file, or type in a new
741 @GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER: Indicates an Open mode for
742 selecting folders. The file chooser will let the user pick an
744 @GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER: Indicates a mode for creating a
745 new folder. The file chooser will let the user name an existing or
748 <!-- ##### ENUM GtkFileChooserConfirmation ##### -->
750 Used as a return value of handlers for the <link
751 linkend="GtkFileChooser-confirm-overwrite">confirm-overwrite</link>
752 signal of a <classname>GtkFileChooser</classname>. This value
753 determines whether the file chooser will present the stock
754 confirmation dialog, accept the user's choice of a filename, or
755 let the user choose another filename.
758 @GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM: The file chooser will present
759 its stock dialog to confirm about overwriting an existing file.
760 @GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME: The file chooser will
761 terminate and accept the user's choice of a file name.
762 @GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN: The file chooser will
763 continue running, so as to let the user select another file name.
769 <!-- ##### MACRO GTK_FILE_CHOOSER_ERROR ##### -->
771 Used to get the #GError quark for #GtkFileChooser errors.
776 <!-- ##### ENUM GtkFileChooserError ##### -->
778 These identify the various errors that can occur while calling
779 #GtkFileChooser functions.
782 @GTK_FILE_CHOOSER_ERROR_NONEXISTENT: Indicates that a file does not exist.
783 @GTK_FILE_CHOOSER_ERROR_BAD_FILENAME: Indicates a malformed filename.
784 @GTK_FILE_CHOOSER_ERROR_ALREADY_EXISTS:
786 <!-- ##### FUNCTION gtk_file_chooser_set_action ##### -->
795 <!-- ##### FUNCTION gtk_file_chooser_get_action ##### -->
804 <!-- ##### FUNCTION gtk_file_chooser_set_local_only ##### -->
813 <!-- ##### FUNCTION gtk_file_chooser_get_local_only ##### -->
822 <!-- ##### FUNCTION gtk_file_chooser_set_select_multiple ##### -->
831 <!-- ##### FUNCTION gtk_file_chooser_get_select_multiple ##### -->
840 <!-- ##### FUNCTION gtk_file_chooser_set_show_hidden ##### -->
849 <!-- ##### FUNCTION gtk_file_chooser_get_show_hidden ##### -->
858 <!-- ##### FUNCTION gtk_file_chooser_set_do_overwrite_confirmation ##### -->
864 @do_overwrite_confirmation:
867 <!-- ##### FUNCTION gtk_file_chooser_get_do_overwrite_confirmation ##### -->
876 <!-- ##### FUNCTION gtk_file_chooser_set_current_name ##### -->
885 <!-- ##### FUNCTION gtk_file_chooser_get_filename ##### -->
894 <!-- ##### FUNCTION gtk_file_chooser_set_filename ##### -->
904 <!-- ##### FUNCTION gtk_file_chooser_select_filename ##### -->
914 <!-- ##### FUNCTION gtk_file_chooser_unselect_filename ##### -->
923 <!-- ##### FUNCTION gtk_file_chooser_select_all ##### -->
931 <!-- ##### FUNCTION gtk_file_chooser_unselect_all ##### -->
939 <!-- ##### FUNCTION gtk_file_chooser_get_filenames ##### -->
948 <!-- ##### FUNCTION gtk_file_chooser_set_current_folder ##### -->
958 <!-- ##### FUNCTION gtk_file_chooser_get_current_folder ##### -->
967 <!-- ##### FUNCTION gtk_file_chooser_get_uri ##### -->
976 <!-- ##### FUNCTION gtk_file_chooser_set_uri ##### -->
986 <!-- ##### FUNCTION gtk_file_chooser_select_uri ##### -->
996 <!-- ##### FUNCTION gtk_file_chooser_unselect_uri ##### -->
1005 <!-- ##### FUNCTION gtk_file_chooser_get_uris ##### -->
1014 <!-- ##### FUNCTION gtk_file_chooser_set_current_folder_uri ##### -->
1024 <!-- ##### FUNCTION gtk_file_chooser_get_current_folder_uri ##### -->
1033 <!-- ##### FUNCTION gtk_file_chooser_set_preview_widget ##### -->
1042 <!-- ##### FUNCTION gtk_file_chooser_get_preview_widget ##### -->
1051 <!-- ##### FUNCTION gtk_file_chooser_set_preview_widget_active ##### -->
1060 <!-- ##### FUNCTION gtk_file_chooser_get_preview_widget_active ##### -->
1069 <!-- ##### FUNCTION gtk_file_chooser_set_use_preview_label ##### -->
1078 <!-- ##### FUNCTION gtk_file_chooser_get_use_preview_label ##### -->
1087 <!-- ##### FUNCTION gtk_file_chooser_get_preview_filename ##### -->
1096 <!-- ##### FUNCTION gtk_file_chooser_get_preview_uri ##### -->
1105 <!-- ##### FUNCTION gtk_file_chooser_set_extra_widget ##### -->
1114 <!-- ##### FUNCTION gtk_file_chooser_get_extra_widget ##### -->
1123 <!-- ##### FUNCTION gtk_file_chooser_add_filter ##### -->
1132 <!-- ##### FUNCTION gtk_file_chooser_remove_filter ##### -->
1141 <!-- ##### FUNCTION gtk_file_chooser_list_filters ##### -->
1150 <!-- ##### FUNCTION gtk_file_chooser_set_filter ##### -->
1159 <!-- ##### FUNCTION gtk_file_chooser_get_filter ##### -->
1168 <!-- ##### FUNCTION gtk_file_chooser_add_shortcut_folder ##### -->
1179 <!-- ##### FUNCTION gtk_file_chooser_remove_shortcut_folder ##### -->
1190 <!-- ##### FUNCTION gtk_file_chooser_list_shortcut_folders ##### -->
1199 <!-- ##### FUNCTION gtk_file_chooser_add_shortcut_folder_uri ##### -->
1210 <!-- ##### FUNCTION gtk_file_chooser_remove_shortcut_folder_uri ##### -->
1221 <!-- ##### FUNCTION gtk_file_chooser_list_shortcut_folder_uris ##### -->
1234 sgml-parent-document: ("../gtk-docs.sgml" "book" "refentry")