1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5
<title>GtkFileChooserDialog</title>
6
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
7
<link rel="home" href="index.html" title="GTK+ 2 Reference Manual">
8
<link rel="up" href="SelectorWidgets.html" title="Selectors (File/Font/Color/Input Devices)">
9
<link rel="prev" href="GtkFileChooserButton.html" title="GtkFileChooserButton">
10
<link rel="next" href="GtkFileChooserWidget.html" title="GtkFileChooserWidget">
11
<meta name="generator" content="GTK-Doc V1.18 (XML mode)">
12
<link rel="stylesheet" href="style.css" type="text/css">
14
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
15
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
17
<td><a accesskey="p" href="GtkFileChooserButton.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
18
<td><a accesskey="u" href="SelectorWidgets.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
19
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
20
<th width="100%" align="center">GTK+ 2 Reference Manual</th>
21
<td><a accesskey="n" href="GtkFileChooserWidget.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
23
<tr><td colspan="5" class="shortcuts">
24
<a href="#GtkFileChooserDialog.synopsis" class="shortcut">Top</a>
26
<a href="#GtkFileChooserDialog.description" class="shortcut">Description</a>
28
<a href="#GtkFileChooserDialog.object-hierarchy" class="shortcut">Object Hierarchy</a>
30
<a href="#GtkFileChooserDialog.implemented-interfaces" class="shortcut">Implemented Interfaces</a>
33
<div class="refentry">
34
<a name="GtkFileChooserDialog"></a><div class="titlepage"></div>
35
<div class="refnamediv"><table width="100%"><tr>
37
<h2><span class="refentrytitle"><a name="GtkFileChooserDialog.top_of_page"></a>GtkFileChooserDialog</span></h2>
38
<p>GtkFileChooserDialog — A file chooser dialog, suitable for "File/Open" or "File/Save" commands</p>
40
<td valign="top" align="right"><img src="filechooser.png"></td>
42
<div class="refsynopsisdiv">
43
<a name="GtkFileChooserDialog.synopsis"></a><h2>Synopsis</h2>
44
<pre class="synopsis">
45
#include <gtk/gtk.h>
47
struct <a class="link" href="GtkFileChooserDialog.html#GtkFileChooserDialog-struct" title="struct GtkFileChooserDialog">GtkFileChooserDialog</a>;
48
<a class="link" href="GtkWidget.html" title="GtkWidget"><span class="returnvalue">GtkWidget</span></a> * <a class="link" href="GtkFileChooserDialog.html#gtk-file-chooser-dialog-new" title="gtk_file_chooser_dialog_new ()">gtk_file_chooser_dialog_new</a> (<em class="parameter"><code>const <span class="type">gchar</span> *title</code></em>,
49
<em class="parameter"><code><a class="link" href="GtkWindow.html" title="GtkWindow"><span class="type">GtkWindow</span></a> *parent</code></em>,
50
<em class="parameter"><code><a class="link" href="GtkFileChooser.html#GtkFileChooserAction" title="enum GtkFileChooserAction"><span class="type">GtkFileChooserAction</span></a> action</code></em>,
51
<em class="parameter"><code>const <span class="type">gchar</span> *first_button_text</code></em>,
52
<em class="parameter"><code>...</code></em>);
53
<a class="link" href="GtkWidget.html" title="GtkWidget"><span class="returnvalue">GtkWidget</span></a> * <a class="link" href="GtkFileChooserDialog.html#gtk-file-chooser-dialog-new-with-backend" title="gtk_file_chooser_dialog_new_with_backend ()">gtk_file_chooser_dialog_new_with_backend</a>
54
(<em class="parameter"><code>const <span class="type">gchar</span> *title</code></em>,
55
<em class="parameter"><code><a class="link" href="GtkWindow.html" title="GtkWindow"><span class="type">GtkWindow</span></a> *parent</code></em>,
56
<em class="parameter"><code><a class="link" href="GtkFileChooser.html#GtkFileChooserAction" title="enum GtkFileChooserAction"><span class="type">GtkFileChooserAction</span></a> action</code></em>,
57
<em class="parameter"><code>const <span class="type">gchar</span> *backend</code></em>,
58
<em class="parameter"><code>const <span class="type">gchar</span> *first_button_text</code></em>,
59
<em class="parameter"><code>...</code></em>);
62
<div class="refsect1">
63
<a name="GtkFileChooserDialog.object-hierarchy"></a><h2>Object Hierarchy</h2>
64
<pre class="synopsis">
66
+----GInitiallyUnowned
67
+----<a class="link" href="GtkObject.html" title="GtkObject">GtkObject</a>
68
+----<a class="link" href="GtkWidget.html" title="GtkWidget">GtkWidget</a>
69
+----<a class="link" href="GtkContainer.html" title="GtkContainer">GtkContainer</a>
70
+----<a class="link" href="GtkBin.html" title="GtkBin">GtkBin</a>
71
+----<a class="link" href="GtkWindow.html" title="GtkWindow">GtkWindow</a>
72
+----<a class="link" href="GtkDialog.html" title="GtkDialog">GtkDialog</a>
73
+----GtkFileChooserDialog
76
<div class="refsect1">
77
<a name="GtkFileChooserDialog.implemented-interfaces"></a><h2>Implemented Interfaces</h2>
79
GtkFileChooserDialog implements
80
AtkImplementorIface, <a class="link" href="GtkBuildable.html" title="GtkBuildable">GtkBuildable</a> and <a class="link" href="GtkFileChooser.html" title="GtkFileChooser">GtkFileChooser</a>.</p>
82
<div class="refsect1">
83
<a name="GtkFileChooserDialog.description"></a><h2>Description</h2>
85
<a class="link" href="GtkFileChooserDialog.html" title="GtkFileChooserDialog"><span class="type">GtkFileChooserDialog</span></a> is a dialog box suitable for use with
86
"File/Open" or "File/Save as" commands. This widget works by
87
putting a <a class="link" href="GtkFileChooserWidget.html" title="GtkFileChooserWidget"><span class="type">GtkFileChooserWidget</span></a> inside a <a class="link" href="GtkDialog.html" title="GtkDialog"><span class="type">GtkDialog</span></a>. It exposes
88
the <span class="type">GtkFileChooserIface</span> interface, so you can use all of the
89
<a class="link" href="GtkFileChooser.html" title="GtkFileChooser"><span class="type">GtkFileChooser</span></a> functions on the file chooser dialog as well as
90
those for <a class="link" href="GtkDialog.html" title="GtkDialog"><span class="type">GtkDialog</span></a>.
93
Note that <a class="link" href="GtkFileChooserDialog.html" title="GtkFileChooserDialog"><span class="type">GtkFileChooserDialog</span></a> does not have any methods of its
94
own. Instead, you should use the functions that work on a
95
<a class="link" href="GtkFileChooser.html" title="GtkFileChooser"><span class="type">GtkFileChooser</span></a>.
98
<a name="gtkfilechooser-typical-usage"></a><p class="title"><b>Example 45. Typical usage</b></p>
99
<div class="example-contents">
101
In the simplest of cases, you can the following code to use
102
<a class="link" href="GtkFileChooserDialog.html" title="GtkFileChooserDialog"><span class="type">GtkFileChooserDialog</span></a> to select a file for opening:
104
<pre class="programlisting">
106
dialog = gtk_file_chooser_dialog_new ("Open File",
108
GTK_FILE_CHOOSER_ACTION_OPEN,
109
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
110
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
112
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
115
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
116
open_file (filename);
119
gtk_widget_destroy (dialog);
122
To use a dialog for saving, you can use this:
124
<pre class="programlisting">
126
dialog = gtk_file_chooser_dialog_new ("Save File",
128
GTK_FILE_CHOOSER_ACTION_SAVE,
129
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
130
GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
132
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
133
if (user_edited_a_new_document)
135
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), default_folder_for_saving);
136
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), "Untitled document");
139
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), filename_for_existing_document);
140
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
143
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
144
save_to_file (filename);
147
gtk_widget_destroy (dialog);
151
<br class="example-break"><div class="section">
152
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
153
<a name="gtkfilechooserdialog-response-codes"></a>Response Codes</h2></div></div></div>
155
<a class="link" href="GtkFileChooserDialog.html" title="GtkFileChooserDialog"><span class="type">GtkFileChooserDialog</span></a> inherits from <a class="link" href="GtkDialog.html" title="GtkDialog"><span class="type">GtkDialog</span></a>, so buttons that
156
go in its action area have response codes such as
157
<a class="link" href="GtkDialog.html#GTK-RESPONSE-ACCEPT:CAPS"><span class="type">GTK_RESPONSE_ACCEPT</span></a> and <a class="link" href="GtkDialog.html#GTK-RESPONSE-CANCEL:CAPS"><span class="type">GTK_RESPONSE_CANCEL</span></a>. For example, you
158
could call <a class="link" href="GtkFileChooserDialog.html#gtk-file-chooser-dialog-new" title="gtk_file_chooser_dialog_new ()"><code class="function">gtk_file_chooser_dialog_new()</code></a> as follows:
160
<pre class="programlisting">
162
dialog = gtk_file_chooser_dialog_new ("Open File",
164
GTK_FILE_CHOOSER_ACTION_OPEN,
165
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
166
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
170
This will create buttons for "Cancel" and "Open" that use stock
171
response identifiers from <a class="link" href="GtkDialog.html#GtkResponseType" title="enum GtkResponseType"><span class="type">GtkResponseType</span></a>. For most dialog
172
boxes you can use your own custom response codes rather than the
173
ones in <a class="link" href="GtkDialog.html#GtkResponseType" title="enum GtkResponseType"><span class="type">GtkResponseType</span></a>, but <a class="link" href="GtkFileChooserDialog.html" title="GtkFileChooserDialog"><span class="type">GtkFileChooserDialog</span></a> assumes that
174
its "accept"-type action, e.g. an "Open" or "Save" button,
175
<span class="emphasis"><em>will</em></span> have one of the following response
177
<a name="gtkfilechooserdialog-responses"></a></p>
178
<table border="0" summary="Simple list" class="simplelist">
179
<tr><td><a class="link" href="GtkDialog.html#GTK-RESPONSE-ACCEPT:CAPS"><span class="type">GTK_RESPONSE_ACCEPT</span></a></td></tr>
180
<tr><td><a class="link" href="GtkDialog.html#GTK-RESPONSE-OK:CAPS"><span class="type">GTK_RESPONSE_OK</span></a></td></tr>
181
<tr><td><a class="link" href="GtkDialog.html#GTK-RESPONSE-YES:CAPS"><span class="type">GTK_RESPONSE_YES</span></a></td></tr>
182
<tr><td><a class="link" href="GtkDialog.html#GTK-RESPONSE-APPLY:CAPS"><span class="type">GTK_RESPONSE_APPLY</span></a></td></tr>
187
This is because <a class="link" href="GtkFileChooserDialog.html" title="GtkFileChooserDialog"><span class="type">GtkFileChooserDialog</span></a> must intercept responses
188
and switch to folders if appropriate, rather than letting the
189
dialog terminate — the implementation uses these known
190
response codes to know which responses can be blocked if
193
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
194
<h3 class="title">Note</h3>
196
To summarize, make sure you use a <a class="link" href="GtkFileChooserDialog.html#gtkfilechooserdialog-responses">stock response
197
code</a> when you use <a class="link" href="GtkFileChooserDialog.html" title="GtkFileChooserDialog"><span class="type">GtkFileChooserDialog</span></a> to ensure
203
<div class="refsect1">
204
<a name="GtkFileChooserDialog.details"></a><h2>Details</h2>
205
<div class="refsect2">
206
<a name="GtkFileChooserDialog-struct"></a><h3>struct GtkFileChooserDialog</h3>
207
<pre class="programlisting">struct GtkFileChooserDialog;</pre>
212
<div class="refsect2">
213
<a name="gtk-file-chooser-dialog-new"></a><h3>gtk_file_chooser_dialog_new ()</h3>
214
<pre class="programlisting"><a class="link" href="GtkWidget.html" title="GtkWidget"><span class="returnvalue">GtkWidget</span></a> * gtk_file_chooser_dialog_new (<em class="parameter"><code>const <span class="type">gchar</span> *title</code></em>,
215
<em class="parameter"><code><a class="link" href="GtkWindow.html" title="GtkWindow"><span class="type">GtkWindow</span></a> *parent</code></em>,
216
<em class="parameter"><code><a class="link" href="GtkFileChooser.html#GtkFileChooserAction" title="enum GtkFileChooserAction"><span class="type">GtkFileChooserAction</span></a> action</code></em>,
217
<em class="parameter"><code>const <span class="type">gchar</span> *first_button_text</code></em>,
218
<em class="parameter"><code>...</code></em>);</pre>
220
Creates a new <a class="link" href="GtkFileChooserDialog.html" title="GtkFileChooserDialog"><span class="type">GtkFileChooserDialog</span></a>. This function is analogous to
221
<a class="link" href="GtkDialog.html#gtk-dialog-new-with-buttons" title="gtk_dialog_new_with_buttons ()"><code class="function">gtk_dialog_new_with_buttons()</code></a>.
223
<div class="variablelist"><table border="0" class="variablelist">
225
<col align="left" valign="top">
230
<td><p><span class="term"><em class="parameter"><code>title</code></em> :</span></p></td>
231
<td>Title of the dialog, or <a href="/usr/share/gtk-doc/html/liboil/liboil-liboiljunk.html#NULL:CAPS"><code class="literal">NULL</code></a>. <span class="annotation">[<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
235
<td><p><span class="term"><em class="parameter"><code>parent</code></em> :</span></p></td>
236
<td>Transient parent of the dialog, or <a href="/usr/share/gtk-doc/html/liboil/liboil-liboiljunk.html#NULL:CAPS"><code class="literal">NULL</code></a>. <span class="annotation">[<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
240
<td><p><span class="term"><em class="parameter"><code>action</code></em> :</span></p></td>
241
<td>Open or save mode for the dialog</td>
244
<td><p><span class="term"><em class="parameter"><code>first_button_text</code></em> :</span></p></td>
245
<td>stock ID or text to go in the first button, or <a href="/usr/share/gtk-doc/html/liboil/liboil-liboiljunk.html#NULL:CAPS"><code class="literal">NULL</code></a>. <span class="annotation">[<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
249
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
250
<td>a new <a class="link" href="GtkFileChooserDialog.html" title="GtkFileChooserDialog"><span class="type">GtkFileChooserDialog</span></a>
255
<p class="since">Since 2.4</p>
258
<div class="refsect2">
259
<a name="gtk-file-chooser-dialog-new-with-backend"></a><h3>gtk_file_chooser_dialog_new_with_backend ()</h3>
260
<pre class="programlisting"><a class="link" href="GtkWidget.html" title="GtkWidget"><span class="returnvalue">GtkWidget</span></a> * gtk_file_chooser_dialog_new_with_backend
261
(<em class="parameter"><code>const <span class="type">gchar</span> *title</code></em>,
262
<em class="parameter"><code><a class="link" href="GtkWindow.html" title="GtkWindow"><span class="type">GtkWindow</span></a> *parent</code></em>,
263
<em class="parameter"><code><a class="link" href="GtkFileChooser.html#GtkFileChooserAction" title="enum GtkFileChooserAction"><span class="type">GtkFileChooserAction</span></a> action</code></em>,
264
<em class="parameter"><code>const <span class="type">gchar</span> *backend</code></em>,
265
<em class="parameter"><code>const <span class="type">gchar</span> *first_button_text</code></em>,
266
<em class="parameter"><code>...</code></em>);</pre>
267
<div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
268
<h3 class="title">Warning</h3>
269
<p><code class="literal">gtk_file_chooser_dialog_new_with_backend</code> has been deprecated since version 2.14 and should not be used in newly-written code. Use <a class="link" href="GtkFileChooserDialog.html#gtk-file-chooser-dialog-new" title="gtk_file_chooser_dialog_new ()"><code class="function">gtk_file_chooser_dialog_new()</code></a> instead.</p>
272
Creates a new <a class="link" href="GtkFileChooserDialog.html" title="GtkFileChooserDialog"><span class="type">GtkFileChooserDialog</span></a> with a specified backend. This is
273
especially useful if you use <a class="link" href="GtkFileChooser.html#gtk-file-chooser-set-local-only" title="gtk_file_chooser_set_local_only ()"><code class="function">gtk_file_chooser_set_local_only()</code></a> to allow
274
non-local files and you use a more expressive vfs, such as gnome-vfs,
277
<div class="variablelist"><table border="0" class="variablelist">
279
<col align="left" valign="top">
284
<td><p><span class="term"><em class="parameter"><code>title</code></em> :</span></p></td>
285
<td>Title of the dialog, or <a href="/usr/share/gtk-doc/html/liboil/liboil-liboiljunk.html#NULL:CAPS"><code class="literal">NULL</code></a>. <span class="annotation">[<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
289
<td><p><span class="term"><em class="parameter"><code>parent</code></em> :</span></p></td>
290
<td>Transient parent of the dialog, or <a href="/usr/share/gtk-doc/html/liboil/liboil-liboiljunk.html#NULL:CAPS"><code class="literal">NULL</code></a>. <span class="annotation">[<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
294
<td><p><span class="term"><em class="parameter"><code>action</code></em> :</span></p></td>
295
<td>Open or save mode for the dialog</td>
298
<td><p><span class="term"><em class="parameter"><code>backend</code></em> :</span></p></td>
299
<td>The name of the specific filesystem backend to use.</td>
302
<td><p><span class="term"><em class="parameter"><code>first_button_text</code></em> :</span></p></td>
303
<td>stock ID or text to go in the first button, or <a href="/usr/share/gtk-doc/html/liboil/liboil-liboiljunk.html#NULL:CAPS"><code class="literal">NULL</code></a>. <span class="annotation">[<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
307
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
308
<td>a new <a class="link" href="GtkFileChooserDialog.html" title="GtkFileChooserDialog"><span class="type">GtkFileChooserDialog</span></a>
313
<p class="since">Since 2.4</p>
316
<div class="refsect1">
317
<a name="GtkFileChooserDialog.see-also"></a><h2>See Also</h2>
319
<a class="link" href="GtkFileChooser.html" title="GtkFileChooser"><span class="type">GtkFileChooser</span></a>, <a class="link" href="GtkDialog.html" title="GtkDialog"><span class="type">GtkDialog</span></a>
325
Generated by GTK-Doc V1.18</div>
b'\\ No newline at end of file'