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>
210 <entry>location-popup</entry>
211 <entry><keycombo><keycap>Control</keycap><keycap>L</keycap></keycombo></entry>
214 <entry>up-folder</entry>
215 <entry><keycombo><keycap>Alt</keycap><keycap>Up</keycap></keycombo></entry>
218 <entry>down-folder</entry>
219 <entry><keycombo><keycap>Alt</keycap><keycap>Down</keycap></keycombo></entry>
222 <entry>home-folder</entry>
223 <entry><keycombo><keycap>Alt</keycap><keycap>Home</keycap></keycombo></entry>
230 To change these defaults to something else, you could
231 include the following fragment in your
232 <filename>.gtkrc-2.0</filename> file:
236 binding "my-own-gtkfilechooser-bindings" {
237 bind "<Alt><Shift>l" {
240 bind "<Alt><Shift>Up" {
243 bind "<Alt><Shift>Down" {
246 bind "<Alt><Shift>Home" {
247 "home-folder-folder" ()
251 class "GtkFileChooserDefault" binding "my-own-gtkfilechooser-bindings"
255 <refsect3 id="GtkFileChooserDefault-location-popup">
256 <title>The "GtkFileChooserDefault::location-popup" signal</title>
259 void user_function (GtkFileChooserDefault *chooser,
260 <link linkend="gpointer">gpointer</link> user_data);
264 This is used to make the file chooser show a "Location"
265 dialog which the user can use to manually type the name of
266 the file he wishes to select. By default this is bound to
267 <keycombo><keycap>Control</keycap><keycap>L</keycap></keycombo>.
270 <variablelist role="params">
272 <term><parameter>chooser</parameter> :</term>
275 the object which received the signal.
280 <term><parameter>user_data</parameter> :</term>
283 user data set when the signal handler was connected.
290 <refsect3 id="GtkFileChooserDefault-up-folder">
291 <title>The "GtkFileChooserDefault::up-folder" signal</title>
294 void user_function (GtkFileChooserDefault *chooser,
295 <link linkend="gpointer">gpointer</link> user_data);
299 This is used to make the file chooser go to the parent of
300 the current folder in the file hierarchy. By default this
302 <keycombo><keycap>Alt</keycap><keycap>Up</keycap></keycombo>.
305 <variablelist role="params">
307 <term><parameter>chooser</parameter> :</term>
310 the object which received the signal.
315 <term><parameter>user_data</parameter> :</term>
318 user data set when the signal handler was connected.
325 <refsect3 id="GtkFileChooserDefault-down-folder">
326 <title>The "GtkFileChooserDefault::down-folder" signal</title>
329 void user_function (GtkFileChooserDefault *chooser,
330 <link linkend="gpointer">gpointer</link> user_data);
334 This is used to make the file chooser go to a child of the
335 current folder in the file hierarchy. The subfolder that
336 will be used is displayed in the path bar widget of the file
337 chooser. For example, if the path bar is showing
338 "/foo/<emphasis>bar/</emphasis>baz", then this will cause
339 the file chooser to switch to the "baz" subfolder. By
340 default this is bound to
341 <keycombo><keycap>Alt</keycap><keycap>Down</keycap></keycombo>.
344 <variablelist role="params">
346 <term><parameter>chooser</parameter> :</term>
349 the object which received the signal.
354 <term><parameter>user_data</parameter> :</term>
357 user data set when the signal handler was connected.
364 <refsect3 id="GtkFileChooserDefault-home-folder">
365 <title>The "GtkFileChooserDefault::home-folder" signal</title>
368 void user_function (GtkFileChooserDefault *chooser,
369 <link linkend="gpointer">gpointer</link> user_data);
373 This is used to make the file chooser show the user's home
374 folder in the file list. By default this is bound to
375 <keycombo><keycap>Alt</keycap><keycap>Home</keycap></keycombo>.
378 <variablelist role="params">
380 <term><parameter>chooser</parameter> :</term>
383 the object which received the signal.
388 <term><parameter>user_data</parameter> :</term>
391 user data set when the signal handler was connected.
399 <!-- ##### SECTION See_Also ##### -->
401 #GtkFileChooserDialog, #GtkFileChooserWidget, #GtkFileChooserButton
404 <!-- ##### SECTION Stability_Level ##### -->
407 <!-- ##### STRUCT GtkFileChooser ##### -->
413 <!-- ##### SIGNAL GtkFileChooser::confirm-overwrite ##### -->
415 This signal gets emitted whenever it is appropriate to present a
416 confirmation dialog when the user has selected a file name that
417 already exists. The signal only gets emitted when the file
418 chooser is in #GTK_FILE_CHOOSER_ACTION_SAVE mode.
422 Most applications just need to turn on the <link
423 linkend="GtkFileChooser--do-overwrite-confirmation">do-overwrite-confirmation</link>
424 property (or call the
425 gtk_file_chooser_set_do_overwrite_confirmation() function), and
426 they will automatically get a stock confirmation dialog.
427 Applications which need to customize this behavior should do
428 that, and also connect to the <symbol>confirm-overwrite</symbol>
433 A signal handler for this signal must return a
434 #GtkFileChooserConfirmation value, which indicates the action to
435 take. If the handler determines that the user wants to select a
436 different filename, it should return
437 #GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN. If it determines
438 that the user is satisfied with his choice of file name, it
439 should return #GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME.
440 On the other hand, if it determines that the stock confirmation
441 dialog should be used, it should return
442 #GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM. The following example
446 <example id="gtkfilechooser-confirmation">
447 <title>Custom confirmation</title>
450 static GtkFileChooserConfirmation
451 confirm_overwrite_callback (GtkFileChooser *chooser, gpointer data)
455 uri = gtk_file_chooser_get_uri (chooser);
457 if (is_uri_read_only (uri))
459 if (user_wants_to_replace_read_only_file (uri))
460 return GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME;
462 return GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN;
464 return GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM; /* fall back to the default dialog */
469 chooser = gtk_file_chooser_dialog_new (...);
471 gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
472 g_signal_connect (chooser, "confirm-overwrite",
473 G_CALLBACK (confirm_overwrite_callback), NULL);
475 if (gtk_dialog_run (chooser) == GTK_RESPONSE_ACCEPT)
476 save_to_file (gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
478 gtk_widget_destroy (chooser);
482 @filechooser: the object which received the signal.
483 @Returns: #GtkFileChooserConfirmation value that indicates which
484 action to take after emitting the signal.
486 <!-- ##### SIGNAL GtkFileChooser::current-folder-changed ##### -->
491 @filechooser: the object which received the signal.
493 <!-- ##### SIGNAL GtkFileChooser::file-activated ##### -->
498 @filechooser: the object which received the signal.
500 <!-- ##### SIGNAL GtkFileChooser::selection-changed ##### -->
505 @filechooser: the object which received the signal.
507 <!-- ##### SIGNAL GtkFileChooser::update-preview ##### -->
512 @filechooser: the object which received the signal.
514 <!-- ##### ARG GtkFileChooser:action ##### -->
519 <!-- ##### ARG GtkFileChooser:do-overwrite-confirmation ##### -->
524 <!-- ##### ARG GtkFileChooser:extra-widget ##### -->
529 <!-- ##### ARG GtkFileChooser:file-system-backend ##### -->
534 <!-- ##### ARG GtkFileChooser:filter ##### -->
539 <!-- ##### ARG GtkFileChooser:local-only ##### -->
544 <!-- ##### ARG GtkFileChooser:preview-widget ##### -->
549 <!-- ##### ARG GtkFileChooser:preview-widget-active ##### -->
554 <!-- ##### ARG GtkFileChooser:select-multiple ##### -->
559 <!-- ##### ARG GtkFileChooser:show-hidden ##### -->
564 <!-- ##### ARG GtkFileChooser:use-preview-label ##### -->
569 <!-- ##### ENUM GtkFileChooserAction ##### -->
571 Describes whether a #GtkFileChooser is being used to open
572 existing files or to save to a possibly new file.
575 @GTK_FILE_CHOOSER_ACTION_OPEN: Indicates open mode. The file chooser
576 will only let the user pick an existing file.
577 @GTK_FILE_CHOOSER_ACTION_SAVE: Indicates save mode. The file chooser
578 will let the user pick an existing file, or type in a new
580 @GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER: Indicates an Open mode for
581 selecting folders. The file chooser will let the user pick an
583 @GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER: Indicates a mode for creating a
584 new folder. The file chooser will let the user name an existing or
587 <!-- ##### ENUM GtkFileChooserConfirmation ##### -->
589 Used as a return value of handlers for the <link
590 linkend="GtkFileChooser-confirm-overwrite">confirm-overwrite</link>
591 signal of a <classname>GtkFileChooser</classname>. This value
592 determines whether the file chooser will present the stock
593 confirmation dialog, accept the user's choice of a filename, or
594 let the user choose another filename.
597 @GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM: The file chooser will present
598 its stock dialog to confirm about overwriting an existing file.
599 @GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME: The file chooser will
600 terminate and accept the user's choice of a file name.
601 @GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN: The file chooser will
602 continue running, so as to let the user select another file name.
604 <!-- ##### MACRO GTK_FILE_CHOOSER_ERROR ##### -->
606 Used to get the #GError quark for #GtkFileChooser errors.
611 <!-- ##### ENUM GtkFileChooserError ##### -->
613 These identify the various errors that can occur while calling
614 #GtkFileChooser functions.
617 @GTK_FILE_CHOOSER_ERROR_NONEXISTENT: Indicates that a file does not exist.
618 @GTK_FILE_CHOOSER_ERROR_BAD_FILENAME: Indicates a malformed filename.
620 <!-- ##### FUNCTION gtk_file_chooser_error_quark ##### -->
628 <!-- ##### FUNCTION gtk_file_chooser_set_action ##### -->
637 <!-- ##### FUNCTION gtk_file_chooser_get_action ##### -->
646 <!-- ##### FUNCTION gtk_file_chooser_set_local_only ##### -->
653 <!-- # Unused Parameters # -->
657 <!-- ##### FUNCTION gtk_file_chooser_get_local_only ##### -->
666 <!-- ##### FUNCTION gtk_file_chooser_set_select_multiple ##### -->
675 <!-- ##### FUNCTION gtk_file_chooser_get_select_multiple ##### -->
684 <!-- ##### FUNCTION gtk_file_chooser_set_show_hidden ##### -->
693 <!-- ##### FUNCTION gtk_file_chooser_get_show_hidden ##### -->
702 <!-- ##### FUNCTION gtk_file_chooser_set_do_overwrite_confirmation ##### -->
708 @do_overwrite_confirmation:
711 <!-- ##### FUNCTION gtk_file_chooser_get_do_overwrite_confirmation ##### -->
720 <!-- ##### FUNCTION gtk_file_chooser_set_current_name ##### -->
729 <!-- ##### FUNCTION gtk_file_chooser_get_filename ##### -->
738 <!-- ##### FUNCTION gtk_file_chooser_set_filename ##### -->
748 <!-- ##### FUNCTION gtk_file_chooser_select_filename ##### -->
758 <!-- ##### FUNCTION gtk_file_chooser_unselect_filename ##### -->
767 <!-- ##### FUNCTION gtk_file_chooser_select_all ##### -->
775 <!-- ##### FUNCTION gtk_file_chooser_unselect_all ##### -->
783 <!-- ##### FUNCTION gtk_file_chooser_get_filenames ##### -->
792 <!-- ##### FUNCTION gtk_file_chooser_set_current_folder ##### -->
802 <!-- ##### FUNCTION gtk_file_chooser_get_current_folder ##### -->
811 <!-- ##### FUNCTION gtk_file_chooser_get_uri ##### -->
820 <!-- ##### FUNCTION gtk_file_chooser_set_uri ##### -->
830 <!-- ##### FUNCTION gtk_file_chooser_select_uri ##### -->
840 <!-- ##### FUNCTION gtk_file_chooser_unselect_uri ##### -->
849 <!-- ##### FUNCTION gtk_file_chooser_get_uris ##### -->
858 <!-- ##### FUNCTION gtk_file_chooser_set_current_folder_uri ##### -->
868 <!-- ##### FUNCTION gtk_file_chooser_get_current_folder_uri ##### -->
877 <!-- ##### FUNCTION gtk_file_chooser_set_preview_widget ##### -->
886 <!-- ##### FUNCTION gtk_file_chooser_get_preview_widget ##### -->
895 <!-- ##### FUNCTION gtk_file_chooser_set_preview_widget_active ##### -->
904 <!-- ##### FUNCTION gtk_file_chooser_get_preview_widget_active ##### -->
913 <!-- ##### FUNCTION gtk_file_chooser_set_use_preview_label ##### -->
922 <!-- ##### FUNCTION gtk_file_chooser_get_use_preview_label ##### -->
931 <!-- ##### FUNCTION gtk_file_chooser_get_preview_filename ##### -->
938 <!-- # Unused Parameters # -->
942 <!-- ##### FUNCTION gtk_file_chooser_get_preview_uri ##### -->
949 <!-- # Unused Parameters # -->
953 <!-- ##### FUNCTION gtk_file_chooser_set_extra_widget ##### -->
962 <!-- ##### FUNCTION gtk_file_chooser_get_extra_widget ##### -->
971 <!-- ##### FUNCTION gtk_file_chooser_add_filter ##### -->
980 <!-- ##### FUNCTION gtk_file_chooser_remove_filter ##### -->
989 <!-- ##### FUNCTION gtk_file_chooser_list_filters ##### -->
998 <!-- ##### FUNCTION gtk_file_chooser_set_filter ##### -->
1007 <!-- ##### FUNCTION gtk_file_chooser_get_filter ##### -->
1016 <!-- ##### FUNCTION gtk_file_chooser_add_shortcut_folder ##### -->
1027 <!-- ##### FUNCTION gtk_file_chooser_remove_shortcut_folder ##### -->
1038 <!-- ##### FUNCTION gtk_file_chooser_list_shortcut_folders ##### -->
1047 <!-- ##### FUNCTION gtk_file_chooser_add_shortcut_folder_uri ##### -->
1056 <!-- # Unused Parameters # -->
1060 <!-- ##### FUNCTION gtk_file_chooser_remove_shortcut_folder_uri ##### -->
1069 <!-- # Unused Parameters # -->
1073 <!-- ##### FUNCTION gtk_file_chooser_list_shortcut_folder_uris ##### -->
1086 sgml-parent-document: ("../gtk-docs.sgml" "book" "refentry")