]> Pileus Git - ~andy/gtk/blob - docs/reference/gtk/tmpl/gtkfilesel.sgml
Update a bit.
[~andy/gtk] / docs / reference / gtk / tmpl / gtkfilesel.sgml
1 <!-- ##### SECTION Title ##### -->
2 GtkFileSelection
3
4 <!-- ##### SECTION Short_Description ##### -->
5 prompt the user for a file or directory name.
6
7 <!-- ##### SECTION Long_Description ##### -->
8 <para>
9 GtkFileSelection should be used to retrieve file or directory names from the user. It will create a new dialog window containing a directory list, and a file list corresponding to the current working directory. The filesystem can be navigated using the directory list or the drop-down history menu. Alternatively, the TAB key can be used to navigate using filename completion - common in text based editors such as emacs and jed.
10 </para>
11 <para>
12 File selection dialogs are created with a call to gtk_file_selection_new().
13 </para>
14 <para>
15 The default filename can be set using gtk_file_selection_set_filename() and the selected filename retrieved using gtk_file_selection_get_filename().
16 </para>
17 <para>
18 Use gtk_file_selection_complete() to display files and directories
19 that match a given pattern. This can be used for example, to show only
20 *.txt files, or only files beginning with gtk*.
21 </para>
22 <para>
23 Simple file operations; create directory, delete file, and rename file, are available from buttons at the top of the dialog. These can be hidden using gtk_file_selection_hide_fileop_buttons() and shown again using gtk_file_selection_show_fileop_buttons().
24 </para>
25 <para>
26 <example>
27 <title>Getting a filename from the user</title>
28 <programlisting>
29
30 /* The file selection widget and the string to store the chosen filename */
31
32 GtkWidget *file_selector;
33 gchar *selected_filename;
34
35 void store_filename(GtkFileSelection *selector, gpointer user_data) {
36    selected_filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION(file_selector));
37 }
38
39 void create_file_selection(void) {
40
41    /* Create the selector */
42    
43    file_selector = gtk_file_selection_new("Please select a file for editing.");
44    
45    gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION(file_selector)->ok_button),
46                            "clicked", GTK_SIGNAL_FUNC (store_filename), NULL);
47                            
48    /* Ensure that the dialog box is destroyed when the user clicks a button. */
49    
50    gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION(file_selector)->ok_button),
51                                           "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy),
52                                           (gpointer) file_selector);
53
54    gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION(file_selector)->cancel_button),
55                                           "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy),
56                                           (gpointer) file_selector);
57    
58    /* Display that dialog */
59    
60    gtk_widget_show (file_selector);
61 }
62
63 </programlisting>
64 </example>
65 </para>
66
67 <!-- ##### SECTION See_Also ##### -->
68
69 <para>
70 <variablelist>
71 <varlistentry>
72 <term>#GtkDialog</term>
73 <listitem><para>Add your own widgets into the #GtkFileSelection.</para></listitem>
74 </varlistentry>
75 </variablelist>
76 </para>
77
78 <!-- ##### STRUCT GtkFileSelection ##### -->
79 <para>
80 The #GtkFileSelection struct contains the following #GtkWidget fields:
81
82 <informaltable pgwide=1 frame="none" role="struct">
83 <tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*">
84 <tbody>
85
86 <row>
87 <entry>*fileop_dialog;</entry>
88 <entry>the dialog box used to display the #GtkFileSelection. It can be customized by adding/removing widgets from it using the standard #GtkDialog functions.</entry>
89 </row>
90
91 <row>
92 <entry>*dir_list, *file_list;</entry>
93 <entry>the two #GtkCList widgets corresponding to directories and files.</entry>
94 </row>
95
96 <row>
97 <entry>*ok_button, *cancel_button;</entry>
98 <entry>the two main buttons that signals should be connected to in order to perform an action when the user hits either OK or Cancel.</entry>
99 </row>
100
101 <row>
102 <entry>*history_pulldown;</entry>
103 <entry>the #GtkOptionMenu used to create the drop-down directory history.</entry>
104 </row>
105
106 <row>
107 <entry>*fileop_c_dir, *fileop_del_file, *fileop_ren_file;</entry>
108 <entry>the buttons that appear at the top of the file selection dialog. These "operation buttons" can be hidden and redisplayed with gtk_file_selection_hide_fileop_buttons() and  gtk_file_selection_show_fileop_buttons() respectively.</entry>
109 </row>
110
111 </tbody></tgroup></informaltable>
112
113 </para>
114
115
116 <!-- ##### FUNCTION gtk_file_selection_new ##### -->
117 <para>
118 Creates a new file selection dialog box. By default it will contain a #GtkCList of the application's current working directory, and a file listing. Operation buttons that allow the user to create a directory, delete files and rename files, are also present.
119 </para>
120
121 @title: a message that will be placed in the file requestor's titlebar.
122 @Returns: the new file selection.
123
124
125 <!-- ##### FUNCTION gtk_file_selection_set_filename ##### -->
126 <para>
127 Sets a default path for the file requestor. If @filename includes a directory path, then the requestor will open with that path as its current working directory.
128
129 </para>
130
131 @filesel: a #GtkFileSelection.
132 @filename: a string to set as the default file name.
133
134
135 <!-- ##### FUNCTION gtk_file_selection_get_filename ##### -->
136 <para>
137 Retrieves the currently selected filename from the file selection dialog. If no file is selected then the selected directory path is returned.
138 </para>
139
140 @filesel: a #GtkFileSelection
141 @Returns: a string containing the selected file's full path.
142
143
144 <!-- ##### FUNCTION gtk_file_selection_complete ##### -->
145 <para>
146 Will attempt to match @pattern to a valid filenames or subdirectories in the current directory. If a match can be made, the matched filename will appear in the text entry field of the file selection dialog.
147 If a partial match can be made, the "Files" list will contain those
148 file names which have been partially matched, and the "Directories"
149 list those directories which have been partially matched.
150 </para>
151
152 @filesel: a #GtkFileSelection.
153 @pattern: a string of characters which may or may not match any filenames in the current directory.
154
155
156 <!-- ##### FUNCTION gtk_file_selection_show_fileop_buttons ##### -->
157 <para>
158 Shows the file operation buttons, if they have previously been hidden. The rest of the widgets in the dialog will be resized accordingly.
159 </para>
160
161 @filesel: a #GtkFileSelection.
162
163
164 <!-- ##### FUNCTION gtk_file_selection_hide_fileop_buttons ##### -->
165 <para>
166 Hides the file operation buttons that normally appear at the top of the dialog. Useful if you wish to create a custom file selector, based on #GtkFileSelection.
167 </para>
168
169 @filesel: a #GtkFileSelection.
170
171
172 <!-- ##### ARG GtkFileSelection:show-fileops ##### -->
173 <para>
174
175 </para>
176
177 <!-- ##### ARG GtkFileSelection:filename ##### -->
178 <para>
179
180 </para>
181