<?xml version="1.0"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
               "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
<!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
<!ENTITY version SYSTEM "version.xml">
<!ENTITY pi "&#960;">
<!ENTITY solidus "&#8260;">
]>
<refentry id="GtkFileChooserDialog">
<refmeta>
<refentrytitle role="top_of_page" id="GtkFileChooserDialog.top_of_page">GtkFileChooserDialog</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>GTK4 Library</refmiscinfo>
</refmeta>
<refnamediv>
<refname>GtkFileChooserDialog</refname>
<refpurpose>A file chooser dialog, suitable for “File Open” or “File Save” commands</refpurpose>
</refnamediv>

<refsect1 id="GtkFileChooserDialog.functions" role="functions_proto">
<title role="functions_proto.title">Functions</title>
<informaltable pgwide="1" frame="none">
<tgroup cols="2">
<colspec colname="functions_proto_type" colwidth="150px"/>
<colspec colname="functions_proto_name"/>
<tbody>
<row><entry role="function_type"><link linkend="GtkWidget"><returnvalue>GtkWidget</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="gtk-file-chooser-dialog-new">gtk_file_chooser_dialog_new</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>

</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 id="GtkFileChooserDialog.other" role="other_proto">
<title role="other_proto.title">Types and Values</title>
<informaltable pgwide="1" frame="none">
<tgroup cols="2">
<colspec colname="other_proto_type" colwidth="150px"/>
<colspec colname="other_proto_name"/>
<tbody>
<row><entry role="datatype_keyword"></entry><entry role="function_name"><link linkend="GtkFileChooserDialog-struct">GtkFileChooserDialog</link></entry></row>

</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 id="GtkFileChooserDialog.object-hierarchy" role="object_hierarchy">
<title role="object_hierarchy.title">Object Hierarchy</title>
<screen>    <link linkend="GObject">GObject</link>
    <phrase role="lineart">&#9584;&#9472;&#9472;</phrase> <link linkend="GInitiallyUnowned">GInitiallyUnowned</link>
        <phrase role="lineart">&#9584;&#9472;&#9472;</phrase> <link linkend="GtkWidget">GtkWidget</link>
            <phrase role="lineart">&#9584;&#9472;&#9472;</phrase> <link linkend="GtkWindow">GtkWindow</link>
                <phrase role="lineart">&#9584;&#9472;&#9472;</phrase> <link linkend="GtkDialog">GtkDialog</link>
                    <phrase role="lineart">&#9584;&#9472;&#9472;</phrase> GtkFileChooserDialog
</screen>
</refsect1>
<refsect1 id="GtkFileChooserDialog.implemented-interfaces" role="impl_interfaces">
<title role="impl_interfaces.title">Implemented Interfaces</title>
<para>
GtkFileChooserDialog implements
 <link linkend="AtkImplementorIface">AtkImplementorIface</link>,  <link linkend="GtkBuildable">GtkBuildable</link>,  <link linkend="GtkConstraintTarget">GtkConstraintTarget</link>,  <link linkend="GtkNative">GtkNative</link>,  <link linkend="GtkShortcutManager">GtkShortcutManager</link>,  <link linkend="GtkRoot">GtkRoot</link> and  <link linkend="GtkFileChooser">GtkFileChooser</link>.</para>

</refsect1>

<refsect1 id="GtkFileChooserDialog.includes"><title>Includes</title><synopsis>#include &lt;gtk/gtk.h&gt;
</synopsis></refsect1>

