<?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="gtk4-GtkFileChooserNative">
<refmeta>
<refentrytitle role="top_of_page" id="gtk4-GtkFileChooserNative.top_of_page">GtkFileChooserNative</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>GTK4 Library</refmiscinfo>
</refmeta>
<refnamediv>
<refname>GtkFileChooserNative</refname>
<refpurpose>A native file chooser dialog, suitable for “File Open” or “File Save” commands</refpurpose>
</refnamediv>

<refsect1 id="gtk4-GtkFileChooserNative.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="GtkFileChooserNative"><returnvalue>GtkFileChooserNative</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="gtk-file-chooser-native-new">gtk_file_chooser_native_new</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type">const <link linkend="char"><returnvalue>char</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="gtk-file-chooser-native-get-accept-label">gtk_file_chooser_native_get_accept_label</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="void"><returnvalue>void</returnvalue></link>
</entry><entry role="function_name"><link linkend="gtk-file-chooser-native-set-accept-label">gtk_file_chooser_native_set_accept_label</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type">const <link linkend="char"><returnvalue>char</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="gtk-file-chooser-native-get-cancel-label">gtk_file_chooser_native_get_cancel_label</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="void"><returnvalue>void</returnvalue></link>
</entry><entry role="function_name"><link linkend="gtk-file-chooser-native-set-cancel-label">gtk_file_chooser_native_set_cancel_label</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>

</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 id="gtk4-GtkFileChooserNative.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="GtkFileChooserNative">GtkFileChooserNative</link></entry></row>

</tbody>
</tgroup>
</informaltable>
</refsect1>

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

