Gtk.File_Chooser_Dialog

Entities

Tagged Types

Access Types

Subprograms

Generic Instantiations

Description

Gtk.File_Chooser_Dialog.Gtk_File_Chooser_Dialog is a dialog box suitable for use with "File/Open" or "File/Save as" commands. This widget works by putting a Gtk.File_Chooser_Widget.Gtk_File_Chooser_Widget inside a Gtk.Dialog.Gtk_Dialog. It exposes the Gtk.File_Chooser.Gtk_File_Chooser interface, so you can use all of the Gtk.File_Chooser.Gtk_File_Chooser functions on the file chooser dialog as well as those for Gtk.Dialog.Gtk_Dialog.

Note that Gtk.File_Chooser_Dialog.Gtk_File_Chooser_Dialog does not have any methods of its own. Instead, you should use the functions that work on a Gtk.File_Chooser.Gtk_File_Chooser.

If you want to integrate well with the platform you should use the Gtk.File_Chooser_Native.Gtk_File_Chooser_Native API, which will use a platform-specific dialog if available and fall back to GtkFileChooserDialog otherwise.

## Typical usage ## {gtkfilechooser-typical-usage}

In the simplest of cases, you can the following code to use Gtk.File_Chooser_Dialog.Gtk_File_Chooser_Dialog to select a file for opening:

GtkWidget *dialog;
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
gint res;

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

res = gtk_dialog_run (GTK_DIALOG (dialog));
if (res == GTK_RESPONSE_ACCEPT)
  {
    char *filename;
    GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);
    filename = gtk_file_chooser_get_filename (chooser);
    open_file (filename);
    g_free (filename);
  }

gtk_widget_destroy (dialog);

To use a dialog for saving, you can use this:

GtkWidget *dialog;
GtkFileChooser *chooser;
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE;
gint res;

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);

gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);

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

res = gtk_dialog_run (GTK_DIALOG (dialog));
if (res == GTK_RESPONSE_ACCEPT)
  {
    char *filename;

    filename = gtk_file_chooser_get_filename (chooser);
    save_to_file (filename);
    g_free (filename);
  }

gtk_widget_destroy (dialog);

## Setting up a file chooser dialog ## {gtkfilechooserdialog-setting-up}

There are various cases in which you may need to use a Gtk.File_Chooser_Dialog.Gtk_File_Chooser_Dialog:

suggest a name such as "Untitled" with Gtk.File_Chooser.Set_Current_Name.

and set the existing filename with Gtk.File_Chooser.Set_Filename.

GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER.

Note that old versions of the file chooser's documentation suggested using Gtk.File_Chooser.Set_Current_Folder 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 Gtk.File_Chooser.Set_Filename, i.e. when you are doing a Save As command and you already have a file saved somewhere.

## Response Codes ## {gtkfilechooserdialog-responses}

Gtk.File_Chooser_Dialog.Gtk_File_Chooser_Dialog inherits from Gtk.Dialog.Gtk_Dialog, so buttons that go in its action area have response codes such as GTK_RESPONSE_ACCEPT and GTK_RESPONSE_CANCEL. For example, you could call Gtk_New as follows:

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);

This will create buttons for "Cancel" and "Open" that use stock response identifiers from Gtk_Response_Type. For most dialog boxes you can use your own custom response codes rather than the ones in Gtk_Response_Type, but Gtk.File_Chooser_Dialog.Gtk_File_Chooser_Dialog assumes that its "accept"-type action, e.g. an "Open" or "Save" button, will have one of the following response codes:

GTK_RESPONSE_APPLY

This is because Gtk.File_Chooser_Dialog.Gtk_File_Chooser_Dialog 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.

To summarize, make sure you use a [stock response code][gtkfilechooserdialog-responses] when you use Gtk.File_Chooser_Dialog.Gtk_File_Chooser_Dialog to ensure proper operation.

"+"

