1. ------------------------------------------------------------------------------ 
  2. --                                                                          -- 
  3. --      Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet       -- 
  4. --                     Copyright (C) 2000-2014, AdaCore                     -- 
  5. --                                                                          -- 
  6. -- This library is free software;  you can redistribute it and/or modify it -- 
  7. -- under terms of the  GNU General Public License  as published by the Free -- 
  8. -- Software  Foundation;  either version 3,  or (at your  option) any later -- 
  9. -- version. This library is distributed in the hope that it will be useful, -- 
  10. -- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- -- 
  11. -- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.                            -- 
  12. --                                                                          -- 
  13. -- As a special exception under Section 7 of GPL version 3, you are granted -- 
  14. -- additional permissions described in the GCC Runtime Library Exception,   -- 
  15. -- version 3.1, as published by the Free Software Foundation.               -- 
  16. --                                                                          -- 
  17. -- You should have received a copy of the GNU General Public License and    -- 
  18. -- a copy of the GCC Runtime Library Exception along with this program;     -- 
  19. -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    -- 
  20. -- <http://www.gnu.org/licenses/>.                                          -- 
  21. --                                                                          -- 
  22. ------------------------------------------------------------------------------ 
  23.  
  24. --  <description> 
  25. --  Gtk.File_Chooser_Dialog.Gtk_File_Chooser_Dialog is a dialog box suitable 
  26. --  for use with "File/Open" or "File/Save as" commands. This widget works by 
  27. --  putting a Gtk.File_Chooser_Widget.Gtk_File_Chooser_Widget inside a 
  28. --  Gtk.Dialog.Gtk_Dialog. It exposes the Gtk.File_Chooser.Gtk_File_Chooser 
  29. --  interface, so you can use all of the Gtk.File_Chooser.Gtk_File_Chooser 
  30. --  functions on the file chooser dialog as well as those for 
  31. --  Gtk.Dialog.Gtk_Dialog. 
  32. -- 
  33. --  Note that Gtk.File_Chooser_Dialog.Gtk_File_Chooser_Dialog does not have 
  34. --  any methods of its own. Instead, you should use the functions that work on 
  35. --  a Gtk.File_Chooser.Gtk_File_Chooser. 
  36. -- 
  37. --  <example id="gtkfilechooser-typical-usage"> 
  38. --  == Typical usage == 
  39. -- 
  40. --  In the simplest of cases, you can the following code to use 
  41. --  Gtk.File_Chooser_Dialog.Gtk_File_Chooser_Dialog to select a file for 
  42. --  opening: 
  43. -- 
  44. --    GtkWidget *dialog; 
  45. --    dialog = gtk_file_chooser_dialog_new ("Open File", 
  46. --       parent_window, 
  47. --       GTK_FILE_CHOOSER_ACTION_OPEN, 
  48. --       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, 
  49. --       GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, 
  50. --       NULL); 
  51. --    if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) 
  52. --    { 
  53. --       char *filename; 
  54. --       filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); 
  55. --       open_file (filename); 
  56. --       g_free (filename); 
  57. --    } 
  58. --    gtk_widget_destroy (dialog); 
  59. -- 
  60. --  To use a dialog for saving, you can use this: 
  61. -- 
  62. --    GtkWidget *dialog; 
  63. --    dialog = gtk_file_chooser_dialog_new ("Save File", 
  64. --       parent_window, 
  65. --       GTK_FILE_CHOOSER_ACTION_SAVE, 
  66. --       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, 
  67. --       GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, 
  68. --       NULL); 
  69. --    gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE); 
  70. --    if (user_edited_a_new_document) 
  71. --    gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), "Untitled document"); 
  72. -- else 
  73. --    gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), filename_for_existing_document); 
  74. --    if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) 
  75. --    { 
  76. --       char *filename; 
  77. --       filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); 
  78. --       save_to_file (filename); 
  79. --       g_free (filename); 
  80. --    } 
  81. --    gtk_widget_destroy (dialog); 
  82. -- 
  83. --  <section id="gtkfilechooserdialog-setting-up"> 
  84. --  == Setting up a file chooser dialog == 
  85. -- 
  86. --  There are various cases in which you may need to use a 
  87. --  Gtk.File_Chooser_Dialog.Gtk_File_Chooser_Dialog: 
  88. -- 
  89. --     * To select a file for opening, as for a 
  90. --  <guimenuitem>File/Open</guimenuitem> command. Use 
  91. --  GTK_FILE_CHOOSER_ACTION_OPEN. 
  92. -- 
  93. --     * To save a file for the first time, as for a 
  94. --  <guimenuitem>File/Save</guimenuitem> command. Use 
  95. --  GTK_FILE_CHOOSER_ACTION_SAVE, and suggest a name such as "Untitled" with 
  96. --  Gtk.File_Chooser.Set_Current_Name. 
  97. -- 
  98. --     * To save a file under a different name, as for a 
  99. --  <guimenuitem>File/Save As</guimenuitem> command. Use 
  100. --  GTK_FILE_CHOOSER_ACTION_SAVE, and set the existing filename with 
  101. --  Gtk.File_Chooser.Set_Filename. 
  102. -- 
  103. --     * To choose a folder instead of a file. Use 
  104. --  GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER. 
  105. -- 
  106. --  Note: 
  107. -- 
  108. --  Old versions of the file chooser's documentation suggested using 
  109. --  Gtk.File_Chooser.Set_Current_Folder in various situations, with the 
  110. --  intention of letting the application suggest a reasonable default folder. 
  111. --  This is no longer considered to be a good policy, as now the file chooser 
  112. --  is able to make good suggestions on its own. In general, you should only 
  113. --  cause the file chooser to show a specific folder when it is appropriate to 
  114. --  use Gtk.File_Chooser.Set_Filename, i.e. when you are doing a 
  115. --  <guimenuitem>File/Save As</guimenuitem> command *and* you already have a 
  116. --  file saved somewhere. 
  117. -- 
  118. --  </section> <section id="gtkfilechooserdialog-response-codes"> 
  119. --  == Response Codes == 
  120. -- 
  121. --  Gtk.File_Chooser_Dialog.Gtk_File_Chooser_Dialog inherits from 
  122. --  Gtk.Dialog.Gtk_Dialog, so buttons that go in its action area have response 
  123. --  codes such as GTK_RESPONSE_ACCEPT and GTK_RESPONSE_CANCEL. For example, you 
  124. --  could call Gtk_New as follows: 
  125. -- 
  126. --    GtkWidget *dialog; 
  127. --    dialog = gtk_file_chooser_dialog_new ("Open File", 
  128. --       parent_window, 
  129. --       GTK_FILE_CHOOSER_ACTION_OPEN, 
  130. --       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, 
  131. --       GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, 
  132. --       NULL); 
  133. -- 
  134. --  This will create buttons for "Cancel" and "Open" that use stock response 
  135. --  identifiers from Gtk_Response_Type. For most dialog boxes you can use your 
  136. --  own custom response codes rather than the ones in Gtk_Response_Type, but 
  137. --  Gtk.File_Chooser_Dialog.Gtk_File_Chooser_Dialog assumes that its 
  138. --  "accept"-type action, e.g. an "Open" or "Save" button, *will* have one of 
  139. --  the following response codes: 
  140. -- 
  141. --  <simplelist id="gtkfilechooserdialog-responses"> 
  142. --  <member>GTK_RESPONSE_ACCEPT</member> <member>GTK_RESPONSE_OK</member> 
  143. --  <member>GTK_RESPONSE_YES</member> <member>GTK_RESPONSE_APPLY</member> 
  144. --  </simplelist> 
  145. --  This is because Gtk.File_Chooser_Dialog.Gtk_File_Chooser_Dialog must 
  146. --  intercept responses and switch to folders if appropriate, rather than 
  147. --  letting the dialog terminate &mdash; the implementation uses these known 
  148. --  response codes to know which responses can be blocked if appropriate. 
  149. -- 
  150. --  Note: To summarize, make sure you use a <link 
  151. --  linkend="gtkfilechooserdialog-responses">stock response code</link> when 
  152. --  you use Gtk.File_Chooser_Dialog.Gtk_File_Chooser_Dialog to ensure proper 
  153. --  operation. 
  154. -- 
  155. --  </section> 
  156. --  </description> 
  157. pragma Ada_2005; 
  158.  
  159. pragma Warnings (Off, "*is already use-visible*"); 
  160. with Glib;             use Glib; 
  161. with Glib.Object;      use Glib.Object; 
  162. with Glib.Types;       use Glib.Types; 
  163. with Gtk.Buildable;    use Gtk.Buildable; 
  164. with Gtk.Dialog;       use Gtk.Dialog; 
  165. with Gtk.Enums;        use Gtk.Enums; 
  166. with Gtk.File_Chooser; use Gtk.File_Chooser; 
  167. with Gtk.File_Filter;  use Gtk.File_Filter; 
  168. with Gtk.Widget;       use Gtk.Widget; 
  169. with Gtk.Window;       use Gtk.Window; 
  170.  
  171. package Gtk.File_Chooser_Dialog is 
  172.  
  173.    type Gtk_File_Chooser_Dialog_Record is new Gtk_Dialog_Record with null record; 
  174.    type Gtk_File_Chooser_Dialog is access all Gtk_File_Chooser_Dialog_Record'Class; 
  175.  
  176.    ------------------ 
  177.    -- Constructors -- 
  178.    ------------------ 
  179.  
  180.    procedure Gtk_New 
  181.       (Dialog : out Gtk_File_Chooser_Dialog; 
  182.        Title  : UTF8_String := ""; 
  183.        Parent : access Gtk.Window.Gtk_Window_Record'Class; 
  184.        Action : Gtk.File_Chooser.Gtk_File_Chooser_Action); 
  185.    procedure Initialize 
  186.       (Dialog : not null access Gtk_File_Chooser_Dialog_Record'Class; 
  187.        Title  : UTF8_String := ""; 
  188.        Parent : access Gtk.Window.Gtk_Window_Record'Class; 
  189.        Action : Gtk.File_Chooser.Gtk_File_Chooser_Action); 
  190.    --  Creates a new Gtk.File_Chooser_Dialog.Gtk_File_Chooser_Dialog. This 
  191.    --  function is analogous to gtk_dialog_new_with_buttons. 
  192.    --  Since: gtk+ 2.4 
  193.    --  "title": Title of the dialog, or null 
  194.    --  "parent": Transient parent of the dialog, or null 
  195.    --  "action": Open or save mode for the dialog 
  196.  
  197.    function Gtk_File_Chooser_Dialog_New 
  198.       (Title  : UTF8_String := ""; 
  199.        Parent : access Gtk.Window.Gtk_Window_Record'Class; 
  200.        Action : Gtk.File_Chooser.Gtk_File_Chooser_Action) 
  201.        return Gtk_File_Chooser_Dialog; 
  202.    --  Creates a new Gtk.File_Chooser_Dialog.Gtk_File_Chooser_Dialog. This 
  203.    --  function is analogous to gtk_dialog_new_with_buttons. 
  204.    --  Since: gtk+ 2.4 
  205.    --  "title": Title of the dialog, or null 
  206.    --  "parent": Transient parent of the dialog, or null 
  207.    --  "action": Open or save mode for the dialog 
  208.  
  209.    function Get_Type return Glib.GType; 
  210.    pragma Import (C, Get_Type, "gtk_file_chooser_dialog_get_type"); 
  211.  
  212.    --------------------------------------------- 
  213.    -- Inherited subprograms (from interfaces) -- 
  214.    --------------------------------------------- 
  215.    --  Methods inherited from the Buildable interface are not duplicated here 
  216.    --  since they are meant to be used by tools, mostly. If you need to call 
  217.    --  them, use an explicit cast through the "-" operator below. 
  218.  
  219.    procedure Add_Filter 
  220.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record; 
  221.        Filter  : not null access Gtk.File_Filter.Gtk_File_Filter_Record'Class); 
  222.  
  223.    function Add_Shortcut_Folder 
  224.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record; 
  225.        Folder  : UTF8_String) return Boolean; 
  226.  
  227.    function Add_Shortcut_Folder_Uri 
  228.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record; 
  229.        URI     : UTF8_String) return Boolean; 
  230.  
  231.    function Get_Action 
  232.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record) 
  233.        return Gtk.File_Chooser.Gtk_File_Chooser_Action; 
  234.  
  235.    procedure Set_Action 
  236.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record; 
  237.        Action  : Gtk.File_Chooser.Gtk_File_Chooser_Action); 
  238.  
  239.    function Get_Create_Folders 
  240.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record) 
  241.        return Boolean; 
  242.  
  243.    procedure Set_Create_Folders 
  244.       (Chooser        : not null access Gtk_File_Chooser_Dialog_Record; 
  245.        Create_Folders : Boolean); 
  246.  
  247.    function Get_Current_Folder 
  248.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record) 
  249.        return UTF8_String; 
  250.  
  251.    function Set_Current_Folder 
  252.       (Chooser  : not null access Gtk_File_Chooser_Dialog_Record; 
  253.        Filename : UTF8_String) return Boolean; 
  254.  
  255.    function Get_Current_Folder_Uri 
  256.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record) 
  257.        return UTF8_String; 
  258.  
  259.    function Set_Current_Folder_Uri 
  260.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record; 
  261.        URI     : UTF8_String) return Boolean; 
  262.  
  263.    function Get_Do_Overwrite_Confirmation 
  264.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record) 
  265.        return Boolean; 
  266.  
  267.    procedure Set_Do_Overwrite_Confirmation 
  268.       (Chooser                   : not null access Gtk_File_Chooser_Dialog_Record; 
  269.        Do_Overwrite_Confirmation : Boolean); 
  270.  
  271.    function Get_Extra_Widget 
  272.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record) 
  273.        return Gtk.Widget.Gtk_Widget; 
  274.  
  275.    procedure Set_Extra_Widget 
  276.       (Chooser      : not null access Gtk_File_Chooser_Dialog_Record; 
  277.        Extra_Widget : not null access Gtk.Widget.Gtk_Widget_Record'Class); 
  278.  
  279.    function Get_Filename 
  280.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record) 
  281.        return UTF8_String; 
  282.  
  283.    function Set_Filename 
  284.       (Chooser  : not null access Gtk_File_Chooser_Dialog_Record; 
  285.        Filename : UTF8_String) return Boolean; 
  286.  
  287.    function Get_Filenames 
  288.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record) 
  289.        return Gtk.Enums.String_SList.GSlist; 
  290.  
  291.    function Get_Filter 
  292.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record) 
  293.        return Gtk.File_Filter.Gtk_File_Filter; 
  294.  
  295.    procedure Set_Filter 
  296.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record; 
  297.        Filter  : not null access Gtk.File_Filter.Gtk_File_Filter_Record'Class); 
  298.  
  299.    function Get_Local_Only 
  300.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record) 
  301.        return Boolean; 
  302.  
  303.    procedure Set_Local_Only 
  304.       (Chooser    : not null access Gtk_File_Chooser_Dialog_Record; 
  305.        Local_Only : Boolean); 
  306.  
  307.    function Get_Preview_Filename 
  308.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record) 
  309.        return UTF8_String; 
  310.  
  311.    function Get_Preview_Uri 
  312.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record) 
  313.        return UTF8_String; 
  314.  
  315.    function Get_Preview_Widget 
  316.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record) 
  317.        return Gtk.Widget.Gtk_Widget; 
  318.  
  319.    procedure Set_Preview_Widget 
  320.       (Chooser        : not null access Gtk_File_Chooser_Dialog_Record; 
  321.        Preview_Widget : not null access Gtk.Widget.Gtk_Widget_Record'Class); 
  322.  
  323.    function Get_Preview_Widget_Active 
  324.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record) 
  325.        return Boolean; 
  326.  
  327.    procedure Set_Preview_Widget_Active 
  328.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record; 
  329.        Active  : Boolean); 
  330.  
  331.    function Get_Select_Multiple 
  332.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record) 
  333.        return Boolean; 
  334.  
  335.    procedure Set_Select_Multiple 
  336.       (Chooser         : not null access Gtk_File_Chooser_Dialog_Record; 
  337.        Select_Multiple : Boolean); 
  338.  
  339.    function Get_Show_Hidden 
  340.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record) 
  341.        return Boolean; 
  342.  
  343.    procedure Set_Show_Hidden 
  344.       (Chooser     : not null access Gtk_File_Chooser_Dialog_Record; 
  345.        Show_Hidden : Boolean); 
  346.  
  347.    function Get_Uri 
  348.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record) 
  349.        return UTF8_String; 
  350.  
  351.    function Set_Uri 
  352.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record; 
  353.        URI     : UTF8_String) return Boolean; 
  354.  
  355.    function Get_Uris 
  356.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record) 
  357.        return Gtk.Enums.String_SList.GSlist; 
  358.  
  359.    function Get_Use_Preview_Label 
  360.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record) 
  361.        return Boolean; 
  362.  
  363.    procedure Set_Use_Preview_Label 
  364.       (Chooser   : not null access Gtk_File_Chooser_Dialog_Record; 
  365.        Use_Label : Boolean); 
  366.  
  367.    function List_Filters 
  368.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record) 
  369.        return Glib.Object.Object_List.GSlist; 
  370.  
  371.    function List_Shortcut_Folder_Uris 
  372.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record) 
  373.        return Gtk.Enums.String_SList.GSlist; 
  374.  
  375.    function List_Shortcut_Folders 
  376.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record) 
  377.        return Gtk.Enums.String_SList.GSlist; 
  378.  
  379.    procedure Remove_Filter 
  380.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record; 
  381.        Filter  : not null access Gtk.File_Filter.Gtk_File_Filter_Record'Class); 
  382.  
  383.    function Remove_Shortcut_Folder 
  384.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record; 
  385.        Folder  : UTF8_String) return Boolean; 
  386.  
  387.    function Remove_Shortcut_Folder_Uri 
  388.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record; 
  389.        URI     : UTF8_String) return Boolean; 
  390.  
  391.    procedure Select_All 
  392.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record); 
  393.  
  394.    function Select_Filename 
  395.       (Chooser  : not null access Gtk_File_Chooser_Dialog_Record; 
  396.        Filename : UTF8_String) return Boolean; 
  397.  
  398.    function Select_Uri 
  399.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record; 
  400.        URI     : UTF8_String) return Boolean; 
  401.  
  402.    procedure Set_Current_Name 
  403.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record; 
  404.        Name    : UTF8_String); 
  405.  
  406.    procedure Unselect_All 
  407.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record); 
  408.  
  409.    procedure Unselect_Filename 
  410.       (Chooser  : not null access Gtk_File_Chooser_Dialog_Record; 
  411.        Filename : UTF8_String); 
  412.  
  413.    procedure Unselect_Uri 
  414.       (Chooser : not null access Gtk_File_Chooser_Dialog_Record; 
  415.        URI     : UTF8_String); 
  416.  
  417.    ---------------- 
  418.    -- Interfaces -- 
  419.    ---------------- 
  420.    --  This class implements several interfaces. See Glib.Types 
  421.    -- 
  422.    --  - "Buildable" 
  423.    -- 
  424.    --  - "FileChooser" 
  425.  
  426.    package Implements_Gtk_Buildable is new Glib.Types.Implements 
  427.      (Gtk.Buildable.Gtk_Buildable, Gtk_File_Chooser_Dialog_Record, Gtk_File_Chooser_Dialog); 
  428.    function "+" 
  429.      (Widget : access Gtk_File_Chooser_Dialog_Record'Class) 
  430.    return Gtk.Buildable.Gtk_Buildable 
  431.    renames Implements_Gtk_Buildable.To_Interface; 
  432.    function "-" 
  433.      (Interf : Gtk.Buildable.Gtk_Buildable) 
  434.    return Gtk_File_Chooser_Dialog 
  435.    renames Implements_Gtk_Buildable.To_Object; 
  436.  
  437.    package Implements_Gtk_File_Chooser is new Glib.Types.Implements 
  438.      (Gtk.File_Chooser.Gtk_File_Chooser, Gtk_File_Chooser_Dialog_Record, Gtk_File_Chooser_Dialog); 
  439.    function "+" 
  440.      (Widget : access Gtk_File_Chooser_Dialog_Record'Class) 
  441.    return Gtk.File_Chooser.Gtk_File_Chooser 
  442.    renames Implements_Gtk_File_Chooser.To_Interface; 
  443.    function "-" 
  444.      (Interf : Gtk.File_Chooser.Gtk_File_Chooser) 
  445.    return Gtk_File_Chooser_Dialog 
  446.    renames Implements_Gtk_File_Chooser.To_Object; 
  447.  
  448. end Gtk.File_Chooser_Dialog;