<refsect1 id="gtk4-GtkFileChooserNative.description" role="desc">
<title role="desc.title">Description</title>
<para><link linkend="GtkFileChooserNative"><type>GtkFileChooserNative</type></link> is an abstraction of a dialog box suitable
for use with “File Open” or “File Save as” commands. By default, this
just uses a <link linkend="GtkFileChooserDialog"><type>GtkFileChooserDialog</type></link> to implement the actual dialog.
However, on certain platforms, such as Windows and macOS, the native platform
file chooser is used instead. When the application is running in a
sandboxed environment without direct filesystem access (such as Flatpak),
<link linkend="GtkFileChooserNative"><type>GtkFileChooserNative</type></link> may call the proper APIs (portals) to let the user
choose a file and make it available to the application.</para>
<para>While the API of <link linkend="GtkFileChooserNative"><type>GtkFileChooserNative</type></link> closely mirrors <link linkend="GtkFileChooserDialog"><type>GtkFileChooserDialog</type></link>,
the main difference is that there is no access to any <link linkend="GtkWindow"><type>GtkWindow</type></link> or <link linkend="GtkWidget"><type>GtkWidget</type></link>
for the dialog. This is required, as there may not be one in the case of a
platform native dialog.</para>
<para>Showing, hiding and running the dialog is handled by the <link linkend="GtkNativeDialog"><type>GtkNativeDialog</type></link>
functions.</para>
<refsect3 id="gtkfilechoosernative-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_response (GtkNativeDialog *dialog,
             int              response)
{
  if (response == GTK_RESPONSE_ACCEPT)
    {
      GtkFileChooser *chooser = GTK_FILE_CHOOSER (native);
      GFile *file = gtk_file_chooser_get_file (chooser);

      open_file (file);

      g_object_unref (file);
    }

  g_object_unref (native);
}

  // ...
  GtkFileChooserNative *native;
  GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;

  native = gtk_file_chooser_native_new ("Open File",
                                        parent_window,
                                        action,
                                        "_Open",
                                        "_Cancel");

  g_signal_connect (native, "response", G_CALLBACK (on_response), NULL);
  gtk_native_dialog_show (GTK_NATIVE_DIALOG (native));
]]></programlisting></informalexample>
<para></para>
<para>To use a dialog for saving, you can use this:</para>
<informalexample><programlisting role="example"><![CDATA[
static void
on_response (GtkNativeDialog *dialog,
             int              response)
{
  if (response == GTK_RESPONSE_ACCEPT)
    {
      GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);
      GFile *file = gtk_file_chooser_get_file (chooser);

      save_to_file (file);

      g_object_unref (file);
    }

  g_object_unref (native);
}

  // ...
  GtkFileChooserNative *native;
  GtkFileChooser *chooser;
  GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE;

  native = gtk_file_chooser_native_new ("Save File",
                                        parent_window,
                                        action,
                                        "_Save",
                                        "_Cancel");
  chooser = GTK_FILE_CHOOSER (native);

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

  g_signal_connect (native, "response", G_CALLBACK (on_response), NULL);
  gtk_native_dialog_show (GTK_NATIVE_DIALOG (native));
]]></programlisting></informalexample>
<para></para>
<para>For more information on how to best set up a file dialog, see <link linkend="GtkFileChooserDialog"><type>GtkFileChooserDialog</type></link>.</para>
</refsect3>
<refsect3 id="gtkfilechooserdialognative-responses"><title>Response Codes</title><para><link linkend="GtkFileChooserNative"><type>GtkFileChooserNative</type></link> inherits from <link linkend="GtkNativeDialog"><type>GtkNativeDialog</type></link>, which means it
will return <link linkend="GTK-RESPONSE-ACCEPT:CAPS"><type>GTK_RESPONSE_ACCEPT</type></link> if the user accepted, and
<link linkend="GTK-RESPONSE-CANCEL:CAPS"><type>GTK_RESPONSE_CANCEL</type></link> if he pressed cancel. It can also return
<link linkend="GTK-RESPONSE-DELETE-EVENT:CAPS"><type>GTK_RESPONSE_DELETE_EVENT</type></link> if the window was unexpectedly closed.</para>
</refsect3>
<refsect3 id="gtkfilechooserdialognative-differences"><title>Differences from <link linkend="GtkFileChooserDialog"><type>GtkFileChooserDialog</type></link></title><para>There are a few things in the GtkFileChooser API that are not
possible to use with <link linkend="GtkFileChooserNative"><type>GtkFileChooserNative</type></link>, as such use would
prohibit the use of a native dialog.</para>
<para>There is no support for the signals that are emitted when the user
navigates in the dialog, including:</para>
<itemizedlist>
<listitem><para><link linkend="GtkFileChooser-current-folder-changed"><type>“current-folder-changed”</type></link></para></listitem>
<listitem><para><link linkend="GtkFileChooser-selection-changed"><type>“selection-changed”</type></link></para></listitem>
<listitem>
<para><link linkend="GtkFileChooser-file-activated"><type>“file-activated”</type></link></para>
</listitem>
</itemizedlist>
<para>You can also not use the methods that directly control user navigation:</para>
<itemizedlist>
<listitem><para>gtk_file_chooser_unselect_filename()</para></listitem>
<listitem><para>gtk_file_chooser_select_all()</para></listitem>
<listitem>
<para>gtk_file_chooser_unselect_all()</para>
</listitem>
</itemizedlist>
<para>If you need any of the above you will have to use <link linkend="GtkFileChooserDialog"><type>GtkFileChooserDialog</type></link> directly.</para>
<para>No operations that change the dialog work while the dialog is visible. Set
all the properties that are required before showing the dialog.</para>
</refsect3>
<refsect3 id="gtkfilechooserdialognative-win32"><title>Win32 details</title><para>On windows the IFileDialog implementation (added in Windows Vista) is
used. It supports many of the features that <link linkend="GtkFileChooserDialog"><type>GtkFileChooserDialog</type></link>
does, but there are some things it does not handle:</para>
<itemizedlist>
<listitem>
<para>Any <link linkend="GtkFileFilter"><type>GtkFileFilter</type></link> added using a mimetype or custom filter.</para>
</listitem>
</itemizedlist>
<para>If any of these features are used the regular <link linkend="GtkFileChooserDialog"><type>GtkFileChooserDialog</type></link>
will be used in place of the native one.</para>
</refsect3>
<refsect3 id="gtkfilechooserdialognative-portal"><title>Portal details</title><para>When the org.freedesktop.portal.FileChooser portal is available on the
session bus, it is used to bring up an out-of-process file chooser. Depending
on the kind of session the application is running in, this may or may not
be a GTK+ file chooser. In this situation, the following things are not
supported and will be silently ignored:</para>
<itemizedlist>
<listitem>
<para>Any <link linkend="GtkFileFilter"><type>GtkFileFilter</type></link> added with a custom filter.</para>
</listitem>
</itemizedlist>
</refsect3>
<refsect3 id="gtkfilechooserdialognative-macos"><title>macOS details</title><para>On macOS the NSSavePanel and NSOpenPanel classes are used to provide native
file chooser dialogs. Some features provided by <link linkend="GtkFileChooserDialog"><type>GtkFileChooserDialog</type></link> are
not supported:</para>
<itemizedlist>
<listitem>
<para>Any <link linkend="GtkFileFilter"><type>GtkFileFilter</type></link> added with a custom filter.</para>
</listitem>
<listitem><para>Shortcut folders.</para></listitem>
</itemizedlist>
</refsect3>