<refsect1 id="GtkFileChooserDialog.description" role="desc">
<title role="desc.title">Description</title>
<para><link linkend="GtkFileChooserDialog"><type>GtkFileChooserDialog</type></link> is a dialog box suitable for use with
“File Open” or “File Save” commands.  This widget works by
putting a <link linkend="GtkFileChooserWidget"><type>GtkFileChooserWidget</type></link> inside a <link linkend="GtkDialog"><type>GtkDialog</type></link>.  It exposes
the <link linkend="GtkFileChooser"><type>GtkFileChooser</type></link> interface, so you can use all of the
<link linkend="GtkFileChooser"><type>GtkFileChooser</type></link> functions on the file chooser dialog as well as
those for <link linkend="GtkDialog"><type>GtkDialog</type></link>.</para>
<para>Note that <link linkend="GtkFileChooserDialog"><type>GtkFileChooserDialog</type></link> does not have any methods of its
own.  Instead, you should use the functions that work on a
<link linkend="GtkFileChooser"><type>GtkFileChooser</type></link>.</para>
<para>If you want to integrate well with the platform you should use the
<link linkend="GtkFileChooserNative"><type>GtkFileChooserNative</type></link> API, which will use a platform-specific
dialog if available and fall back to GtkFileChooserDialog
otherwise.</para>
<refsect3 id="gtkfilechooser-typical-usage"><title>Typical usage</title><para>In the simplest of cases, you can the following code to use
<link linkend="GtkFileChooserDialog"><type>GtkFileChooserDialog</type></link> to select a file for opening:</para>
<informalexample><programlisting role="example"><![CDATA[
static void
on_open_response (GtkDialog *dialog,
                  int        response)
{
  if (response == GTK_RESPONSE_ACCEPT)
    {
      GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);

      g_autoptr(GFile) file = gtk_file_chooser_get_file (chooser);

      open_file (file);
    }

  gtk_window_destroy (GTK_WINDOW (dialog));
}

  // ...
  GtkWidget *dialog;
  GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;

  dialog = gtk_file_chooser_dialog_new ("Open File",
                                        parent_window,
                                        action,
                                        _("_Cancel"),
                                        GTK_RESPONSE_CANCEL,
                                        _("_Open"),
                                        GTK_RESPONSE_ACCEPT,
                                        NULL);

  gtk_widget_show (dialog);

  g_signal_connect (dialog, "response",
                    G_CALLBACK (on_open_response),
                    NULL);
]]></programlisting></informalexample>
<para></para>
<para>To use a dialog for saving, you can use this:</para>
<informalexample><programlisting role="example"><![CDATA[
static void
on_save_response (GtkDialog *dialog,
                  int        response)
{
  if (response == GTK_RESPONSE_ACCEPT)
    {
      GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);

      g_autoptr(GFile) file = gtk_file_chooser_get_file (chooser);

      save_to_file (file);
    }

  gtk_window_destroy (GTK_WINDOW (dialog));
}

  // ...
  GtkWidget *dialog;
  GtkFileChooser *chooser;
  GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE;

  dialog = gtk_file_chooser_dialog_new ("Save File",
                                        parent_window,
                                        action,
                                        _("_Cancel"),
                                        GTK_RESPONSE_CANCEL,
                                        _("_Save"),
                                        GTK_RESPONSE_ACCEPT,
                                        NULL);
  chooser = GTK_FILE_CHOOSER (dialog);

  if (user_edited_a_new_document)
    gtk_file_chooser_set_current_name (chooser, _("Untitled document"));
  else
    gtk_file_chooser_set_file (chooser, existing_filename);

  gtk_widget_show (dialog);

  g_signal_connect (dialog, "response",
                    G_CALLBACK (on_save_response),
                    NULL);
]]></programlisting></informalexample>
<para></para>
</refsect3>
<refsect3 id="gtkfilechooserdialog-setting-up"><title>Setting up a file chooser dialog</title><para>There are various cases in which you may need to use a <link linkend="GtkFileChooserDialog"><type>GtkFileChooserDialog</type></link>:</para>
<itemizedlist>
<listitem>
<para>To select a file for opening. Use <link linkend="GTK-FILE-CHOOSER-ACTION-OPEN:CAPS"><type>GTK_FILE_CHOOSER_ACTION_OPEN</type></link>.</para>
</listitem>
<listitem>
<para>To save a file for the first time. Use <link linkend="GTK-FILE-CHOOSER-ACTION-SAVE:CAPS"><type>GTK_FILE_CHOOSER_ACTION_SAVE</type></link>,
and suggest a name such as “Untitled” with <link linkend="gtk-file-chooser-set-current-name"><function>gtk_file_chooser_set_current_name()</function></link>.</para>
</listitem>
<listitem>
<para>To save a file under a different name. Use <link linkend="GTK-FILE-CHOOSER-ACTION-SAVE:CAPS"><type>GTK_FILE_CHOOSER_ACTION_SAVE</type></link>,
and set the existing file with <link linkend="gtk-file-chooser-set-file"><function>gtk_file_chooser_set_file()</function></link>.</para>
</listitem>
<listitem>
<para>To choose a folder instead of a file. Use <link linkend="GTK-FILE-CHOOSER-ACTION-SELECT-FOLDER:CAPS"><type>GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER</type></link>.</para>
</listitem>
</itemizedlist>
<para>Note that old versions of the file chooser’s documentation suggested
using <link linkend="gtk-file-chooser-set-current-folder"><function>gtk_file_chooser_set_current_folder()</function></link> in various
situations, with the intention of letting the application
suggest a reasonable default folder.  This is no longer
considered to be a good policy, as now the file chooser is
able to make good suggestions on its own.  In general, you
should only cause the file chooser to show a specific folder
when it is appropriate to use <link linkend="gtk-file-chooser-set-file"><function>gtk_file_chooser_set_file()</function></link>,
i.e. when you are doing a Save As command and you already
have a file saved somewhere.</para>
</refsect3>
<refsect3 id="gtkfilechooserdialog-responses"><title>Response Codes</title><para><link linkend="GtkFileChooserDialog"><type>GtkFileChooserDialog</type></link> inherits from <link linkend="GtkDialog"><type>GtkDialog</type></link>, so buttons that
go in its action area have response codes such as
<link linkend="GTK-RESPONSE-ACCEPT:CAPS"><type>GTK_RESPONSE_ACCEPT</type></link> and <link linkend="GTK-RESPONSE-CANCEL:CAPS"><type>GTK_RESPONSE_CANCEL</type></link>.  For example, you
could call <link linkend="gtk-file-chooser-dialog-new"><function>gtk_file_chooser_dialog_new()</function></link> as follows:</para>
<informalexample><programlisting role="example"><![CDATA[
GtkWidget *dialog;
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;

dialog = gtk_file_chooser_dialog_new ("Open File",
                                      parent_window,
                                      action,
                                      _("_Cancel"),
                                      GTK_RESPONSE_CANCEL,
                                      _("_Open"),
                                      GTK_RESPONSE_ACCEPT,
                                      NULL);
]]></programlisting></informalexample>
<para></para>
<para>This will create buttons for “Cancel” and “Open” that use predefined
response identifiers from <link linkend="GtkResponseType"><type>GtkResponseType</type></link>.  For most dialog
boxes you can use your own custom response codes rather than the
ones in <link linkend="GtkResponseType"><type>GtkResponseType</type></link>, but <link linkend="GtkFileChooserDialog"><type>GtkFileChooserDialog</type></link> assumes that
its “accept”-type action, e.g. an “Open” or “Save” button,
will have one of the following response codes:</para>
<itemizedlist>
<listitem><para><link linkend="GTK-RESPONSE-ACCEPT:CAPS"><type>GTK_RESPONSE_ACCEPT</type></link></para></listitem>
<listitem><para><link linkend="GTK-RESPONSE-OK:CAPS"><type>GTK_RESPONSE_OK</type></link></para></listitem>
<listitem><para><link linkend="GTK-RESPONSE-YES:CAPS"><type>GTK_RESPONSE_YES</type></link></para></listitem>
<listitem>
<para><link linkend="GTK-RESPONSE-APPLY:CAPS"><type>GTK_RESPONSE_APPLY</type></link></para>
</listitem>
</itemizedlist>
<para>This is because <link linkend="GtkFileChooserDialog"><type>GtkFileChooserDialog</type></link> must intercept responses
and switch to folders if appropriate, rather than letting the
dialog terminate — the implementation uses these known
response codes to know which responses can be blocked if
appropriate.</para>
<para>To summarize, make sure you use a
<link linkend="gtkfilechooserdialog-responses">predefined response code</link>
when you use <link linkend="GtkFileChooserDialog"><type>GtkFileChooserDialog</type></link> to ensure proper operation.</para>
</refsect3>

