]> Pileus Git - ~andy/gtk/blob - gtk/gtkfilechooserdialog.c
Change FSF Address
[~andy/gtk] / gtk / gtkfilechooserdialog.c
1 /* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
2 /* GTK - The GIMP Toolkit
3  * gtkfilechooserdialog.c: File selector dialog
4  * Copyright (C) 2003, Red Hat, Inc.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #include "config.h"
21
22 #include "gtkfilechooserdialog.h"
23
24 #include "gtkfilechooserprivate.h"
25 #include "gtkfilechooserwidget.h"
26 #include "gtkfilechooserutils.h"
27 #include "gtkfilechooserembed.h"
28 #include "gtkfilesystem.h"
29 #include "gtksizerequest.h"
30 #include "gtktypebuiltins.h"
31 #include "gtkintl.h"
32
33 #include <stdarg.h>
34
35
36 /**
37  * SECTION:gtkfilechooserdialog
38  * @Short_description: A file chooser dialog, suitable for "File/Open" or "File/Save" commands
39  * @Title: GtkFileChooserDialog
40  * @See_also: #GtkFileChooser, #GtkDialog
41  *
42  * #GtkFileChooserDialog is a dialog box suitable for use with
43  * "File/Open" or "File/Save as" commands.  This widget works by
44  * putting a #GtkFileChooserWidget inside a #GtkDialog.  It exposes
45  * the #GtkFileChooserIface interface, so you can use all of the
46  * #GtkFileChooser functions on the file chooser dialog as well as
47  * those for #GtkDialog.
48  *
49  * Note that #GtkFileChooserDialog does not have any methods of its
50  * own.  Instead, you should use the functions that work on a
51  * #GtkFileChooser.
52  *
53  * <example id="gtkfilechooser-typical-usage">
54  * <title>Typical usage</title>
55  * In the simplest of cases, you can the following code to use
56  * #GtkFileChooserDialog to select a file for opening:
57  * <para>
58  * <informalexample><programlisting>
59  * GtkWidget *dialog;
60  *
61  * dialog = gtk_file_chooser_dialog_new ("Open File",
62  *                                       parent_window,
63  *                                       GTK_FILE_CHOOSER_ACTION_OPEN,
64  *                                       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
65  *                                       GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
66  *                                       NULL);
67  *
68  * if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
69  *   {
70  *     char *filename;
71  *
72  *     filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
73  *     open_file (filename);
74  *     g_free (filename);
75  *   }
76  *
77  * gtk_widget_destroy (dialog);
78  * </programlisting></informalexample>
79  * </para>
80  * To use a dialog for saving, you can use this:
81  * <para>
82  * <informalexample><programlisting>
83  * GtkWidget *dialog;
84  *
85  * dialog = gtk_file_chooser_dialog_new ("Save File",
86  *                                       parent_window,
87  *                                       GTK_FILE_CHOOSER_ACTION_SAVE,
88  *                                       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
89  *                                       GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
90  *                                       NULL);
91  * gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
92  *
93  * if (user_edited_a_new_document)
94  *   gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), "Untitled document");
95  * else
96  *   gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), filename_for_existing_document);
97  *
98  * if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
99  *   {
100  *     char *filename;
101  *
102  *     filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
103  *     save_to_file (filename);
104  *     g_free (filename);
105  *   }
106  *
107  * gtk_widget_destroy (dialog);
108  * </programlisting></informalexample>
109  * </para>
110  * </example>
111  * <section id="gtkfilechooserdialog-setting-up">
112  * <title>Setting up a file chooser dialog</title>
113  * There are various cases in which you may need to use a #GtkFileChooserDialog:
114  * <itemizedlist><listitem>To select a file for opening, as for a
115  *   <guimenuitem>File/Open</guimenuitem> command.  Use
116  *   #GTK_FILE_CHOOSER_ACTION_OPEN.
117  * </listitem>
118  * <listitem>To save a file for the first time, as for a
119  *   <guimenuitem>File/Save</guimenuitem> command.  Use
120  *   #GTK_FILE_CHOOSER_ACTION_SAVE, and suggest a name such as
121  *   "Untitled" with gtk_file_chooser_set_current_name().
122  * </listitem>
123  * <listitem>To save a file under a different name, as for a
124  *   <guimenuitem>File/Save As</guimenuitem> command.  Use
125  *   #GTK_FILE_CHOOSER_ACTION_SAVE, and set the existing filename
126  *   with gtk_file_chooser_set_filename().
127  * </listitem>
128  * <listitem>To choose a folder instead of a file.  Use
129  *   #GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER.
130  * </listitem></itemizedlist>
131  * <note>
132  * <para>
133  * Old versions of the file chooser's documentation suggested
134  * using gtk_file_chooser_set_current_folder() in various
135  * situations, with the intention of letting the application
136  * suggest a reasonable default folder.  This is no longer
137  * considered to be a good policy, as now the file chooser is
138  * able to make good suggestions on its own.  In general, you
139  * should only cause the file chooser to show a specific folder
140  * when it is appropriate to use gtk_file_chooser_set_filename(),
141  * i.e. when you are doing a <guimenuitem>File/Save
142  * As</guimenuitem> command <emphasis>and</emphasis> you already
143  * have a file saved somewhere.
144  * </para>
145  * </note>
146  * </section>
147  * <section id="gtkfilechooserdialog-response-codes">
148  * <title>Response Codes</title>
149  * #GtkFileChooserDialog inherits from #GtkDialog, so buttons that
150  * go in its action area have response codes such as
151  * #GTK_RESPONSE_ACCEPT and #GTK_RESPONSE_CANCEL.  For example, you
152  * could call gtk_file_chooser_dialog_new() as follows:
153  * <para>
154  * <informalexample><programlisting>
155  * GtkWidget *dialog;
156  *
157  * dialog = gtk_file_chooser_dialog_new ("Open File",
158  *                                       parent_window,
159  *                                       GTK_FILE_CHOOSER_ACTION_OPEN,
160  *                                       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
161  *                                       GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
162  *                                       NULL);
163  * </programlisting></informalexample>
164  * </para>
165  * This will create buttons for "Cancel" and "Open" that use stock
166  * response identifiers from #GtkResponseType.  For most dialog
167  * boxes you can use your own custom response codes rather than the
168  * ones in #GtkResponseType, but #GtkFileChooserDialog assumes that
169  * its "accept"-type action, e.g. an "Open" or "Save" button,
170  * <emphasis>will</emphasis> have one of the following response
171  * codes:
172  * <para>
173  * <simplelist id="gtkfilechooserdialog-responses">
174  * <member>#GTK_RESPONSE_ACCEPT</member>
175  * <member>#GTK_RESPONSE_OK</member>
176  * <member>#GTK_RESPONSE_YES</member>
177  * <member>#GTK_RESPONSE_APPLY</member>
178  * </simplelist>
179  * </para>
180  * This is because #GtkFileChooserDialog must intercept responses
181  * and switch to folders if appropriate, rather than letting the
182  * dialog terminate &mdash; the implementation uses these known
183  * response codes to know which responses can be blocked if
184  * appropriate.
185  * <para>
186  * <note>
187  * To summarize, make sure you use a
188  * <link linkend="gtkfilechooserdialog-responses">stock response code</link>
189  * when you use #GtkFileChooserDialog to ensure proper operation.
190  * </note>
191  * </para>
192  * </section>
193  */
194
195
196 #define GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE(o)  (GTK_FILE_CHOOSER_DIALOG (o)->priv)
197
198 static void gtk_file_chooser_dialog_finalize   (GObject                   *object);
199
200 static GObject* gtk_file_chooser_dialog_constructor  (GType                  type,
201                                                       guint                  n_construct_properties,
202                                                       GObjectConstructParam *construct_params);
203 static void     gtk_file_chooser_dialog_set_property (GObject               *object,
204                                                       guint                  prop_id,
205                                                       const GValue          *value,
206                                                       GParamSpec            *pspec);
207 static void     gtk_file_chooser_dialog_get_property (GObject               *object,
208                                                       guint                  prop_id,
209                                                       GValue                *value,
210                                                       GParamSpec            *pspec);
211
212 static void     gtk_file_chooser_dialog_map          (GtkWidget             *widget);
213
214 static void response_cb (GtkDialog *dialog,
215                          gint       response_id);
216
217 G_DEFINE_TYPE_WITH_CODE (GtkFileChooserDialog, gtk_file_chooser_dialog, GTK_TYPE_DIALOG,
218                          G_IMPLEMENT_INTERFACE (GTK_TYPE_FILE_CHOOSER,
219                                                 _gtk_file_chooser_delegate_iface_init))
220
221 static void
222 gtk_file_chooser_dialog_class_init (GtkFileChooserDialogClass *class)
223 {
224   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
225   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
226
227   gobject_class->constructor = gtk_file_chooser_dialog_constructor;
228   gobject_class->set_property = gtk_file_chooser_dialog_set_property;
229   gobject_class->get_property = gtk_file_chooser_dialog_get_property;
230   gobject_class->finalize = gtk_file_chooser_dialog_finalize;
231
232   widget_class->map       = gtk_file_chooser_dialog_map;
233
234   gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_FILE_CHOOSER);
235
236   _gtk_file_chooser_install_properties (gobject_class);
237
238   g_type_class_add_private (class, sizeof (GtkFileChooserDialogPrivate));
239 }
240
241 static void
242 gtk_file_chooser_dialog_init (GtkFileChooserDialog *dialog)
243 {
244   GtkWidget *action_area, *content_area;
245   GtkFileChooserDialogPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
246                                                                    GTK_TYPE_FILE_CHOOSER_DIALOG,
247                                                                    GtkFileChooserDialogPrivate);
248   GtkDialog *fc_dialog = GTK_DIALOG (dialog);
249
250   dialog->priv = priv;
251   dialog->priv->response_requested = FALSE;
252
253   content_area = gtk_dialog_get_content_area (fc_dialog);
254   action_area = gtk_dialog_get_action_area (fc_dialog);
255
256   gtk_container_set_border_width (GTK_CONTAINER (fc_dialog), 5);
257   gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
258   gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
259
260   /* We do a signal connection here rather than overriding the method in
261    * class_init because GtkDialog::response is a RUN_LAST signal.  We want *our*
262    * handler to be run *first*, regardless of whether the user installs response
263    * handlers of his own.
264    */
265   g_signal_connect (dialog, "response",
266                     G_CALLBACK (response_cb), NULL);
267 }
268
269 static void
270 gtk_file_chooser_dialog_finalize (GObject *object)
271 {
272   GtkFileChooserDialog *dialog = GTK_FILE_CHOOSER_DIALOG (object);
273
274   g_free (dialog->priv->file_system);
275
276   G_OBJECT_CLASS (gtk_file_chooser_dialog_parent_class)->finalize (object);  
277 }
278
279 static gboolean
280 is_stock_accept_response_id (int response_id)
281 {
282   return (response_id == GTK_RESPONSE_ACCEPT
283           || response_id == GTK_RESPONSE_OK
284           || response_id == GTK_RESPONSE_YES
285           || response_id == GTK_RESPONSE_APPLY);
286 }
287
288 /* Callback used when the user activates a file in the file chooser widget */
289 static void
290 file_chooser_widget_file_activated (GtkFileChooser       *chooser,
291                                     GtkFileChooserDialog *dialog)
292 {
293   GtkDialog *fc_dialog = GTK_DIALOG (dialog);
294   GtkWidget *action_area;
295   GList *children, *l;
296
297   if (gtk_window_activate_default (GTK_WINDOW (dialog)))
298     return;
299
300   /* There probably isn't a default widget, so make things easier for the
301    * programmer by looking for a reasonable button on our own.
302    */
303   action_area = gtk_dialog_get_action_area (fc_dialog);
304   children = gtk_container_get_children (GTK_CONTAINER (action_area));
305
306   for (l = children; l; l = l->next)
307     {
308       GtkWidget *widget;
309       int response_id;
310
311       widget = GTK_WIDGET (l->data);
312       response_id = gtk_dialog_get_response_for_widget (fc_dialog, widget);
313       if (gtk_widget_is_sensitive (widget) &&
314           is_stock_accept_response_id (response_id))
315         {
316           gtk_widget_activate (widget); /* Should we gtk_dialog_response (dialog, response_id) instead? */
317           break;
318         }
319     }
320
321   g_list_free (children);
322 }
323
324 #if 0
325 /* FIXME: to see why this function is ifdef-ed out, see the comment below in
326  * file_chooser_widget_default_size_changed().
327  */
328 static void
329 load_position (int *out_xpos, int *out_ypos)
330 {
331   GtkFileChooserSettings *settings;
332   int x, y, width, height;
333
334   settings = _gtk_file_chooser_settings_new ();
335   _gtk_file_chooser_settings_get_geometry (settings, &x, &y, &width, &height);
336   g_object_unref (settings);
337
338   *out_xpos = x;
339   *out_ypos = y;
340 }
341 #endif
342
343 static void
344 file_chooser_widget_default_size_changed (GtkWidget            *widget,
345                                           GtkFileChooserDialog *dialog)
346 {
347   GtkFileChooserDialogPrivate *priv;
348   gint default_width, default_height;
349   GtkRequisition req, widget_req;
350
351   priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog);
352
353   /* Unset any previously set size */
354   gtk_widget_set_size_request (GTK_WIDGET (dialog), -1, -1);
355
356   if (gtk_widget_is_drawable (widget))
357     {
358       /* Force a size request of everything before we start.  This will make sure
359        * that widget->requisition is meaningful. */
360       gtk_widget_get_preferred_size (GTK_WIDGET (dialog),
361                                      &req, NULL);
362       gtk_widget_get_preferred_size (widget,
363                                      &widget_req, NULL);
364     }
365
366   _gtk_file_chooser_embed_get_default_size (GTK_FILE_CHOOSER_EMBED (priv->widget),
367                                             &default_width, &default_height);
368
369   gtk_window_resize (GTK_WINDOW (dialog), default_width, default_height);
370
371   if (!gtk_widget_get_mapped (GTK_WIDGET (dialog)))
372     {
373 #if 0
374       /* FIXME: the code to restore the position does not work yet.  It is not
375        * clear whether it is actually desirable --- if enabled, applications
376        * would not be able to say "center the file chooser on top of my toplevel
377        * window".  So, we don't use this code at all.
378        */
379       load_position (&xpos, &ypos);
380       if (xpos >= 0 && ypos >= 0)
381         {
382           gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_NONE);
383           gtk_window_move (GTK_WINDOW (dialog), xpos, ypos);
384         }
385 #endif
386     }
387 }
388
389 static void
390 file_chooser_widget_response_requested (GtkWidget            *widget,
391                                         GtkFileChooserDialog *dialog)
392 {
393   GtkDialog *fc_dialog = GTK_DIALOG (dialog);
394   GtkWidget *action_area;
395   GList *children, *l;
396
397   dialog->priv->response_requested = TRUE;
398
399   if (gtk_window_activate_default (GTK_WINDOW (dialog)))
400     return;
401
402   /* There probably isn't a default widget, so make things easier for the
403    * programmer by looking for a reasonable button on our own.
404    */
405   action_area = gtk_dialog_get_action_area (fc_dialog);
406   children = gtk_container_get_children (GTK_CONTAINER (action_area));
407
408   for (l = children; l; l = l->next)
409     {
410       GtkWidget *widget;
411       int response_id;
412
413       widget = GTK_WIDGET (l->data);
414       response_id = gtk_dialog_get_response_for_widget (fc_dialog, widget);
415       if (gtk_widget_is_sensitive (widget) &&
416           is_stock_accept_response_id (response_id))
417         {
418           gtk_widget_activate (widget); /* Should we gtk_dialog_response (dialog, response_id) instead? */
419           break;
420         }
421     }
422
423   if (l == NULL)
424     dialog->priv->response_requested = FALSE;
425
426   g_list_free (children);
427 }
428   
429 static GObject*
430 gtk_file_chooser_dialog_constructor (GType                  type,
431                                      guint                  n_construct_properties,
432                                      GObjectConstructParam *construct_params)
433 {
434   GtkFileChooserDialogPrivate *priv;
435   GtkWidget *content_area;
436   GObject *object;
437
438   object = G_OBJECT_CLASS (gtk_file_chooser_dialog_parent_class)->constructor (type,
439                                                                                n_construct_properties,
440                                                                                construct_params);
441   priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (object);
442
443   gtk_widget_push_composite_child ();
444
445   if (priv->file_system)
446     priv->widget = g_object_new (GTK_TYPE_FILE_CHOOSER_WIDGET,
447                                  NULL);
448   else
449     priv->widget = g_object_new (GTK_TYPE_FILE_CHOOSER_WIDGET, NULL);
450
451   g_signal_connect (priv->widget, "file-activated",
452                     G_CALLBACK (file_chooser_widget_file_activated), object);
453   g_signal_connect (priv->widget, "default-size-changed",
454                     G_CALLBACK (file_chooser_widget_default_size_changed), object);
455   g_signal_connect (priv->widget, "response-requested",
456                     G_CALLBACK (file_chooser_widget_response_requested), object);
457
458   content_area = gtk_dialog_get_content_area (GTK_DIALOG (object));
459
460   gtk_container_set_border_width (GTK_CONTAINER (priv->widget), 5);
461   gtk_box_pack_start (GTK_BOX (content_area), priv->widget, TRUE, TRUE, 0);
462
463   gtk_widget_show (priv->widget);
464
465   _gtk_file_chooser_set_delegate (GTK_FILE_CHOOSER (object),
466                                   GTK_FILE_CHOOSER (priv->widget));
467
468   gtk_widget_pop_composite_child ();
469
470   return object;
471 }
472
473 static void
474 gtk_file_chooser_dialog_set_property (GObject         *object,
475                                       guint            prop_id,
476                                       const GValue    *value,
477                                       GParamSpec      *pspec)
478
479 {
480   GtkFileChooserDialogPrivate *priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (object);
481
482   switch (prop_id)
483     {
484     default:
485       g_object_set_property (G_OBJECT (priv->widget), pspec->name, value);
486       break;
487     }
488 }
489
490 static void
491 gtk_file_chooser_dialog_get_property (GObject         *object,
492                                       guint            prop_id,
493                                       GValue          *value,
494                                       GParamSpec      *pspec)
495 {
496   GtkFileChooserDialogPrivate *priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (object);
497
498   g_object_get_property (G_OBJECT (priv->widget), pspec->name, value);
499 }
500
501 static void
502 foreach_ensure_default_response_cb (GtkWidget *widget,
503                                     gpointer   data)
504 {
505   GtkFileChooserDialog *dialog = GTK_FILE_CHOOSER_DIALOG (data);
506   int response_id;
507
508   response_id = gtk_dialog_get_response_for_widget (GTK_DIALOG (dialog), widget);
509   if (is_stock_accept_response_id (response_id))
510     gtk_dialog_set_default_response (GTK_DIALOG (dialog), response_id);
511 }
512
513 static void
514 ensure_default_response (GtkFileChooserDialog *dialog)
515 {
516   GtkWidget *action_area;
517
518   action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
519   gtk_container_foreach (GTK_CONTAINER (action_area),
520                          foreach_ensure_default_response_cb,
521                          dialog);
522 }
523
524 /* GtkWidget::map handler */
525 static void
526 gtk_file_chooser_dialog_map (GtkWidget *widget)
527 {
528   GtkFileChooserDialog *dialog = GTK_FILE_CHOOSER_DIALOG (widget);
529   GtkFileChooserDialogPrivate *priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog);
530
531   ensure_default_response (dialog);
532
533   _gtk_file_chooser_embed_initial_focus (GTK_FILE_CHOOSER_EMBED (priv->widget));
534
535   GTK_WIDGET_CLASS (gtk_file_chooser_dialog_parent_class)->map (widget);
536 }
537
538 /* GtkDialog::response handler */
539 static void
540 response_cb (GtkDialog *dialog,
541              gint       response_id)
542 {
543   GtkFileChooserDialogPrivate *priv;
544
545   priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog);
546
547   /* Act only on response IDs we recognize */
548   if (is_stock_accept_response_id (response_id)
549       && !priv->response_requested
550       && !_gtk_file_chooser_embed_should_respond (GTK_FILE_CHOOSER_EMBED (priv->widget)))
551     {
552       g_signal_stop_emission_by_name (dialog, "response");
553     }
554
555   priv->response_requested = FALSE;
556 }
557
558 static GtkWidget *
559 gtk_file_chooser_dialog_new_valist (const gchar          *title,
560                                     GtkWindow            *parent,
561                                     GtkFileChooserAction  action,
562                                     const gchar          *first_button_text,
563                                     va_list               varargs)
564 {
565   GtkWidget *result;
566   const char *button_text = first_button_text;
567   gint response_id;
568
569   result = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG,
570                          "title", title,
571                          "action", action,
572                          NULL);
573
574   if (parent)
575     gtk_window_set_transient_for (GTK_WINDOW (result), parent);
576
577   while (button_text)
578     {
579       response_id = va_arg (varargs, gint);
580       gtk_dialog_add_button (GTK_DIALOG (result), button_text, response_id);
581       button_text = va_arg (varargs, const gchar *);
582     }
583
584   return result;
585 }
586
587 /**
588  * gtk_file_chooser_dialog_new:
589  * @title: (allow-none): Title of the dialog, or %NULL
590  * @parent: (allow-none): Transient parent of the dialog, or %NULL
591  * @action: Open or save mode for the dialog
592  * @first_button_text: (allow-none): stock ID or text to go in the first button, or %NULL
593  * @...: response ID for the first button, then additional (button, id) pairs, ending with %NULL
594  *
595  * Creates a new #GtkFileChooserDialog.  This function is analogous to
596  * gtk_dialog_new_with_buttons().
597  *
598  * Return value: a new #GtkFileChooserDialog
599  *
600  * Since: 2.4
601  **/
602 GtkWidget *
603 gtk_file_chooser_dialog_new (const gchar         *title,
604                              GtkWindow           *parent,
605                              GtkFileChooserAction action,
606                              const gchar         *first_button_text,
607                              ...)
608 {
609   GtkWidget *result;
610   va_list varargs;
611   
612   va_start (varargs, first_button_text);
613   result = gtk_file_chooser_dialog_new_valist (title, parent, action,
614                                                first_button_text,
615                                                varargs);
616   va_end (varargs);
617
618   return result;
619 }