</refsect1>
<refsect1 id="gtk4-GtkFileChooserNative.functions_details" role="details">
<title role="details.title">Functions</title>
<refsect2 id="gtk-file-chooser-native-new" role="function">
<title>gtk_file_chooser_native_new&#160;()</title>
<indexterm zone="gtk-file-chooser-native-new"><primary>gtk_file_chooser_native_new</primary></indexterm>
<programlisting language="C"><link linkend="GtkFileChooserNative"><returnvalue>GtkFileChooserNative</returnvalue></link>&#160;*
gtk_file_chooser_native_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> *accept_label</parameter>,
                             <parameter>const <link linkend="gchar"><type>gchar</type></link> *cancel_label</parameter>);</programlisting>
<para>Creates a new <link linkend="GtkFileChooserNative"><type>GtkFileChooserNative</type></link>.</para>
<refsect3 id="gtk-file-chooser-native-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 native, 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 native, 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>accept_label</para></entry>
<entry role="parameter_description"><para>text to go in the accept button, or <link linkend="NULL:CAPS"><literal>NULL</literal></link> for the default. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>allow-none</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>cancel_label</para></entry>
<entry role="parameter_description"><para>text to go in the cancel button, or <link linkend="NULL:CAPS"><literal>NULL</literal></link> for the default. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>allow-none</acronym>]</emphasis></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="gtk-file-chooser-native-new.returns" role="returns">
<title>Returns</title>
<para> a new <link linkend="GtkFileChooserNative"><type>GtkFileChooserNative</type></link></para>
</refsect3></refsect2>
<refsect2 id="gtk-file-chooser-native-get-accept-label" role="function">
<title>gtk_file_chooser_native_get_accept_label&#160;()</title>
<indexterm zone="gtk-file-chooser-native-get-accept-label"><primary>gtk_file_chooser_native_get_accept_label</primary></indexterm>
<programlisting language="C">const <link linkend="char"><returnvalue>char</returnvalue></link>&#160;*
gtk_file_chooser_native_get_accept_label
                               (<parameter><link linkend="GtkFileChooserNative"><type>GtkFileChooserNative</type></link> *self</parameter>);</programlisting>
<para>Retrieves the custom label text for the accept button.</para>
<refsect3 id="gtk-file-chooser-native-get-accept-label.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>self</para></entry>
<entry role="parameter_description"><para>a <link linkend="GtkFileChooserNative"><type>GtkFileChooserNative</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="gtk-file-chooser-native-get-accept-label.returns" role="returns">
<title>Returns</title>
<para>The custom label, or <link linkend="NULL:CAPS"><literal>NULL</literal></link> for the default. This string
is owned by GTK+ and should not be modified or freed. </para>
<para><emphasis role="annotation">[<acronym>nullable</acronym>]</emphasis></para>
</refsect3></refsect2>
<refsect2 id="gtk-file-chooser-native-set-accept-label" role="function">
<title>gtk_file_chooser_native_set_accept_label&#160;()</title>
<indexterm zone="gtk-file-chooser-native-set-accept-label"><primary>gtk_file_chooser_native_set_accept_label</primary></indexterm>
<programlisting language="C"><link linkend="void"><returnvalue>void</returnvalue></link>
gtk_file_chooser_native_set_accept_label
                               (<parameter><link linkend="GtkFileChooserNative"><type>GtkFileChooserNative</type></link> *self</parameter>,
                                <parameter>const <link linkend="char"><type>char</type></link> *accept_label</parameter>);</programlisting>