function "+"
  (Widget : access Gtk_File_Chooser_Dialog_Record'Class)
return Gtk.Buildable.Gtk_Buildable
Parameters
Widget
Return Value

"+"

function "+"
  (Widget : access Gtk_File_Chooser_Dialog_Record'Class)
return Gtk.File_Chooser.Gtk_File_Chooser
Parameters
Widget
Return Value

"-"

function "-"
  (Interf : Gtk.Buildable.Gtk_Buildable)
return Gtk_File_Chooser_Dialog
Parameters
Interf
Return Value

"-"

function "-"
  (Interf : Gtk.File_Chooser.Gtk_File_Chooser)
return Gtk_File_Chooser_Dialog
Parameters
Interf
Return Value

Add_Choice

procedure Add_Choice
   (Chooser       : not null access Gtk_File_Chooser_Dialog_Record;
    Id            : UTF8_String;
    Label         : UTF8_String;
    Options       : GNAT.Strings.String_List;
    Option_Labels : GNAT.Strings.String_List)
Parameters
Chooser
Id
Label
Options
Option_Labels

Add_Filter

procedure Add_Filter
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record;
    Filter  : not null access Gtk.File_Filter.Gtk_File_Filter_Record'Class)
Parameters
Chooser
Filter

Add_Shortcut_Folder

function Add_Shortcut_Folder
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record;
    Folder  : UTF8_String) return Boolean
Parameters
Chooser
Folder
Return Value

Add_Shortcut_Folder_Uri

function Add_Shortcut_Folder_Uri
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record;
    URI     : UTF8_String) return Boolean
Parameters
Chooser
URI
Return Value

Get_Action

function Get_Action
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record)
    return Gtk.File_Chooser.Gtk_File_Chooser_Action
Parameters
Chooser
Return Value

Get_Choice

function Get_Choice
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record;
    Id      : UTF8_String) return UTF8_String
Parameters
Chooser
Id
Return Value

Get_Create_Folders

function Get_Create_Folders
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record)
    return Boolean
Parameters
Chooser
Return Value

Get_Current_Folder

function Get_Current_Folder
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record)
    return UTF8_String
Parameters
Chooser
Return Value

Get_Current_Folder_Uri

function Get_Current_Folder_Uri
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record)
    return UTF8_String
Parameters
Chooser
Return Value

Get_Current_Name

function Get_Current_Name
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record)
    return UTF8_String
Parameters
Chooser
Return Value

Get_Do_Overwrite_Confirmation

function Get_Do_Overwrite_Confirmation
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record)
    return Boolean
Parameters
Chooser
Return Value

Get_Extra_Widget

function Get_Extra_Widget
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record)
    return Gtk.Widget.Gtk_Widget
Parameters
Chooser
Return Value

Get_Filename

function Get_Filename
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record)
    return UTF8_String
Parameters
Chooser
Return Value

Get_Filenames

function Get_Filenames
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record)
    return Gtk.Enums.String_SList.GSlist
Parameters
Chooser
Return Value

Get_Filter

function Get_Filter
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record)
    return Gtk.File_Filter.Gtk_File_Filter
Parameters
Chooser
Return Value

Get_Local_Only

function Get_Local_Only
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record)
    return Boolean
Parameters
Chooser
Return Value

Get_Preview_Filename

function Get_Preview_Filename
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record)
    return UTF8_String
Parameters
Chooser
Return Value

Get_Preview_Uri

function Get_Preview_Uri
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record)
    return UTF8_String
Parameters
Chooser
Return Value

Get_Preview_Widget

function Get_Preview_Widget
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record)
    return Gtk.Widget.Gtk_Widget
Parameters
Chooser
Return Value

Get_Preview_Widget_Active

function Get_Preview_Widget_Active
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record)
    return Boolean
Parameters
Chooser
Return Value

Get_Select_Multiple

function Get_Select_Multiple
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record)
    return Boolean
Parameters
Chooser
Return Value

Get_Show_Hidden

function Get_Show_Hidden
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record)
    return Boolean
Parameters
Chooser
Return Value

Get_Type

function Get_Type return Glib.GType
Return Value

Get_Uri

function Get_Uri
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record)
    return UTF8_String
Parameters
Chooser
Return Value

Get_Uris

function Get_Uris
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record)
    return Gtk.Enums.String_SList.GSlist
Parameters
Chooser
Return Value

Get_Use_Preview_Label

function Get_Use_Preview_Label
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record)
    return Boolean
Parameters
Chooser
Return Value

Gtk_File_Chooser_Dialog

