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