]> Pileus Git - ~andy/gtk/blob - docs/reference/gtk/tmpl/gtkfilechooser.sgml
Create an empty target list if targets is NULL.
[~andy/gtk] / docs / reference / gtk / tmpl / gtkfilechooser.sgml
1 <!-- ##### SECTION Title ##### -->
2 GtkFileChooser
3
4 <!-- ##### SECTION Short_Description ##### -->
5 File chooser interface used by #GtkFileChooserWidget and #GtkFileChooserDialog.
6
7 <!-- ##### SECTION Long_Description ##### -->
8     <para>
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.
16     </para>
17
18     <refsect2 id="gtkfilechooser-encodings">
19       <title>File Names and Encodings</title>
20
21       <para>
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
30         variable.
31       </para>
32
33       <important>
34         <para>
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.
43         </para>
44       </important>
45     </refsect2>
46
47     <refsect2 id="gtkfilechooser-preview">
48       <title>Adding a Preview Widget</title>
49
50       <para>
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.
57       </para>
58
59       <para>
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
66         generate a preview.
67       </para>
68
69       <example id="example-gtkfilechooser-preview">
70         <title>Sample Usage</title>
71
72         <programlisting>
73 {
74   GtkImage *preview;
75
76   ...
77
78   preview = gtk_image_new (<!-- -->);
79
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);
83 }
84
85 static void
86 update_preview_cb (GtkFileChooser *file_chooser, gpointer data)
87 {
88   GtkWidget *preview;
89   char *filename;
90   GdkPixbuf *pixbuf;
91   gboolean have_preview;
92
93   preview = GTK_WIDGET (data);
94   filename = gtk_file_chooser_get_preview_filename (file_chooser);
95
96   pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 128, 128, NULL);
97   have_preview = (pixbuf != NULL);
98   g_free (filename);
99
100   gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf);
101   if (pixbuf)
102     gdk_pixbuf_unref (pixbuf);
103
104   gtk_file_chooser_set_preview_widget_active (file_chooser, have_preview);
105 }
106         </programlisting>
107       </example>
108     </refsect2>
109
110     <refsect2 id="gtkfilechooser-extra">
111       <title>Adding Extra Widgets</title>
112
113       <para>
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.
120       </para>
121
122       <example id="example-gtkfilechooser-extra">
123         <title>Sample Usage</title>
124
125         <programlisting>
126 {
127   GtkWidget *toggle;
128
129   ...
130
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);
134 }
135         </programlisting>
136       </example>
137
138       <note>
139         <para>
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.
144         </para>
145       </note>
146     </refsect2>
147
148     <refsect2 id="gtkfilechooser-key-bindings">
149       <title>Key Bindings</title>
150
151       <para>
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.
158       </para>
159
160       <example id="gtkfilechooser-key-binding-example">
161         <title>GtkFileChooser key binding example</title>
162
163         <para>
164           The default keys that activate the key-binding signals in
165           <classname>GtkFileChooserDefaultClass</classname> are as
166           follows:
167         </para>
168
169         <informaltable>
170           <tgroup cols="2">
171             <tbody>
172               <row>
173                 <entry>Signal name</entry>
174                 <entry>Key</entry>
175               </row>
176               <row>
177                 <entry>location-popup</entry>
178                 <entry><keycombo><keycap>Control</keycap><keycap>L</keycap></keycombo></entry>
179               </row>
180               <row>
181                 <entry>up-folder</entry>
182                 <entry><keycombo><keycap>Alt</keycap><keycap>Up</keycap></keycombo></entry>
183               </row>
184               <row>
185                 <entry>down-folder</entry>
186                 <entry><keycombo><keycap>Alt</keycap><keycap>Down</keycap></keycombo></entry>
187               </row>
188               <row>
189                 <entry>home-folder</entry>
190                 <entry><keycombo><keycap>Alt</keycap><keycap>Home</keycap></keycombo></entry>
191               </row>
192             </tbody>
193           </tgroup>
194         </informaltable>
195
196         <para>
197           To change these defaults to something else, you could
198           include the following fragment in your
199           <filename>.gtkrc-2.0</filename> file:
200         </para>
201
202         <programlisting>
203 binding "my-own-gtkfilechooser-bindings" {
204         bind "&lt;Alt&gt;&lt;Shift&gt;l" {
205                 "location-popup" ()
206         }
207         bind "&lt;Alt&gt;&lt;Shift&gt;Up" {
208                 "up-folder" ()
209         }
210         bind "&lt;Alt&gt;&lt;Shift&gt;Down" {
211                 "down-folder" ()
212         }
213         bind "&lt;Alt&gt;&lt;Shift&gt;Home" {
214                 "home-folder-folder" ()
215         }
216 }
217
218 class "GtkFileChooserDefault" binding "my-own-gtkfilechooser-bindings"
219         </programlisting>
220       </example>
221
222       <refsect3 id="GtkFileChooserDefault-location-popup">
223         <title>The &quot;GtkFileChooserDefault::location-popup&quot; signal</title>
224
225         <programlisting>
226           void user_function (GtkFileChooserDefault *chooser,
227                               <link linkend="gpointer">gpointer</link> user_data);
228         </programlisting>
229
230         <para>
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>.
235         </para>
236
237         <variablelist role="params">
238           <varlistentry>
239             <term><parameter>chooser</parameter>&nbsp;:</term>
240             <listitem>
241               <simpara>
242                 the object which received the signal.
243               </simpara>
244             </listitem>
245           </varlistentry>
246           <varlistentry>
247             <term><parameter>user_data</parameter>&nbsp;:</term>
248             <listitem>
249               <simpara>
250                 user data set when the signal handler was connected.
251               </simpara>
252             </listitem>
253           </varlistentry>
254         </variablelist>
255       </refsect3>
256
257       <refsect3 id="GtkFileChooserDefault-up-folder">
258         <title>The &quot;GtkFileChooserDefault::up-folder&quot; signal</title>
259
260         <programlisting>
261           void user_function (GtkFileChooserDefault *chooser,
262                               <link linkend="gpointer">gpointer</link> user_data);
263         </programlisting>
264
265         <para>
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
268           is bound to
269           <keycombo><keycap>Alt</keycap><keycap>Up</keycap></keycombo>.
270         </para>
271
272         <variablelist role="params">
273           <varlistentry>
274             <term><parameter>chooser</parameter>&nbsp;:</term>
275             <listitem>
276               <simpara>
277                 the object which received the signal.
278               </simpara>
279             </listitem>
280           </varlistentry>
281           <varlistentry>
282             <term><parameter>user_data</parameter>&nbsp;:</term>
283             <listitem>
284               <simpara>
285                 user data set when the signal handler was connected.
286               </simpara>
287             </listitem>
288           </varlistentry>
289         </variablelist>
290       </refsect3>
291
292       <refsect3 id="GtkFileChooserDefault-down-folder">
293         <title>The &quot;GtkFileChooserDefault::down-folder&quot; signal</title>
294
295         <programlisting>
296           void user_function (GtkFileChooserDefault *chooser,
297                               <link linkend="gpointer">gpointer</link> user_data);
298         </programlisting>
299
300         <para>
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>.
309         </para>
310
311         <variablelist role="params">
312           <varlistentry>
313             <term><parameter>chooser</parameter>&nbsp;:</term>
314             <listitem>
315               <simpara>
316                 the object which received the signal.
317               </simpara>
318             </listitem>
319           </varlistentry>
320           <varlistentry>
321             <term><parameter>user_data</parameter>&nbsp;:</term>
322             <listitem>
323               <simpara>
324                 user data set when the signal handler was connected.
325               </simpara>
326             </listitem>
327           </varlistentry>
328         </variablelist>
329       </refsect3>
330
331       <refsect3 id="GtkFileChooserDefault-home-folder">
332         <title>The &quot;GtkFileChooserDefault::home-folder&quot; signal</title>
333
334         <programlisting>
335           void user_function (GtkFileChooserDefault *chooser,
336                               <link linkend="gpointer">gpointer</link> user_data);
337         </programlisting>
338
339         <para>
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>.
343         </para>
344
345         <variablelist role="params">
346           <varlistentry>
347             <term><parameter>chooser</parameter>&nbsp;:</term>
348             <listitem>
349               <simpara>
350                 the object which received the signal.
351               </simpara>
352             </listitem>
353           </varlistentry>
354           <varlistentry>
355             <term><parameter>user_data</parameter>&nbsp;:</term>
356             <listitem>
357               <simpara>
358                 user data set when the signal handler was connected.
359               </simpara>
360             </listitem>
361           </varlistentry>
362         </variablelist>
363       </refsect3>
364     </refsect2>
365
366 <!-- ##### SECTION See_Also ##### -->
367     <para>
368       #GtkFileChooserDialog, #GtkFileChooserWidget
369     </para>
370
371 <!-- ##### STRUCT GtkFileChooser ##### -->
372 <para>
373
374 </para>
375
376
377 <!-- ##### ENUM GtkFileChooserAction ##### -->
378     <para>
379       Describes whether a #GtkFileChooser is being used to open
380       existing files or to save to a possibly new file.
381     </para>
382
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
387     filename.
388 @GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER: Indicates an Open mode for
389     selecting folders.  The file chooser will let the user pick an
390     existing folder.
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
393     new folder.
394
395 <!-- ##### MACRO GTK_FILE_CHOOSER_ERROR ##### -->
396     <para>
397       Used to get the #GError quark for #GtkFileChooser errors.
398     </para>
399
400
401
402 <!-- ##### ENUM GtkFileChooserError ##### -->
403     <para>
404       These identify the various errors that can occur while calling
405       #GtkFileChooser functions.
406     </para>
407
408 @GTK_FILE_CHOOSER_ERROR_NONEXISTENT: Indicates that a file does not exist.
409 @GTK_FILE_CHOOSER_ERROR_BAD_FILENAME: Indicates a malformed filename.
410
411 <!-- ##### FUNCTION gtk_file_chooser_error_quark ##### -->
412 <para>
413
414 </para>
415
416 @Returns: 
417
418
419 <!-- ##### FUNCTION gtk_file_chooser_set_action ##### -->
420 <para>
421
422 </para>
423
424 @chooser: 
425 @action: 
426
427
428 <!-- ##### FUNCTION gtk_file_chooser_get_action ##### -->
429 <para>
430
431 </para>
432
433 @chooser: 
434 @Returns: 
435
436
437 <!-- ##### FUNCTION gtk_file_chooser_set_local_only ##### -->
438 <para>
439
440 </para>
441
442 @chooser: 
443 @local_only: 
444 <!-- # Unused Parameters # -->
445 @files_only: 
446
447
448 <!-- ##### FUNCTION gtk_file_chooser_get_local_only ##### -->
449 <para>
450
451 </para>
452
453 @chooser: 
454 @Returns: 
455
456
457 <!-- ##### FUNCTION gtk_file_chooser_set_select_multiple ##### -->
458 <para>
459
460 </para>
461
462 @chooser: 
463 @select_multiple: 
464
465
466 <!-- ##### FUNCTION gtk_file_chooser_get_select_multiple ##### -->
467 <para>
468
469 </para>
470
471 @chooser: 
472 @Returns: 
473
474
475 <!-- ##### FUNCTION gtk_file_chooser_set_current_name ##### -->
476 <para>
477
478 </para>
479
480 @chooser: 
481 @name: 
482
483
484 <!-- ##### FUNCTION gtk_file_chooser_get_filename ##### -->
485 <para>
486
487 </para>
488
489 @chooser: 
490 @Returns: 
491
492
493 <!-- ##### FUNCTION gtk_file_chooser_set_filename ##### -->
494 <para>
495
496 </para>
497
498 @chooser: 
499 @filename: 
500 @Returns: 
501
502
503 <!-- ##### FUNCTION gtk_file_chooser_select_filename ##### -->
504 <para>
505
506 </para>
507
508 @chooser: 
509 @filename: 
510 @Returns: 
511
512
513 <!-- ##### FUNCTION gtk_file_chooser_unselect_filename ##### -->
514 <para>
515
516 </para>
517
518 @chooser: 
519 @filename: 
520
521
522 <!-- ##### FUNCTION gtk_file_chooser_select_all ##### -->
523 <para>
524
525 </para>
526
527 @chooser: 
528
529
530 <!-- ##### FUNCTION gtk_file_chooser_unselect_all ##### -->
531 <para>
532
533 </para>
534
535 @chooser: 
536
537
538 <!-- ##### FUNCTION gtk_file_chooser_get_filenames ##### -->
539 <para>
540
541 </para>
542
543 @chooser: 
544 @Returns: 
545
546
547 <!-- ##### FUNCTION gtk_file_chooser_set_current_folder ##### -->
548 <para>
549
550 </para>
551
552 @chooser: 
553 @filename: 
554 @Returns: 
555
556
557 <!-- ##### FUNCTION gtk_file_chooser_get_current_folder ##### -->
558 <para>
559
560 </para>
561
562 @chooser: 
563 @Returns: 
564
565
566 <!-- ##### FUNCTION gtk_file_chooser_get_uri ##### -->
567 <para>
568
569 </para>
570
571 @chooser: 
572 @Returns: 
573
574
575 <!-- ##### FUNCTION gtk_file_chooser_set_uri ##### -->
576 <para>
577
578 </para>
579
580 @chooser: 
581 @uri: 
582 @Returns: 
583
584
585 <!-- ##### FUNCTION gtk_file_chooser_select_uri ##### -->
586 <para>
587
588 </para>
589
590 @chooser: 
591 @uri: 
592 @Returns: 
593
594
595 <!-- ##### FUNCTION gtk_file_chooser_unselect_uri ##### -->
596 <para>
597
598 </para>
599
600 @chooser: 
601 @uri: 
602
603
604 <!-- ##### FUNCTION gtk_file_chooser_get_uris ##### -->
605 <para>
606
607 </para>
608
609 @chooser: 
610 @Returns: 
611
612
613 <!-- ##### FUNCTION gtk_file_chooser_set_current_folder_uri ##### -->
614 <para>
615
616 </para>
617
618 @chooser: 
619 @uri: 
620 @Returns: 
621
622
623 <!-- ##### FUNCTION gtk_file_chooser_get_current_folder_uri ##### -->
624 <para>
625
626 </para>
627
628 @chooser: 
629 @Returns: 
630
631
632 <!-- ##### FUNCTION gtk_file_chooser_set_preview_widget ##### -->
633 <para>
634
635 </para>
636
637 @chooser: 
638 @preview_widget: 
639
640
641 <!-- ##### FUNCTION gtk_file_chooser_get_preview_widget ##### -->
642 <para>
643
644 </para>
645
646 @chooser: 
647 @Returns: 
648
649
650 <!-- ##### FUNCTION gtk_file_chooser_set_preview_widget_active ##### -->
651 <para>
652
653 </para>
654
655 @chooser: 
656 @active: 
657
658
659 <!-- ##### FUNCTION gtk_file_chooser_get_preview_widget_active ##### -->
660 <para>
661
662 </para>
663
664 @chooser: 
665 @Returns: 
666
667
668 <!-- ##### FUNCTION gtk_file_chooser_set_use_preview_label ##### -->
669 <para>
670
671 </para>
672
673 @chooser: 
674 @use_label: 
675
676
677 <!-- ##### FUNCTION gtk_file_chooser_get_use_preview_label ##### -->
678 <para>
679
680 </para>
681
682 @chooser: 
683 @Returns: 
684
685
686 <!-- ##### FUNCTION gtk_file_chooser_get_preview_filename ##### -->
687 <para>
688
689 </para>
690
691 @chooser: 
692 @Returns: 
693 <!-- # Unused Parameters # -->
694 @file_chooser: 
695
696
697 <!-- ##### FUNCTION gtk_file_chooser_get_preview_uri ##### -->
698 <para>
699
700 </para>
701
702 @chooser: 
703 @Returns: 
704 <!-- # Unused Parameters # -->
705 @file_chooser: 
706
707
708 <!-- ##### FUNCTION gtk_file_chooser_set_extra_widget ##### -->
709 <para>
710
711 </para>
712
713 @chooser: 
714 @extra_widget: 
715
716
717 <!-- ##### FUNCTION gtk_file_chooser_get_extra_widget ##### -->
718 <para>
719
720 </para>
721
722 @chooser: 
723 @Returns: 
724
725
726 <!-- ##### FUNCTION gtk_file_chooser_add_filter ##### -->
727 <para>
728
729 </para>
730
731 @chooser: 
732 @filter: 
733
734
735 <!-- ##### FUNCTION gtk_file_chooser_remove_filter ##### -->
736 <para>
737
738 </para>
739
740 @chooser: 
741 @filter: 
742
743
744 <!-- ##### FUNCTION gtk_file_chooser_list_filters ##### -->
745 <para>
746
747 </para>
748
749 @chooser: 
750 @Returns: 
751
752
753 <!-- ##### FUNCTION gtk_file_chooser_set_filter ##### -->
754 <para>
755
756 </para>
757
758 @chooser: 
759 @filter: 
760
761
762 <!-- ##### FUNCTION gtk_file_chooser_get_filter ##### -->
763 <para>
764
765 </para>
766
767 @chooser: 
768 @Returns: 
769
770
771 <!-- ##### FUNCTION gtk_file_chooser_add_shortcut_folder ##### -->
772 <para>
773
774 </para>
775
776 @chooser: 
777 @folder: 
778 @error: 
779 @Returns: 
780
781
782 <!-- ##### FUNCTION gtk_file_chooser_remove_shortcut_folder ##### -->
783 <para>
784
785 </para>
786
787 @chooser: 
788 @folder: 
789 @error: 
790 @Returns: 
791
792
793 <!-- ##### FUNCTION gtk_file_chooser_list_shortcut_folders ##### -->
794 <para>
795
796 </para>
797
798 @chooser: 
799 @Returns: 
800
801
802 <!-- ##### FUNCTION gtk_file_chooser_add_shortcut_folder_uri ##### -->
803 <para>
804
805 </para>
806
807 @chooser: 
808 @uri: 
809 @error: 
810 @Returns: 
811 <!-- # Unused Parameters # -->
812 @folder: 
813
814
815 <!-- ##### FUNCTION gtk_file_chooser_remove_shortcut_folder_uri ##### -->
816 <para>
817
818 </para>
819
820 @chooser: 
821 @uri: 
822 @error: 
823 @Returns: 
824 <!-- # Unused Parameters # -->
825 @folder: 
826
827
828 <!-- ##### FUNCTION gtk_file_chooser_list_shortcut_folder_uris ##### -->
829 <para>
830
831 </para>
832
833 @chooser: 
834 @Returns: 
835
836
837
838 <!--
839 Local variables:
840 mode: sgml
841 sgml-parent-document: ("../gtk-docs.sgml" "book" "refentry")
842 End:
843 -->
844
845
846 <!-- ##### SIGNAL GtkFileChooser::current-folder-changed ##### -->
847 <para>
848
849 </para>
850
851 @filechooser: the object which received the signal.
852
853 <!-- ##### SIGNAL GtkFileChooser::file-activated ##### -->
854 <para>
855
856 </para>
857
858 @filechooser: the object which received the signal.
859
860 <!-- ##### SIGNAL GtkFileChooser::selection-changed ##### -->
861 <para>
862
863 </para>
864
865 @filechooser: the object which received the signal.
866
867 <!-- ##### SIGNAL GtkFileChooser::update-preview ##### -->
868 <para>
869
870 </para>
871
872 @filechooser: the object which received the signal.
873