type Gtk_File_Chooser_Dialog is access all Gtk_File_Chooser_Dialog_Record'Class;

Gtk_File_Chooser_Dialog_New

function Gtk_File_Chooser_Dialog_New
   (Title  : UTF8_String := "";
    Parent : access Gtk.Window.Gtk_Window_Record'Class;
    Action : Gtk.File_Chooser.Gtk_File_Chooser_Action)
    return Gtk_File_Chooser_Dialog

Creates a new Gtk.File_Chooser_Dialog.Gtk_File_Chooser_Dialog. This function is analogous to gtk_dialog_new_with_buttons. Since: gtk+ 2.4

Parameters
Title

Title of the dialog, or null

Parent

Transient parent of the dialog, or null

Action

Open or save mode for the dialog

Return Value

Gtk_File_Chooser_Dialog_Record

type Gtk_File_Chooser_Dialog_Record is new Gtk_Dialog_Record with null record;

Gtk_New

procedure Gtk_New
   (Dialog : out Gtk_File_Chooser_Dialog;
    Title  : UTF8_String := "";
    Parent : access Gtk.Window.Gtk_Window_Record'Class;
    Action : Gtk.File_Chooser.Gtk_File_Chooser_Action)

Creates a new Gtk.File_Chooser_Dialog.Gtk_File_Chooser_Dialog. This function is analogous to gtk_dialog_new_with_buttons. Since: gtk+ 2.4 Initialize does nothing if the object was already created with another call to Initialize* or G_New.

Parameters
Dialog
Title

Title of the dialog, or null

Parent

Transient parent of the dialog, or null

Action

Open or save mode for the dialog

Implements_Gtk_Buildable

package Implements_Gtk_Buildable is new Glib.Types.Implements
  (Gtk.Buildable.Gtk_Buildable, Gtk_File_Chooser_Dialog_Record, Gtk_File_Chooser_Dialog);

Implements_Gtk_File_Chooser

package Implements_Gtk_File_Chooser is new Glib.Types.Implements
  (Gtk.File_Chooser.Gtk_File_Chooser, Gtk_File_Chooser_Dialog_Record, Gtk_File_Chooser_Dialog);

Initialize

procedure Initialize
   (Dialog : not null access Gtk_File_Chooser_Dialog_Record'Class;
    Title  : UTF8_String := "";
    Parent : access Gtk.Window.Gtk_Window_Record'Class;
    Action : Gtk.File_Chooser.Gtk_File_Chooser_Action)

Creates a new Gtk.File_Chooser_Dialog.Gtk_File_Chooser_Dialog. This function is analogous to gtk_dialog_new_with_buttons. Since: gtk+ 2.4 Initialize does nothing if the object was already created with another call to Initialize* or G_New.

Parameters
Dialog
Title

Title of the dialog, or null

Parent

Transient parent of the dialog, or null

Action

Open or save mode for the dialog

List_Filters

function List_Filters
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record)
    return Glib.Object.Object_List.GSlist
Parameters
Chooser
Return Value

List_Shortcut_Folder_Uris

function List_Shortcut_Folder_Uris
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record)
    return Gtk.Enums.String_SList.GSlist
Parameters
Chooser
Return Value

List_Shortcut_Folders

function List_Shortcut_Folders
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record)
    return Gtk.Enums.String_SList.GSlist
Parameters
Chooser
Return Value

Remove_Choice

procedure Remove_Choice
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record;
    Id      : UTF8_String)
Parameters
Chooser
Id

Remove_Filter

procedure Remove_Filter
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record;
    Filter  : not null access Gtk.File_Filter.Gtk_File_Filter_Record'Class)
Parameters
Chooser
Filter

Remove_Shortcut_Folder

function Remove_Shortcut_Folder
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record;
    Folder  : UTF8_String) return Boolean
Parameters
Chooser
Folder
Return Value

Remove_Shortcut_Folder_Uri

function Remove_Shortcut_Folder_Uri
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record;
    URI     : UTF8_String) return Boolean
Parameters
Chooser
URI
Return Value

Select_All

procedure Select_All
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record)
Parameters
Chooser

Select_Filename

function Select_Filename
   (Chooser  : not null access Gtk_File_Chooser_Dialog_Record;
    Filename : UTF8_String) return Boolean
