1
<refentry id="GtkFileSelection">
3
<refentrytitle role="top_of_page">GtkFileSelection</refentrytitle>
4
<manvolnum>3</manvolnum>
5
<refmiscinfo>GTK Library</refmiscinfo>
9
<refname>GtkFileSelection</refname>
10
<refpurpose>Prompt the user for a file or directory name</refpurpose>
11
<!--[<xref linkend="desc" endterm="desc.title"/>]-->
14
<refsynopsisdiv role="synopsis">
15
<title role="synopsis.title">Synopsis</title>
19
#include <gtk/gtk.h>
22
<link linkend="GtkFileSelection-struct">GtkFileSelection</link>;
23
<link linkend="GtkWidget">GtkWidget</link>* <link linkend="gtk-file-selection-new">gtk_file_selection_new</link> (const <link linkend="gchar">gchar</link> *title);
24
<link linkend="void">void</link> <link linkend="gtk-file-selection-set-filename">gtk_file_selection_set_filename</link> (<link linkend="GtkFileSelection">GtkFileSelection</link> *filesel,
25
const <link linkend="gchar">gchar</link> *filename);
26
const <link linkend="gchar">gchar</link>* <link linkend="gtk-file-selection-get-filename">gtk_file_selection_get_filename</link> (<link linkend="GtkFileSelection">GtkFileSelection</link> *filesel);
27
<link linkend="void">void</link> <link linkend="gtk-file-selection-complete">gtk_file_selection_complete</link> (<link linkend="GtkFileSelection">GtkFileSelection</link> *filesel,
28
const <link linkend="gchar">gchar</link> *pattern);
29
<link linkend="void">void</link> <link linkend="gtk-file-selection-show-fileop-buttons">gtk_file_selection_show_fileop_buttons</link>
30
(<link linkend="GtkFileSelection">GtkFileSelection</link> *filesel);
31
<link linkend="void">void</link> <link linkend="gtk-file-selection-hide-fileop-buttons">gtk_file_selection_hide_fileop_buttons</link>
32
(<link linkend="GtkFileSelection">GtkFileSelection</link> *filesel);
33
<link linkend="gchar">gchar</link>** <link linkend="gtk-file-selection-get-selections">gtk_file_selection_get_selections</link> (<link linkend="GtkFileSelection">GtkFileSelection</link> *filesel);
34
<link linkend="void">void</link> <link linkend="gtk-file-selection-set-select-multiple">gtk_file_selection_set_select_multiple</link>
35
(<link linkend="GtkFileSelection">GtkFileSelection</link> *filesel,
36
<link linkend="gboolean">gboolean</link> select_multiple);
37
<link linkend="gboolean">gboolean</link> <link linkend="gtk-file-selection-get-select-multiple">gtk_file_selection_get_select_multiple</link>
38
(<link linkend="GtkFileSelection">GtkFileSelection</link> *filesel);
44
<refsect1 role="object_hierarchy">
45
<title role="object_hierarchy.title">Object Hierarchy</title>
48
<link linkend="GObject">GObject</link>
49
+----<link linkend="GInitiallyUnowned">GInitiallyUnowned</link>
50
+----<link linkend="GtkObject">GtkObject</link>
51
+----<link linkend="GtkWidget">GtkWidget</link>
52
+----<link linkend="GtkContainer">GtkContainer</link>
53
+----<link linkend="GtkBin">GtkBin</link>
54
+----<link linkend="GtkWindow">GtkWindow</link>
55
+----<link linkend="GtkDialog">GtkDialog</link>
63
<refsect1 role="impl_interfaces">
64
<title role="impl_interfaces.title">Implemented Interfaces</title>
66
GtkFileSelection implements
67
<link linkend="AtkImplementorIface">AtkImplementorIface</link>.</para>
72
<refsect1 role="properties">
73
<title role="properties.title">Properties</title>
76
"<link linkend="GtkFileSelection--filename">filename</link>" <link linkend="gchararray">gchararray</link> : Read / Write
77
"<link linkend="GtkFileSelection--select-multiple">select-multiple</link>" <link linkend="gboolean">gboolean</link> : Read / Write
78
"<link linkend="GtkFileSelection--show-fileops">show-fileops</link>" <link linkend="gboolean">gboolean</link> : Read / Write
84
<refsect1 role="desc">
85
<title role="desc.title">Description</title>
87
<link linkend="GtkFileSelection"><type>GtkFileSelection</type></link> should be used to retrieve file or directory names from
88
the user. It will create a new dialog window containing a directory list,
89
and a file list corresponding to the current working directory. The filesystem
90
can be navigated using the directory list or the drop-down history menu.
91
Alternatively, the TAB key can be used to navigate using filename
92
completion - common in text based editors such as emacs and jed.
95
File selection dialogs are created with a call to <link linkend="gtk-file-selection-new"><function>gtk_file_selection_new()</function></link>.
98
The default filename can be set using <link linkend="gtk-file-selection-set-filename"><function>gtk_file_selection_set_filename()</function></link> and the selected filename retrieved using <link linkend="gtk-file-selection-get-filename"><function>gtk_file_selection_get_filename()</function></link>.
101
Use <link linkend="gtk-file-selection-complete"><function>gtk_file_selection_complete()</function></link> to display files and directories
102
that match a given pattern. This can be used for example, to show only
103
*.txt files, or only files beginning with gtk*.
106
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 <link linkend="gtk-file-selection-hide-fileop-buttons"><function>gtk_file_selection_hide_fileop_buttons()</function></link> and shown again using <link linkend="gtk-file-selection-show-fileop-buttons"><function>gtk_file_selection_show_fileop_buttons()</function></link>.
110
<title>Getting a filename from the user.</title>
113
/* The file selection widget and the string to store the chosen filename */
115
void store_filename (GtkWidget *widget, gpointer user_data) {
116
GtkWidget *file_selector = GTK_WIDGET (user_data);
117
const gchar *selected_filename;
119
selected_filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (file_selector));
120
g_print ("Selected filename: %s\n", selected_filename);
123
void create_file_selection (void) {
125
GtkWidget *file_selector;
127
/* Create the selector */
129
file_selector = gtk_file_selection_new ("Please select a file for editing.");
131
g_signal_connect (GTK_FILE_SELECTION (file_selector)->ok_button,
133
G_CALLBACK (store_filename),
136
/* Ensure that the dialog box is destroyed when the user clicks a button. */
138
g_signal_connect_swapped (GTK_FILE_SELECTION (file_selector)->ok_button,
140
G_CALLBACK (gtk_widget_destroy),
143
g_signal_connect_swapped (GTK_FILE_SELECTION (file_selector)->cancel_button,
145
G_CALLBACK (gtk_widget_destroy),
148
/* Display that dialog */
150
gtk_widget_show (file_selector);
158
<refsect1 role="details">
159
<title role="details.title">Details</title>
161
<title><anchor id="GtkFileSelection-struct" role="struct"/>GtkFileSelection</title>
162
<indexterm><primary>GtkFileSelection</primary></indexterm><programlisting>typedef struct {
164
GtkWidget *file_list;
165
GtkWidget *selection_entry;
166
GtkWidget *selection_text;
167
GtkWidget *main_vbox;
168
GtkWidget *ok_button;
169
GtkWidget *cancel_button;
170
GtkWidget *help_button;
171
GtkWidget *history_pulldown;
172
GtkWidget *history_menu;
174
GtkWidget *fileop_dialog;
175
GtkWidget *fileop_entry;
179
GtkWidget *fileop_c_dir;
180
GtkWidget *fileop_del_file;
181
GtkWidget *fileop_ren_file;
183
GtkWidget *button_area;
184
GtkWidget *action_area;
188
The <link linkend="GtkFileSelection"><type>GtkFileSelection</type></link> struct contains the following <link linkend="GtkWidget"><type>GtkWidget</type></link> fields:
190
<informaltable pgwide="1" frame="none" role="struct">
191
<tgroup cols="2"><colspec colwidth="2*"/><colspec colwidth="8*"/>
195
<entry>*fileop_dialog;</entry>
196
<entry>the dialog box used to display the <link linkend="GtkFileSelection"><type>GtkFileSelection</type></link>. It can be customized by adding/removing widgets from it using the standard <link linkend="GtkDialog"><type>GtkDialog</type></link> functions.</entry>
200
<entry>*ok_button, *cancel_button;</entry>
201
<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>
205
<entry>*history_pulldown;</entry>
206
<entry>the <link linkend="GtkOptionMenu"><type>GtkOptionMenu</type></link> used to create the drop-down directory history.</entry>
210
<entry>*fileop_c_dir, *fileop_del_file, *fileop_ren_file;</entry>
211
<entry>the buttons that appear at the top of the file selection dialog. These "operation buttons" can be hidden and redisplayed with <link linkend="gtk-file-selection-hide-fileop-buttons"><function>gtk_file_selection_hide_fileop_buttons()</function></link> and <link linkend="gtk-file-selection-show-fileop-buttons"><function>gtk_file_selection_show_fileop_buttons()</function></link> respectively.</entry>
214
</tbody></tgroup></informaltable>
218
<title><anchor id="gtk-file-selection-new" role="function"/>gtk_file_selection_new ()</title>
219
<indexterm><primary>gtk_file_selection_new</primary></indexterm><programlisting><link linkend="GtkWidget">GtkWidget</link>* gtk_file_selection_new (const <link linkend="gchar">gchar</link> *title);</programlisting>
221
Creates a new file selection dialog box. By default it will contain a <link linkend="GtkTreeView"><type>GtkTreeView</type></link> 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.
222
</para><variablelist role="params">
223
<varlistentry><term><parameter>title</parameter> :</term>
224
<listitem><simpara>a message that will be placed in the file requestor's titlebar.
225
</simpara></listitem></varlistentry>
226
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>the new file selection.
229
</simpara></listitem></varlistentry>
230
</variablelist></refsect2>
232
<title><anchor id="gtk-file-selection-set-filename" role="function"/>gtk_file_selection_set_filename ()</title>
233
<indexterm><primary>gtk_file_selection_set_filename</primary></indexterm><programlisting><link linkend="void">void</link> gtk_file_selection_set_filename (<link linkend="GtkFileSelection">GtkFileSelection</link> *filesel,
234
const <link linkend="gchar">gchar</link> *filename);</programlisting>
236
Sets a default path for the file requestor. If <parameter>filename</parameter> includes a
237
directory path, then the requestor will open with that path as its
238
current working directory.
241
This has the consequence that in order to open the requestor with a
242
working directory and an empty filename, <parameter>filename</parameter> must have a trailing
246
The encoding of <parameter>filename</parameter> is preferred GLib file name encoding, which
247
may not be UTF-8. See <link linkend="g-filename-from-utf8"><function>g_filename_from_utf8()</function></link>.</para>
249
</para><variablelist role="params">
250
<varlistentry><term><parameter>filesel</parameter> :</term>
251
<listitem><simpara> a <link linkend="GtkFileSelection"><type>GtkFileSelection</type></link>.
252
</simpara></listitem></varlistentry>
253
<varlistentry><term><parameter>filename</parameter> :</term>
254
<listitem><simpara> a string to set as the default file name.
255
</simpara></listitem></varlistentry>
256
</variablelist></refsect2>
258
<title><anchor id="gtk-file-selection-get-filename" role="function"/>gtk_file_selection_get_filename ()</title>
259
<indexterm><primary>gtk_file_selection_get_filename</primary></indexterm><programlisting>const <link linkend="gchar">gchar</link>* gtk_file_selection_get_filename (<link linkend="GtkFileSelection">GtkFileSelection</link> *filesel);</programlisting>
261
This function returns the selected filename in the GLib file name
262
encoding. To convert to UTF-8, call <link linkend="g-filename-to-utf8"><function>g_filename_to_utf8()</function></link>. The
263
returned string points to a statically allocated buffer and should
264
be copied if you plan to keep it around.
267
If no file is selected then the selected directory path is returned.</para>
269
</para><variablelist role="params">
270
<varlistentry><term><parameter>filesel</parameter> :</term>
271
<listitem><simpara> a <link linkend="GtkFileSelection"><type>GtkFileSelection</type></link>
272
</simpara></listitem></varlistentry>
273
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> currently-selected filename in the on-disk encoding.
274
</simpara></listitem></varlistentry>
275
</variablelist></refsect2>
277
<title><anchor id="gtk-file-selection-complete" role="function"/>gtk_file_selection_complete ()</title>
278
<indexterm><primary>gtk_file_selection_complete</primary></indexterm><programlisting><link linkend="void">void</link> gtk_file_selection_complete (<link linkend="GtkFileSelection">GtkFileSelection</link> *filesel,
279
const <link linkend="gchar">gchar</link> *pattern);</programlisting>
281
Will attempt to match <parameter>pattern</parameter> 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.
282
If a partial match can be made, the "Files" list will contain those
283
file names which have been partially matched, and the "Folders"
284
list those directories which have been partially matched.
285
</para><variablelist role="params">
286
<varlistentry><term><parameter>filesel</parameter> :</term>
287
<listitem><simpara>a <link linkend="GtkFileSelection"><type>GtkFileSelection</type></link>.
288
</simpara></listitem></varlistentry>
289
<varlistentry><term><parameter>pattern</parameter> :</term>
290
<listitem><simpara>a string of characters which may or may not match any filenames in the current directory.
293
</simpara></listitem></varlistentry>
294
</variablelist></refsect2>
296
<title><anchor id="gtk-file-selection-show-fileop-buttons" role="function"/>gtk_file_selection_show_fileop_buttons ()</title>
297
<indexterm><primary>gtk_file_selection_show_fileop_buttons</primary></indexterm><programlisting><link linkend="void">void</link> gtk_file_selection_show_fileop_buttons
298
(<link linkend="GtkFileSelection">GtkFileSelection</link> *filesel);</programlisting>
300
Shows the file operation buttons, if they have previously been hidden. The rest of the widgets in the dialog will be resized accordingly.
301
</para><variablelist role="params">
302
<varlistentry><term><parameter>filesel</parameter> :</term>
303
<listitem><simpara>a <link linkend="GtkFileSelection"><type>GtkFileSelection</type></link>.
306
</simpara></listitem></varlistentry>
307
</variablelist></refsect2>
309
<title><anchor id="gtk-file-selection-hide-fileop-buttons" role="function"/>gtk_file_selection_hide_fileop_buttons ()</title>
310
<indexterm><primary>gtk_file_selection_hide_fileop_buttons</primary></indexterm><programlisting><link linkend="void">void</link> gtk_file_selection_hide_fileop_buttons
311
(<link linkend="GtkFileSelection">GtkFileSelection</link> *filesel);</programlisting>
313
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 <link linkend="GtkFileSelection"><type>GtkFileSelection</type></link>.
314
</para><variablelist role="params">
315
<varlistentry><term><parameter>filesel</parameter> :</term>
316
<listitem><simpara>a <link linkend="GtkFileSelection"><type>GtkFileSelection</type></link>.
319
</simpara></listitem></varlistentry>
320
</variablelist></refsect2>
322
<title><anchor id="gtk-file-selection-get-selections" role="function"/>gtk_file_selection_get_selections ()</title>
323
<indexterm><primary>gtk_file_selection_get_selections</primary></indexterm><programlisting><link linkend="gchar">gchar</link>** gtk_file_selection_get_selections (<link linkend="GtkFileSelection">GtkFileSelection</link> *filesel);</programlisting>
325
Retrieves the list of file selections the user has made in the dialog box.
326
This function is intended for use when the user can select multiple files
330
The filenames are in the GLib file name encoding. To convert to
331
UTF-8, call <link linkend="g-filename-to-utf8"><function>g_filename_to_utf8()</function></link> on each string.</para>
334
</para><variablelist role="params">
335
<varlistentry><term><parameter>filesel</parameter> :</term>
336
<listitem><simpara> a <link linkend="GtkFileSelection"><type>GtkFileSelection</type></link>
337
</simpara></listitem></varlistentry>
338
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> a newly-allocated <link linkend="NULL:CAPS"><literal>NULL</literal></link>-terminated array of strings. Use
339
<link linkend="g-strfreev"><function>g_strfreev()</function></link> to free it.
340
</simpara></listitem></varlistentry>
341
</variablelist></refsect2>
343
<title><anchor id="gtk-file-selection-set-select-multiple" role="function"/>gtk_file_selection_set_select_multiple ()</title>
344
<indexterm><primary>gtk_file_selection_set_select_multiple</primary></indexterm><programlisting><link linkend="void">void</link> gtk_file_selection_set_select_multiple
345
(<link linkend="GtkFileSelection">GtkFileSelection</link> *filesel,
346
<link linkend="gboolean">gboolean</link> select_multiple);</programlisting>
348
Sets whether the user is allowed to select multiple files in the file list.
349
Use <link linkend="gtk-file-selection-get-selections"><function>gtk_file_selection_get_selections()</function></link> to get the list of selected files.</para>
352
</para><variablelist role="params">
353
<varlistentry><term><parameter>filesel</parameter> :</term>
354
<listitem><simpara> a <link linkend="GtkFileSelection"><type>GtkFileSelection</type></link>
355
</simpara></listitem></varlistentry>
356
<varlistentry><term><parameter>select_multiple</parameter> :</term>
357
<listitem><simpara> whether or not the user is allowed to select multiple
358
files in the file list.
359
</simpara></listitem></varlistentry>
360
</variablelist></refsect2>
362
<title><anchor id="gtk-file-selection-get-select-multiple" role="function"/>gtk_file_selection_get_select_multiple ()</title>
363
<indexterm><primary>gtk_file_selection_get_select_multiple</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link> gtk_file_selection_get_select_multiple
364
(<link linkend="GtkFileSelection">GtkFileSelection</link> *filesel);</programlisting>
366
Determines whether or not the user is allowed to select multiple files in
367
the file list. See <link linkend="gtk-file-selection-set-select-multiple"><function>gtk_file_selection_set_select_multiple()</function></link>.</para>
370
</para><variablelist role="params">
371
<varlistentry><term><parameter>filesel</parameter> :</term>
372
<listitem><simpara> a <link linkend="GtkFileSelection"><type>GtkFileSelection</type></link>
373
</simpara></listitem></varlistentry>
374
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> <link linkend="TRUE:CAPS"><literal>TRUE</literal></link> if the user is allowed to select multiple files in the
376
</simpara></listitem></varlistentry>
377
</variablelist></refsect2>
380
<refsect1 role="property_details">
381
<title role="property_details.title">Property Details</title>
382
<refsect2><title><anchor id="GtkFileSelection--filename"/>The "<literal>filename</literal>" property</title>
383
<indexterm><primary>GtkFileSelection:filename</primary></indexterm><programlisting> "filename" <link linkend="gchararray">gchararray</link> : Read / Write</programlisting>
384
<para>The currently selected filename.</para><para>Default value: NULL</para>
386
<refsect2><title><anchor id="GtkFileSelection--select-multiple"/>The "<literal>select-multiple</literal>" property</title>
387
<indexterm><primary>GtkFileSelection:select-multiple</primary></indexterm><programlisting> "select-multiple" <link linkend="gboolean">gboolean</link> : Read / Write</programlisting>
388
<para>Whether to allow multiple files to be selected.</para><para>Default value: FALSE</para>
390
<refsect2><title><anchor id="GtkFileSelection--show-fileops"/>The "<literal>show-fileops</literal>" property</title>
391
<indexterm><primary>GtkFileSelection:show-fileops</primary></indexterm><programlisting> "show-fileops" <link linkend="gboolean">gboolean</link> : Read / Write</programlisting>
392
<para>Whether buttons for creating/manipulating files should be displayed.</para><para>Default value: FALSE</para>
400
<title>See Also</title>
405
<term><link linkend="GtkDialog"><type>GtkDialog</type></link></term>
406
<listitem><para>Add your own widgets into the <link linkend="GtkFileSelection"><type>GtkFileSelection</type></link>.</para></listitem>