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 gdk_pixbuf_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>;
217 <entry>up-folder</entry>
219 <keycombo><keycap>Alt</keycap><keycap>Up</keycap></keycombo><footnote>
221 Both the individual Up key and the numeric
222 keypad's Up key are supported.
226 <keycap>Backspace</keycap>
230 <entry>down-folder</entry>
231 <entry><keycombo><keycap>Alt</keycap><keycap>Down</keycap></keycombo></entry>
234 <entry>home-folder</entry>
235 <entry><keycombo><keycap>Alt</keycap><keycap>Home</keycap></keycombo></entry>
238 <entry>desktop-folder</entry>
239 <entry><keycombo><keycap>Alt</keycap><keycap>D</keycap></keycombo></entry>
246 You can change these defaults to something else. For
247 example, to add a <keycap>Shift</keycap> modifier to a few
248 of the default bindings, you can include the following
249 fragment in your <filename>.gtkrc-2.0</filename> file:
253 binding "my-own-gtkfilechooser-bindings" {
254 bind "<Alt><Shift>Up" {
257 bind "<Alt><Shift>Down" {
260 bind "<Alt><Shift>Home" {
265 class "GtkFileChooserDefault" binding "my-own-gtkfilechooser-bindings"
269 <refsect3 id="GtkFileChooserDefault-location-popup">
270 <title>The "GtkFileChooserDefault::location-popup" signal</title>
273 void user_function (GtkFileChooserDefault *chooser,
275 <link linkend="gpointer">gpointer</link> user_data);
279 This is used to make the file chooser show a "Location"
280 dialog which the user can use to manually type the name of
281 the file he wishes to select. The
282 <parameter>path</parameter> argument is a string that gets
283 put in the text entry for the file name. By default this is bound to
284 <keycombo><keycap>Control</keycap><keycap>L</keycap></keycombo>
285 with a <parameter>path</parameter> string of "" (the empty
286 string); it is also bound to <keycap>/</keycap> with a
287 <parameter>path</parameter> string of "<literal>/</literal>"
288 (a slash): this lets you type <keycap>/</keycap> and
289 immediately type a path name.
292 <variablelist role="params">
294 <term><parameter>chooser</parameter> :</term>
297 the object which received the signal.
302 <term><parameter>path</parameter> :</term>
305 default contents for the text entry for the file name
310 <term><parameter>user_data</parameter> :</term>
313 user data set when the signal handler was connected.
321 You can create your own bindings for the
322 <symbol>location-popup</symbol> signal with custom
323 <parameter>path</parameter> strings, and have a crude form
324 of easily-to-type bookmarks. For example, say you access
325 the path <filename>/home/username/misc</filename> very
326 frequently. You could then create an <keycombo>
327 <keycap>Alt</keycap> <keycap>M</keycap> </keycombo>
328 shortcut by including the following in your
329 <filename>.gtkrc-2.0</filename>:
333 binding "misc-shortcut" {
334 bind "<Alt>M" {
335 "location-popup" ("/home/username/misc")
339 class "GtkFileChooserDefault" binding "misc-shortcut"
344 <refsect3 id="GtkFileChooserDefault-up-folder">
345 <title>The "GtkFileChooserDefault::up-folder" signal</title>
348 void user_function (GtkFileChooserDefault *chooser,
349 <link linkend="gpointer">gpointer</link> user_data);
353 This is used to make the file chooser go to the parent of
354 the current folder in the file hierarchy. By default this
355 is bound to <keycap>Backspace</keycap> and
356 <keycombo><keycap>Alt</keycap><keycap>Up</keycap></keycombo>
357 (the Up key in the numeric keypad also works).
360 <variablelist role="params">
362 <term><parameter>chooser</parameter> :</term>
365 the object which received the signal.
370 <term><parameter>user_data</parameter> :</term>
373 user data set when the signal handler was connected.
380 <refsect3 id="GtkFileChooserDefault-down-folder">
381 <title>The "GtkFileChooserDefault::down-folder" signal</title>
384 void user_function (GtkFileChooserDefault *chooser,
385 <link linkend="gpointer">gpointer</link> user_data);
389 This is used to make the file chooser go to a child of the
390 current folder in the file hierarchy. The subfolder that
391 will be used is displayed in the path bar widget of the file
392 chooser. For example, if the path bar is showing
393 "/foo/<emphasis>bar/</emphasis>baz", then this will cause
394 the file chooser to switch to the "baz" subfolder. By
395 default this is bound to
396 <keycombo><keycap>Alt</keycap><keycap>Down</keycap></keycombo>
397 (the Down key in the numeric keypad also works).
400 <variablelist role="params">
402 <term><parameter>chooser</parameter> :</term>
405 the object which received the signal.
410 <term><parameter>user_data</parameter> :</term>
413 user data set when the signal handler was connected.
420 <refsect3 id="GtkFileChooserDefault-home-folder">
421 <title>The "GtkFileChooserDefault::home-folder" signal</title>
424 void user_function (GtkFileChooserDefault *chooser,
425 <link linkend="gpointer">gpointer</link> user_data);
429 This is used to make the file chooser show the user's home
430 folder in the file list. By default this is bound to
431 <keycombo><keycap>Alt</keycap><keycap>Home</keycap></keycombo>
432 (the Home key in the numeric keypad also works).
435 <variablelist role="params">
437 <term><parameter>chooser</parameter> :</term>
440 the object which received the signal.
445 <term><parameter>user_data</parameter> :</term>
448 user data set when the signal handler was connected.
455 <refsect3 id="GtkFileChooserDefault-desktop-folder">
456 <title>The "GtkFileChooserDefault::desktop-folder" signal</title>
459 void user_function (GtkFileChooserDefault *chooser,
460 <link linkend="gpointer">gpointer</link> user_data);
464 This is used to make the file chooser show the user's Desktop
465 folder in the file list. By default this is bound to
466 <keycombo><keycap>Alt</keycap><keycap>D</keycap></keycombo>.
469 <variablelist role="params">
471 <term><parameter>chooser</parameter> :</term>
474 the object which received the signal.
479 <term><parameter>user_data</parameter> :</term>
482 user data set when the signal handler was connected.
490 <!-- ##### SECTION See_Also ##### -->
492 #GtkFileChooserDialog, #GtkFileChooserWidget, #GtkFileChooserButton
495 <!-- ##### SECTION Stability_Level ##### -->
498 <!-- ##### STRUCT GtkFileChooser ##### -->
504 <!-- ##### SIGNAL GtkFileChooser::confirm-overwrite ##### -->
506 This signal gets emitted whenever it is appropriate to present a
507 confirmation dialog when the user has selected a file name that
508 already exists. The signal only gets emitted when the file
509 chooser is in #GTK_FILE_CHOOSER_ACTION_SAVE mode.
513 Most applications just need to turn on the <link
514 linkend="GtkFileChooser--do-overwrite-confirmation">do-overwrite-confirmation</link>
515 property (or call the
516 gtk_file_chooser_set_do_overwrite_confirmation() function), and
517 they will automatically get a stock confirmation dialog.
518 Applications which need to customize this behavior should do
519 that, and also connect to the <symbol>confirm-overwrite</symbol>
524 A signal handler for this signal must return a
525 #GtkFileChooserConfirmation value, which indicates the action to
526 take. If the handler determines that the user wants to select a
527 different filename, it should return
528 #GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN. If it determines
529 that the user is satisfied with his choice of file name, it
530 should return #GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME.
531 On the other hand, if it determines that the stock confirmation
532 dialog should be used, it should return
533 #GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM. The following example
537 <example id="gtkfilechooser-confirmation">
538 <title>Custom confirmation</title>
541 static GtkFileChooserConfirmation
542 confirm_overwrite_callback (GtkFileChooser *chooser, gpointer data)
546 uri = gtk_file_chooser_get_uri (chooser);
548 if (is_uri_read_only (uri))
550 if (user_wants_to_replace_read_only_file (uri))
551 return GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME;
553 return GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN;
555 return GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM; /* fall back to the default dialog */
560 chooser = gtk_file_chooser_dialog_new (...);
562 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
563 g_signal_connect (chooser, "confirm-overwrite",
564 G_CALLBACK (confirm_overwrite_callback), NULL);
566 if (gtk_dialog_run (chooser) == GTK_RESPONSE_ACCEPT)
567 save_to_file (gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
569 gtk_widget_destroy (chooser);
573 @filechooser: the object which received the signal.
574 @Returns: #GtkFileChooserConfirmation value that indicates which
575 action to take after emitting the signal.
581 <!-- ##### SIGNAL GtkFileChooser::current-folder-changed ##### -->
586 @filechooser: the object which received the signal.
588 <!-- ##### SIGNAL GtkFileChooser::file-activated ##### -->
593 @filechooser: the object which received the signal.
595 <!-- ##### SIGNAL GtkFileChooser::selection-changed ##### -->
600 @filechooser: the object which received the signal.
602 <!-- ##### SIGNAL GtkFileChooser::update-preview ##### -->
607 @filechooser: the object which received the signal.
609 <!-- ##### ARG GtkFileChooser:action ##### -->
614 <!-- ##### ARG GtkFileChooser:do-overwrite-confirmation ##### -->
619 <!-- ##### ARG GtkFileChooser:extra-widget ##### -->
624 <!-- ##### ARG GtkFileChooser:file-system-backend ##### -->
629 <!-- ##### ARG GtkFileChooser:filter ##### -->
634 <!-- ##### ARG GtkFileChooser:local-only ##### -->
639 <!-- ##### ARG GtkFileChooser:preview-widget ##### -->
644 <!-- ##### ARG GtkFileChooser:preview-widget-active ##### -->
649 <!-- ##### ARG GtkFileChooser:select-multiple ##### -->
654 <!-- ##### ARG GtkFileChooser:show-hidden ##### -->
659 <!-- ##### ARG GtkFileChooser:use-preview-label ##### -->
664 <!-- ##### ENUM GtkFileChooserAction ##### -->
666 Describes whether a #GtkFileChooser is being used to open
667 existing files or to save to a possibly new file.
670 @GTK_FILE_CHOOSER_ACTION_OPEN: Indicates open mode. The file chooser
671 will only let the user pick an existing file.
672 @GTK_FILE_CHOOSER_ACTION_SAVE: Indicates save mode. The file chooser
673 will let the user pick an existing file, or type in a new
675 @GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER: Indicates an Open mode for
676 selecting folders. The file chooser will let the user pick an
678 @GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER: Indicates a mode for creating a
679 new folder. The file chooser will let the user name an existing or
682 <!-- ##### ENUM GtkFileChooserConfirmation ##### -->
684 Used as a return value of handlers for the <link
685 linkend="GtkFileChooser-confirm-overwrite">confirm-overwrite</link>
686 signal of a <classname>GtkFileChooser</classname>. This value
687 determines whether the file chooser will present the stock
688 confirmation dialog, accept the user's choice of a filename, or
689 let the user choose another filename.
692 @GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM: The file chooser will present
693 its stock dialog to confirm about overwriting an existing file.
694 @GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME: The file chooser will
695 terminate and accept the user's choice of a file name.
696 @GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN: The file chooser will
697 continue running, so as to let the user select another file name.
703 <!-- ##### MACRO GTK_FILE_CHOOSER_ERROR ##### -->
705 Used to get the #GError quark for #GtkFileChooser errors.
710 <!-- ##### ENUM GtkFileChooserError ##### -->
712 These identify the various errors that can occur while calling
713 #GtkFileChooser functions.
716 @GTK_FILE_CHOOSER_ERROR_NONEXISTENT: Indicates that a file does not exist.
717 @GTK_FILE_CHOOSER_ERROR_BAD_FILENAME: Indicates a malformed filename.
719 <!-- ##### FUNCTION gtk_file_chooser_error_quark ##### -->
727 <!-- ##### FUNCTION gtk_file_chooser_set_action ##### -->
736 <!-- ##### FUNCTION gtk_file_chooser_get_action ##### -->
745 <!-- ##### FUNCTION gtk_file_chooser_set_local_only ##### -->
752 <!-- # Unused Parameters # -->
756 <!-- ##### FUNCTION gtk_file_chooser_get_local_only ##### -->
765 <!-- ##### FUNCTION gtk_file_chooser_set_select_multiple ##### -->
774 <!-- ##### FUNCTION gtk_file_chooser_get_select_multiple ##### -->
783 <!-- ##### FUNCTION gtk_file_chooser_set_show_hidden ##### -->
792 <!-- ##### FUNCTION gtk_file_chooser_get_show_hidden ##### -->
801 <!-- ##### FUNCTION gtk_file_chooser_set_do_overwrite_confirmation ##### -->
807 @do_overwrite_confirmation:
810 <!-- ##### FUNCTION gtk_file_chooser_get_do_overwrite_confirmation ##### -->
819 <!-- ##### FUNCTION gtk_file_chooser_set_current_name ##### -->
828 <!-- ##### FUNCTION gtk_file_chooser_get_filename ##### -->
837 <!-- ##### FUNCTION gtk_file_chooser_set_filename ##### -->
847 <!-- ##### FUNCTION gtk_file_chooser_select_filename ##### -->
857 <!-- ##### FUNCTION gtk_file_chooser_unselect_filename ##### -->
866 <!-- ##### FUNCTION gtk_file_chooser_select_all ##### -->
874 <!-- ##### FUNCTION gtk_file_chooser_unselect_all ##### -->
882 <!-- ##### FUNCTION gtk_file_chooser_get_filenames ##### -->
891 <!-- ##### FUNCTION gtk_file_chooser_set_current_folder ##### -->
901 <!-- ##### FUNCTION gtk_file_chooser_get_current_folder ##### -->
910 <!-- ##### FUNCTION gtk_file_chooser_get_uri ##### -->
919 <!-- ##### FUNCTION gtk_file_chooser_set_uri ##### -->
929 <!-- ##### FUNCTION gtk_file_chooser_select_uri ##### -->
939 <!-- ##### FUNCTION gtk_file_chooser_unselect_uri ##### -->
948 <!-- ##### FUNCTION gtk_file_chooser_get_uris ##### -->
957 <!-- ##### FUNCTION gtk_file_chooser_set_current_folder_uri ##### -->
967 <!-- ##### FUNCTION gtk_file_chooser_get_current_folder_uri ##### -->
976 <!-- ##### FUNCTION gtk_file_chooser_set_preview_widget ##### -->
985 <!-- ##### FUNCTION gtk_file_chooser_get_preview_widget ##### -->
994 <!-- ##### FUNCTION gtk_file_chooser_set_preview_widget_active ##### -->
1003 <!-- ##### FUNCTION gtk_file_chooser_get_preview_widget_active ##### -->
1012 <!-- ##### FUNCTION gtk_file_chooser_set_use_preview_label ##### -->
1021 <!-- ##### FUNCTION gtk_file_chooser_get_use_preview_label ##### -->
1030 <!-- ##### FUNCTION gtk_file_chooser_get_preview_filename ##### -->
1037 <!-- # Unused Parameters # -->
1041 <!-- ##### FUNCTION gtk_file_chooser_get_preview_uri ##### -->
1048 <!-- # Unused Parameters # -->
1052 <!-- ##### FUNCTION gtk_file_chooser_set_extra_widget ##### -->
1061 <!-- ##### FUNCTION gtk_file_chooser_get_extra_widget ##### -->
1070 <!-- ##### FUNCTION gtk_file_chooser_add_filter ##### -->
1079 <!-- ##### FUNCTION gtk_file_chooser_remove_filter ##### -->
1088 <!-- ##### FUNCTION gtk_file_chooser_list_filters ##### -->
1097 <!-- ##### FUNCTION gtk_file_chooser_set_filter ##### -->
1106 <!-- ##### FUNCTION gtk_file_chooser_get_filter ##### -->
1115 <!-- ##### FUNCTION gtk_file_chooser_add_shortcut_folder ##### -->
1126 <!-- ##### FUNCTION gtk_file_chooser_remove_shortcut_folder ##### -->
1137 <!-- ##### FUNCTION gtk_file_chooser_list_shortcut_folders ##### -->
1146 <!-- ##### FUNCTION gtk_file_chooser_add_shortcut_folder_uri ##### -->
1155 <!-- # Unused Parameters # -->
1159 <!-- ##### FUNCTION gtk_file_chooser_remove_shortcut_folder_uri ##### -->
1168 <!-- # Unused Parameters # -->
1172 <!-- ##### FUNCTION gtk_file_chooser_list_shortcut_folder_uris ##### -->
1185 sgml-parent-document: ("../gtk-docs.sgml" "book" "refentry")