</refsect1>
<refsect1 id="GtkFileChooserDialog.functions_details" role="details">
<title role="details.title">Functions</title>
<refsect2 id="gtk-file-chooser-dialog-new" role="function">
<title>gtk_file_chooser_dialog_new&#160;()</title>
<indexterm zone="gtk-file-chooser-dialog-new"><primary>gtk_file_chooser_dialog_new</primary></indexterm>
<programlisting language="C"><link linkend="GtkWidget"><returnvalue>GtkWidget</returnvalue></link>&#160;*
gtk_file_chooser_dialog_new (<parameter>const <link linkend="gchar"><type>gchar</type></link> *title</parameter>,
                             <parameter><link linkend="GtkWindow"><type>GtkWindow</type></link> *parent</parameter>,
                             <parameter><link linkend="GtkFileChooserAction"><type>GtkFileChooserAction</type></link> action</parameter>,
                             <parameter>const <link linkend="gchar"><type>gchar</type></link> *first_button_text</parameter>,
                             <parameter>...</parameter>);</programlisting>
<para>Creates a new <link linkend="GtkFileChooserDialog"><type>GtkFileChooserDialog</type></link>.  This function is analogous to
<link linkend="gtk-dialog-new-with-buttons"><function>gtk_dialog_new_with_buttons()</function></link>.</para>
<refsect3 id="gtk-file-chooser-dialog-new.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>title</para></entry>
<entry role="parameter_description"><para>Title of the dialog, or <link linkend="NULL:CAPS"><literal>NULL</literal></link>. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>allow-none</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>parent</para></entry>
<entry role="parameter_description"><para>Transient parent of the dialog, or <link linkend="NULL:CAPS"><literal>NULL</literal></link>. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>allow-none</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>action</para></entry>
<entry role="parameter_description"><para>Open or save mode for the dialog</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>first_button_text</para></entry>
<entry role="parameter_description"><para>text to go in the first button, or <link linkend="NULL:CAPS"><literal>NULL</literal></link>. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>allow-none</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>...</para></entry>
<entry role="parameter_description"><para>response ID for the first button, then additional (button, id) pairs, ending with <link linkend="NULL:CAPS"><literal>NULL</literal></link></para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="gtk-file-chooser-dialog-new.returns" role="returns">
<title>Returns</title>
<para> a new <link linkend="GtkFileChooserDialog"><type>GtkFileChooserDialog</type></link></para>
</refsect3></refsect2>

</refsect1>
<refsect1 id="GtkFileChooserDialog.other_details" role="details">
<title role="details.title">Types and Values</title>
<refsect2 id="GtkFileChooserDialog-struct" role="struct">
<title>GtkFileChooserDialog</title>
<indexterm zone="GtkFileChooserDialog-struct"><primary>GtkFileChooserDialog</primary></indexterm>
<programlisting language="C">typedef struct _GtkFileChooserDialog GtkFileChooserDialog;</programlisting>
</refsect2>

</refsect1>
<refsect1 id="GtkFileChooserDialog.see-also">
<title>See Also</title>
<para><link linkend="GtkFileChooser"><type>GtkFileChooser</type></link>, <link linkend="GtkDialog"><type>GtkDialog</type></link>, <link linkend="GtkFileChooserNative"><type>GtkFileChooserNative</type></link></para>

</refsect1>

</refentry>
