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
11 this interface are #GtkFileChooserWidget and
12 #GtkFileChooserDialog. You do not need to write an object that
13 implements the #GtkFileChooser interface unless you are trying
14 to adapt an existing file selector to expose a standard
15 programming interface.
18 <refsect2 id="gtkfilechooser-encodings">
19 <title>File Names and Encodings</title>
22 When the user is finished selecting files in a
23 #GtkFileChooser, your program can get the selected names
24 either as filenames or as URIs. For URIs, the normal escaping
25 rules are applied if the URI contains non-ASCII characters.
26 However, filenames are <emphasis>always</emphasis> returned in
27 the character set specified by the
28 <envar>G_FILENAME_ENCODING</envar> environment variable.
29 Please see the Glib documentation for more details about this
35 This means that while you can pass the result of
36 gtk_file_chooser_get_filename() to
37 <function>open(2)</function> or
38 <function>fopen(3)</function>, you may not be able to
39 directly set it as the text of a #GtkLabel widget unless you
40 convert it first to UTF-8, which all GTK+ widgets expect.
41 You should use g_filename_to_utf8() to convert filenames
42 into strings that can be passed to GTK+ widgets.
47 <refsect2 id="gtkfilechooser-preview">
48 <title>Adding a Preview Widget</title>
51 You can add a custom preview widget to a file chooser and then
52 get notification about when the preview needs to be updated.
53 To install a preview widget, use
54 gtk_file_chooser_set_preview_widget(). Then, connect to the
55 #GtkFileChooser::update-preview signal to get notified when
56 you need to update the contents of the preview.
60 Your callback should use
61 gtk_file_chooser_get_preview_filename() to see what needs
62 previewing. Once you have generated the preview for the
63 corresponding file, you must call
64 gtk_file_chooser_set_preview_widget_active() with a boolean
65 flag that indicates whether your callback could successfully
69 <example id="example-gtkfilechooser-preview">
70 <title>Sample Usage</title>
78 preview = gtk_image_new (<!-- -->);
80 gtk_file_chooser_set_preview_widget (my_file_chooser, preview);
81 g_signal_connect (my_file_chooser, "update-preview",
82 G_CALLBACK (update_preview_cb), preview);
86 update_preview_cb (GtkFileChooser *file_chooser, gpointer data)
91 gboolean have_preview;
93 preview = GTK_WIDGET (data);
94 filename = gtk_file_chooser_get_preview_filename (file_chooser);
96 pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 128, 128, NULL);
97 have_preview = (pixbuf != NULL);
100 gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf);
102 gdk_pixbuf_unref (pixbuf);
104 gtk_file_chooser_set_preview_widget_active (file_chooser, have_preview);
110 <refsect2 id="gtkfilechooser-extra">
111 <title>Adding Extra Widgets</title>
114 You can add extra widgets to a file chooser to provide options
115 that are not present in the default design. For example, you
116 can add a toggle button to give the user the option to open a
117 file in read-only mode. You can use
118 gtk_file_chooser_set_extra_widget() to insert additional
119 widgets in a file chooser.
122 <example id="example-gtkfilechooser-extra">
123 <title>Sample Usage</title>
131 toggle = gtk_check_button_new_with_label ("Open file read-only");
132 gtk_widget_show (toggle);
133 gtk_file_chooser_set_extra_widget (my_file_chooser, toggle);
140 If you want to set more than one extra widget in the file
141 chooser, you can a container such as a GtkVBox or a GtkTable
142 and include your widgets in it. Then, set the container as
143 the whole extra widget.
148 <refsect2 id="gtkfilechooser-key-bindings">
149 <title>Key Bindings</title>
152 Internally, GTK+ implements a file chooser's graphical user
153 interface with the private
154 <classname>GtkFileChooserDefaultClass</classname>. This
155 widget has several <link linkend="gtk-Bindings">key
156 bindings</link> and their associated signals. This section
157 describes the available key binding signals.
160 <example id="gtkfilechooser-key-binding-example">
161 <title>GtkFileChooser key binding example</title>
164 The default keys that activate the key-binding signals in
165 <classname>GtkFileChooserDefaultClass</classname> are as
173 <entry>Signal name</entry>
177 <entry>location-popup</entry>
178 <entry><keycombo><keycap>Control</keycap><keycap>L</keycap></keycombo></entry>
181 <entry>up-folder</entry>
182 <entry><keycombo><keycap>Alt</keycap><keycap>Up</keycap></keycombo></entry>
185 <entry>down-folder</entry>
186 <entry><keycombo><keycap>Alt</keycap><keycap>Down</keycap></keycombo></entry>
189 <entry>home-folder</entry>
190 <entry><keycombo><keycap>Alt</keycap><keycap>Home</keycap></keycombo></entry>
197 To change these defaults to something else, you could
198 include the following fragment in your
199 <filename>.gtkrc-2.0</filename> file:
203 binding "my-own-gtkfilechooser-bindings" {
204 bind "<Alt><Shift>l" {
207 bind "<Alt><Shift>Up" {
210 bind "<Alt><Shift>Down" {
213 bind "<Alt><Shift>Home" {
214 "home-folder-folder" ()
218 class "GtkFileChooserDefault" binding "my-own-gtkfilechooser-bindings"
222 <refsect3 id="GtkFileChooserDefault-location-popup">
223 <title>The "GtkFileChooserDefault::location-popup" signal</title>
226 void user_function (GtkFileChooserDefault *chooser,
227 <link linkend="gpointer">gpointer</link> user_data);
231 This is used to make the file chooser show a "Location"
232 dialog which the user can use to manually type the name of
233 the file he wishes to select. By default this is bound to
234 <keycombo><keycap>Control</keycap><keycap>L</keycap></keycombo>.
237 <variablelist role="params">
239 <term><parameter>chooser</parameter> :</term>
242 the object which received the signal.
247 <term><parameter>user_data</parameter> :</term>
250 user data set when the signal handler was connected.
257 <refsect3 id="GtkFileChooserDefault-up-folder">
258 <title>The "GtkFileChooserDefault::up-folder" signal</title>
261 void user_function (GtkFileChooserDefault *chooser,
262 <link linkend="gpointer">gpointer</link> user_data);
266 This is used to make the file chooser go to the parent of
267 the current folder in the file hierarchy. By default this
269 <keycombo><keycap>Alt</keycap><keycap>Up</keycap></keycombo>.
272 <variablelist role="params">
274 <term><parameter>chooser</parameter> :</term>
277 the object which received the signal.
282 <term><parameter>user_data</parameter> :</term>
285 user data set when the signal handler was connected.
292 <refsect3 id="GtkFileChooserDefault-down-folder">
293 <title>The "GtkFileChooserDefault::down-folder" signal</title>
296 void user_function (GtkFileChooserDefault *chooser,
297 <link linkend="gpointer">gpointer</link> user_data);
301 This is used to make the file chooser go to a child of the
302 current folder in the file hierarchy. The subfolder that
303 will be used is displayed in the path bar widget of the file
304 chooser. For example, if the path bar is showing
305 "/foo/<emphasis>bar/</emphasis>baz", then this will cause
306 the file chooser to switch to the "baz" subfolder. By
307 default this is bound to
308 <keycombo><keycap>Alt</keycap><keycap>Down</keycap></keycombo>.
311 <variablelist role="params">
313 <term><parameter>chooser</parameter> :</term>
316 the object which received the signal.
321 <term><parameter>user_data</parameter> :</term>
324 user data set when the signal handler was connected.
331 <refsect3 id="GtkFileChooserDefault-home-folder">
332 <title>The "GtkFileChooserDefault::home-folder" signal</title>
335 void user_function (GtkFileChooserDefault *chooser,
336 <link linkend="gpointer">gpointer</link> user_data);
340 This is used to make the file chooser show the user's home
341 folder in the file list. By default this is bound to
342 <keycombo><keycap>Alt</keycap><keycap>Home</keycap></keycombo>.
345 <variablelist role="params">
347 <term><parameter>chooser</parameter> :</term>
350 the object which received the signal.
355 <term><parameter>user_data</parameter> :</term>
358 user data set when the signal handler was connected.
366 <!-- ##### SECTION See_Also ##### -->
368 #GtkFileChooserDialog, #GtkFileChooserWidget
371 <!-- ##### STRUCT GtkFileChooser ##### -->
377 <!-- ##### ENUM GtkFileChooserAction ##### -->
379 Describes whether a #GtkFileChooser is being used to open
380 existing files or to save to a possibly new file.
383 @GTK_FILE_CHOOSER_ACTION_OPEN: Indicates open mode. The file chooser
384 will only let the user pick an existing file.
385 @GTK_FILE_CHOOSER_ACTION_SAVE: Indicates save mode. The file chooser
386 will let the user pick an existing file, or type in a new
388 @GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER: Indicates an Open mode for
389 selecting folders. The file chooser will let the user pick an
391 @GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER: Indicates a mode for creating a
392 new folder. The file chooser will let the user name an existing or
395 <!-- ##### MACRO GTK_FILE_CHOOSER_ERROR ##### -->
397 Used to get the #GError quark for #GtkFileChooser errors.
402 <!-- ##### ENUM GtkFileChooserError ##### -->
404 These identify the various errors that can occur while calling
405 #GtkFileChooser functions.
408 @GTK_FILE_CHOOSER_ERROR_NONEXISTENT: Indicates that a file does not exist.
409 @GTK_FILE_CHOOSER_ERROR_BAD_FILENAME: Indicates a malformed filename.
411 <!-- ##### FUNCTION gtk_file_chooser_error_quark ##### -->
419 <!-- ##### FUNCTION gtk_file_chooser_set_action ##### -->
428 <!-- ##### FUNCTION gtk_file_chooser_get_action ##### -->
437 <!-- ##### FUNCTION gtk_file_chooser_set_local_only ##### -->
444 <!-- # Unused Parameters # -->
448 <!-- ##### FUNCTION gtk_file_chooser_get_local_only ##### -->
457 <!-- ##### FUNCTION gtk_file_chooser_set_select_multiple ##### -->
466 <!-- ##### FUNCTION gtk_file_chooser_get_select_multiple ##### -->
475 <!-- ##### FUNCTION gtk_file_chooser_set_current_name ##### -->
484 <!-- ##### FUNCTION gtk_file_chooser_get_filename ##### -->
493 <!-- ##### FUNCTION gtk_file_chooser_set_filename ##### -->
503 <!-- ##### FUNCTION gtk_file_chooser_select_filename ##### -->
513 <!-- ##### FUNCTION gtk_file_chooser_unselect_filename ##### -->
522 <!-- ##### FUNCTION gtk_file_chooser_select_all ##### -->
530 <!-- ##### FUNCTION gtk_file_chooser_unselect_all ##### -->
538 <!-- ##### FUNCTION gtk_file_chooser_get_filenames ##### -->
547 <!-- ##### FUNCTION gtk_file_chooser_set_current_folder ##### -->
557 <!-- ##### FUNCTION gtk_file_chooser_get_current_folder ##### -->
566 <!-- ##### FUNCTION gtk_file_chooser_get_uri ##### -->
575 <!-- ##### FUNCTION gtk_file_chooser_set_uri ##### -->
585 <!-- ##### FUNCTION gtk_file_chooser_select_uri ##### -->
595 <!-- ##### FUNCTION gtk_file_chooser_unselect_uri ##### -->
604 <!-- ##### FUNCTION gtk_file_chooser_get_uris ##### -->
613 <!-- ##### FUNCTION gtk_file_chooser_set_current_folder_uri ##### -->
623 <!-- ##### FUNCTION gtk_file_chooser_get_current_folder_uri ##### -->
632 <!-- ##### FUNCTION gtk_file_chooser_set_preview_widget ##### -->
641 <!-- ##### FUNCTION gtk_file_chooser_get_preview_widget ##### -->
650 <!-- ##### FUNCTION gtk_file_chooser_set_preview_widget_active ##### -->
659 <!-- ##### FUNCTION gtk_file_chooser_get_preview_widget_active ##### -->
668 <!-- ##### FUNCTION gtk_file_chooser_set_use_preview_label ##### -->
677 <!-- ##### FUNCTION gtk_file_chooser_get_use_preview_label ##### -->
686 <!-- ##### FUNCTION gtk_file_chooser_get_preview_filename ##### -->
693 <!-- # Unused Parameters # -->
697 <!-- ##### FUNCTION gtk_file_chooser_get_preview_uri ##### -->
704 <!-- # Unused Parameters # -->
708 <!-- ##### FUNCTION gtk_file_chooser_set_extra_widget ##### -->
717 <!-- ##### FUNCTION gtk_file_chooser_get_extra_widget ##### -->
726 <!-- ##### FUNCTION gtk_file_chooser_add_filter ##### -->
735 <!-- ##### FUNCTION gtk_file_chooser_remove_filter ##### -->
744 <!-- ##### FUNCTION gtk_file_chooser_list_filters ##### -->
753 <!-- ##### FUNCTION gtk_file_chooser_set_filter ##### -->
762 <!-- ##### FUNCTION gtk_file_chooser_get_filter ##### -->
771 <!-- ##### FUNCTION gtk_file_chooser_add_shortcut_folder ##### -->
782 <!-- ##### FUNCTION gtk_file_chooser_remove_shortcut_folder ##### -->
793 <!-- ##### FUNCTION gtk_file_chooser_list_shortcut_folders ##### -->
802 <!-- ##### FUNCTION gtk_file_chooser_add_shortcut_folder_uri ##### -->
811 <!-- # Unused Parameters # -->
815 <!-- ##### FUNCTION gtk_file_chooser_remove_shortcut_folder_uri ##### -->
824 <!-- # Unused Parameters # -->
828 <!-- ##### FUNCTION gtk_file_chooser_list_shortcut_folder_uris ##### -->
841 sgml-parent-document: ("../gtk-docs.sgml" "book" "refentry")
846 <!-- ##### SIGNAL GtkFileChooser::current-folder-changed ##### -->
851 @filechooser: the object which received the signal.
853 <!-- ##### SIGNAL GtkFileChooser::file-activated ##### -->
858 @filechooser: the object which received the signal.
860 <!-- ##### SIGNAL GtkFileChooser::selection-changed ##### -->
865 @filechooser: the object which received the signal.
867 <!-- ##### SIGNAL GtkFileChooser::update-preview ##### -->
872 @filechooser: the object which received the signal.