<para>Sets the custom label text for the accept button.</para>
<para>If characters in <parameter>label</parameter>
 are preceded by an underscore, they are underlined.
If you need a literal underscore character in a label, use “__” (two
underscores). The first underlined character represents a keyboard
accelerator called a mnemonic.
Pressing Alt and that key activates the button.</para>
<refsect3 id="gtk-file-chooser-native-set-accept-label.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>self</para></entry>
<entry role="parameter_description"><para>a <link linkend="GtkFileChooserNative"><type>GtkFileChooserNative</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>accept_label</para></entry>
<entry role="parameter_description"><para>custom label or <link linkend="NULL:CAPS"><literal>NULL</literal></link> for the default. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>allow-none</acronym>]</emphasis></entry></row>
</tbody></tgroup></informaltable>
</refsect3></refsect2>
<refsect2 id="gtk-file-chooser-native-get-cancel-label" role="function">
<title>gtk_file_chooser_native_get_cancel_label&#160;()</title>
<indexterm zone="gtk-file-chooser-native-get-cancel-label"><primary>gtk_file_chooser_native_get_cancel_label</primary></indexterm>
<programlisting language="C">const <link linkend="char"><returnvalue>char</returnvalue></link>&#160;*
gtk_file_chooser_native_get_cancel_label
                               (<parameter><link linkend="GtkFileChooserNative"><type>GtkFileChooserNative</type></link> *self</parameter>);</programlisting>
<para>Retrieves the custom label text for the cancel button.</para>
<refsect3 id="gtk-file-chooser-native-get-cancel-label.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>self</para></entry>
<entry role="parameter_description"><para>a <link linkend="GtkFileChooserNative"><type>GtkFileChooserNative</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="gtk-file-chooser-native-get-cancel-label.returns" role="returns">
<title>Returns</title>
<para>The custom label, or <link linkend="NULL:CAPS"><literal>NULL</literal></link> for the default. This string
is owned by GTK+ and should not be modified or freed. </para>
<para><emphasis role="annotation">[<acronym>nullable</acronym>]</emphasis></para>
</refsect3></refsect2>
<refsect2 id="gtk-file-chooser-native-set-cancel-label" role="function">
<title>gtk_file_chooser_native_set_cancel_label&#160;()</title>
<indexterm zone="gtk-file-chooser-native-set-cancel-label"><primary>gtk_file_chooser_native_set_cancel_label</primary></indexterm>
<programlisting language="C"><link linkend="void"><returnvalue>void</returnvalue></link>
gtk_file_chooser_native_set_cancel_label
                               (<parameter><link linkend="GtkFileChooserNative"><type>GtkFileChooserNative</type></link> *self</parameter>,
                                <parameter>const <link linkend="char"><type>char</type></link> *cancel_label</parameter>);</programlisting>
<para>Sets the custom label text for the cancel button.</para>
<para>If characters in <parameter>label</parameter>
 are preceded by an underscore, they are underlined.
If you need a literal underscore character in a label, use “__” (two
underscores). The first underlined character represents a keyboard
accelerator called a mnemonic.
Pressing Alt and that key activates the button.</para>
<refsect3 id="gtk-file-chooser-native-set-cancel-label.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>self</para></entry>
<entry role="parameter_description"><para>a <link linkend="GtkFileChooserNative"><type>GtkFileChooserNative</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>cancel_label</para></entry>
<entry role="parameter_description"><para>custom label or <link linkend="NULL:CAPS"><literal>NULL</literal></link> for the default. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>allow-none</acronym>]</emphasis></entry></row>
</tbody></tgroup></informaltable>
</refsect3></refsect2>

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

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

</refsect1>

</refentry>