Parameters
Chooser
Filename
Return Value

Select_Uri

function Select_Uri
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record;
    URI     : UTF8_String) return Boolean
Parameters
Chooser
URI
Return Value

Set_Action

procedure Set_Action
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record;
    Action  : Gtk.File_Chooser.Gtk_File_Chooser_Action)
Parameters
Chooser
Action

Set_Choice

procedure Set_Choice
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record;
    Id      : UTF8_String;
    Option  : UTF8_String)
Parameters
Chooser
Id
Option

Set_Create_Folders

procedure Set_Create_Folders
   (Chooser        : not null access Gtk_File_Chooser_Dialog_Record;
    Create_Folders : Boolean)
Parameters
Chooser
Create_Folders

Set_Current_Folder

function Set_Current_Folder
   (Chooser  : not null access Gtk_File_Chooser_Dialog_Record;
    Filename : UTF8_String) return Boolean
Parameters
Chooser
Filename
Return Value

Set_Current_Folder_Uri

function Set_Current_Folder_Uri
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record;
    URI     : UTF8_String) return Boolean
Parameters
Chooser
URI
Return Value

Set_Current_Name

procedure Set_Current_Name
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record;
    Name    : UTF8_String)
Parameters
Chooser
Name

Set_Do_Overwrite_Confirmation

procedure Set_Do_Overwrite_Confirmation
   (Chooser                   : not null access Gtk_File_Chooser_Dialog_Record;
    Do_Overwrite_Confirmation : Boolean)
Parameters
Chooser
Do_Overwrite_Confirmation

Set_Extra_Widget

procedure Set_Extra_Widget
   (Chooser      : not null access Gtk_File_Chooser_Dialog_Record;
    Extra_Widget : not null access Gtk.Widget.Gtk_Widget_Record'Class)
Parameters
Chooser
Extra_Widget

Set_Filename

function Set_Filename
   (Chooser  : not null access Gtk_File_Chooser_Dialog_Record;
    Filename : UTF8_String) return Boolean
Parameters
Chooser
Filename
Return Value

Set_Filter

procedure Set_Filter
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record;
    Filter  : not null access Gtk.File_Filter.Gtk_File_Filter_Record'Class)
Parameters
Chooser
Filter

Set_Local_Only

procedure Set_Local_Only
   (Chooser    : not null access Gtk_File_Chooser_Dialog_Record;
    Local_Only : Boolean)
Parameters
Chooser
Local_Only

Set_Preview_Widget

procedure Set_Preview_Widget
   (Chooser        : not null access Gtk_File_Chooser_Dialog_Record;
    Preview_Widget : not null access Gtk.Widget.Gtk_Widget_Record'Class)
Parameters
Chooser
Preview_Widget

Set_Preview_Widget_Active

procedure Set_Preview_Widget_Active
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record;
    Active  : Boolean)
Parameters
Chooser
Active

Set_Select_Multiple

procedure Set_Select_Multiple
   (Chooser         : not null access Gtk_File_Chooser_Dialog_Record;
    Select_Multiple : Boolean)
Parameters
Chooser
Select_Multiple

Set_Show_Hidden

procedure Set_Show_Hidden
   (Chooser     : not null access Gtk_File_Chooser_Dialog_Record;
    Show_Hidden : Boolean)
Parameters
Chooser
Show_Hidden

Set_Uri

function Set_Uri
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record;
    URI     : UTF8_String) return Boolean
Parameters
Chooser
URI
Return Value

Set_Use_Preview_Label

procedure Set_Use_Preview_Label
   (Chooser   : not null access Gtk_File_Chooser_Dialog_Record;
    Use_Label : Boolean)
Parameters
Chooser
Use_Label

Unselect_All

procedure Unselect_All
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record)
Parameters
Chooser

Unselect_Filename

procedure Unselect_Filename
   (Chooser  : not null access Gtk_File_Chooser_Dialog_Record;
    Filename : UTF8_String)
Parameters
Chooser
Filename

Unselect_Uri

procedure Unselect_Uri
   (Chooser : not null access Gtk_File_Chooser_Dialog_Record;
    URI     : UTF8_String)
Parameters
Chooser
URI