1. ----------------------------------------------------------------------- 
  2. --               GtkAda - Ada95 binding for Gtk+/Gnome               -- 
  3. --                                                                   -- 
  4. --   Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet   -- 
  5. --                Copyright (C) 2000-2006 AdaCore                    -- 
  6. --                                                                   -- 
  7. -- This library is free software; you can redistribute it and/or     -- 
  8. -- modify it under the terms of the GNU General Public               -- 
  9. -- License as published by the Free Software Foundation; either      -- 
  10. -- version 2 of the License, or (at your option) any later version.  -- 
  11. --                                                                   -- 
  12. -- This library is distributed in the hope that it will be useful,   -- 
  13. -- but WITHOUT ANY WARRANTY; without even the implied warranty of    -- 
  14. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -- 
  15. -- General Public License for more details.                          -- 
  16. --                                                                   -- 
  17. -- You should have received a copy of the GNU General Public         -- 
  18. -- License along with this library; if not, write to the             -- 
  19. -- Free Software Foundation, Inc., 59 Temple Place - Suite 330,      -- 
  20. -- Boston, MA 02111-1307, USA.                                       -- 
  21. --                                                                   -- 
  22. -- As a special exception, if other files instantiate generics from  -- 
  23. -- this unit, or you link this unit with other files to produce an   -- 
  24. -- executable, this  unit  does not  by itself cause  the resulting  -- 
  25. -- executable to be covered by the GNU General Public License. This  -- 
  26. -- exception does not however invalidate any other reasons why the   -- 
  27. -- executable file  might be covered by the  GNU Public License.     -- 
  28. ----------------------------------------------------------------------- 
  29.  
  30. --  <description> 
  31. --  A Gtk_File_Selection is a general widget to interactively select file. 
  32. --  It displays a dialog in which the user can navigate through directories, 
  33. --  select a file, and even manipulate files with operations like removing, 
  34. --  renaming,... 
  35. --  Currently, only one file can be selected in the dialog. 
  36. --  </description> 
  37. --  <c_version>2.8.17</c_version> 
  38. --  <group>Selectors</group> 
  39. --  <testgtk>create_file_selection.adb</testgtk> 
  40. --  <screenshot>gtk-file_selection</screenshot> 
  41.  
  42. with Glib.Properties; 
  43. with Gtk.Box; 
  44. with Gtk.Button; 
  45. with Gtk.Widget; 
  46. with Gtk.Dialog; 
  47. with GNAT.Strings; 
  48.  
  49. package Gtk.File_Selection is 
  50.  
  51.    type Gtk_File_Selection_Record is new 
  52.      Gtk.Dialog.Gtk_Dialog_Record with private; 
  53.    type Gtk_File_Selection is access all Gtk_File_Selection_Record'Class; 
  54.  
  55.    ------------------------------ 
  56.    -- Operations on the dialog -- 
  57.    ------------------------------ 
  58.  
  59.    procedure Gtk_New 
  60.      (File_Selection : out Gtk_File_Selection; Title : UTF8_String); 
  61.    procedure Initialize 
  62.      (File_Selection : access Gtk_File_Selection_Record'Class; 
  63.       Title          : UTF8_String); 
  64.    --  Creates or initializes a new file selection dialog. 
  65.    --  Title is the name of the dialog, as displayed in its title bar. 
  66.  
  67.    function Get_Type return Gtk.Gtk_Type; 
  68.    --  Return the internal value associated with a Gtk_File_Selection. 
  69.  
  70.    procedure Set_Filename 
  71.      (File_Selection : access Gtk_File_Selection_Record; 
  72.       Filename       : UTF8_String); 
  73.    function Get_Filename 
  74.      (File_Selection : access Gtk_File_Selection_Record) return UTF8_String; 
  75.    --  Highlight the given file in the dialog. 
  76.    --  Note that this does not close the dialog. 
  77.    --  You can also use this procedure to select the directory to be displayed 
  78.    --  in the dialog. Along with Complete, this allows you to set some filters 
  79.    --  in the dialog. 
  80.  
  81.    function Get_Selections 
  82.      (Filesel : access Gtk_File_Selection_Record) 
  83.       return GNAT.Strings.String_List; 
  84.    --  Retrieves the list of file selections the user has made in the dialog 
  85.    --  box. This function is intended for use when the user can select multiple 
  86.    --  files in the file list. 
  87.    --  The filenames are in the GLib file name encoding. To convert to UTF-8, 
  88.    --  call g_filename_to_utf8() on each string. 
  89.    --  The returned value must be freed by the caller 
  90.  
  91.    procedure Complete 
  92.      (File_Selection : access Gtk_File_Selection_Record; 
  93.       Pattern        : UTF8_String); 
  94.    --  Set the filter used to display the files. 
  95.    --  The pattern is displayed in the entry at the bottom of the dialog, and 
  96.    --  the list of files displayed in the list. 
  97.  
  98.    procedure Show_Fileop_Buttons 
  99.      (File_Selection : access Gtk_File_Selection_Record); 
  100.    procedure Hide_Fileop_Buttons 
  101.      (File_Selection : access Gtk_File_Selection_Record); 
  102.    --  When this function is called, the dialog includes a series of buttons 
  103.    --  for file operations (create directory, rename a file, delete a file). 
  104.  
  105.    procedure Set_Show_File_Op_Buttons 
  106.      (File_Selection : access Gtk_File_Selection_Record; 
  107.       Flag           : Boolean); 
  108.    --  Choose whether to display or not the file operation buttons. 
  109.    --  If Flag is true, calls Show_Fileop_Buttons, otherwise calls 
  110.    --  Hide_Fileop_Buttons. 
  111.  
  112.    procedure Set_Select_Multiple 
  113.      (Filesel         : access Gtk_File_Selection_Record; 
  114.       Select_Multiple : Boolean); 
  115.    function Get_Select_Multiple 
  116.      (Filesel : access Gtk_File_Selection_Record) 
  117.       return Boolean; 
  118.    --  Sets whether the user is allowed to select multiple files in the file 
  119.    --  list. 
  120.    --  Use Get_selections to get the list of selected files. 
  121.  
  122.    ------------------------ 
  123.    -- Getting the fields -- 
  124.    ------------------------ 
  125.    --  The following functions are provided to access the fields of the 
  126.    --  file selection dialog. 
  127.    --  This dialog is divided into two main areas, the Action_Area which is 
  128.    --  the top part that contains the list of files, and the button area which 
  129.    --  is the bottom part that contains the OK and Cancel buttons. 
  130.  
  131.    function Get_Action_Area 
  132.      (File_Selection : access Gtk_File_Selection_Record) 
  133.       return Gtk.Box.Gtk_Box; 
  134.    --  Return the action area. 
  135.    --  This is the area that contains the list of files, the filter entry,etc. 
  136.  
  137.    function Get_Button_Area 
  138.      (File_Selection : access Gtk_File_Selection_Record) 
  139.       return Gtk.Box.Gtk_Box; 
  140.    --  Return the button area. 
  141.    --  This is the area that contains the OK and Cancel buttons. 
  142.  
  143.    function Get_Dir_List 
  144.      (File_Selection : access Gtk_File_Selection_Record) 
  145.       return Gtk.Widget.Gtk_Widget; 
  146.    --  Return the list that display the list of directories. 
  147.  
  148.    function Get_File_List 
  149.      (File_Selection : access Gtk_File_Selection_Record) 
  150.       return Gtk.Widget.Gtk_Widget; 
  151.    --  Return the list that display the list of files in the selected directory 
  152.  
  153.    function Get_Cancel_Button 
  154.      (File_Selection : access Gtk_File_Selection_Record) 
  155.       return Gtk.Button.Gtk_Button; 
  156.    --  Return the Cancel button. 
  157.    --  To remove this button from the dialog, call Hide on the return value. 
  158.    --  The callbacks on this button should simply close the dialog, but should 
  159.    --  ignore the file selected by the user. 
  160.  
  161.    function Get_Help_Button 
  162.      (File_Selection : access Gtk_File_Selection_Record) 
  163.       return Gtk.Button.Gtk_Button; 
  164.    --  Return the Help button. 
  165.    --  To remove this button from the dialog, call Hide on the return value. 
  166.    --  The callbacks on this button should display a new dialog that explain 
  167.    --  what file the user should select. 
  168.  
  169.    function Get_Ok_Button 
  170.      (File_Selection : access Gtk_File_Selection_Record) 
  171.       return Gtk.Button.Gtk_Button; 
  172.    --  Return the OK button. 
  173.    --  The callbacks on this button should close the dialog and do something 
  174.    --  with the file selected by the user. 
  175.  
  176.    function Get_History_Pulldown 
  177.      (File_Selection : access Gtk_File_Selection_Record) 
  178.       return Gtk.Widget.Gtk_Widget; 
  179.    --  Return the menu that display the history of directories 
  180.    --  for easy access by the user. 
  181.  
  182.    function Get_Selection_Entry 
  183.      (File_Selection : access Gtk_File_Selection_Record) 
  184.       return Gtk.Widget.Gtk_Widget; 
  185.    --  Return the entry used to set the filter on the list of directories. 
  186.    --  The simplest way to insert text in this entry is to use the 
  187.    --  Complete procedure above. 
  188.  
  189.    function Get_Selection_Text 
  190.      (File_Selection : access Gtk_File_Selection_Record) 
  191.       return Gtk.Widget.Gtk_Widget; 
  192.    --  Return the text displayed just above the Selection_Entry. 
  193.  
  194.    ---------------- 
  195.    -- Properties -- 
  196.    ---------------- 
  197.  
  198.    --  <properties> 
  199.    --  The following properties are defined for this widget. See 
  200.    --  Glib.Properties for more information on properties. 
  201.    -- 
  202.    --  Name:  Filename_Property 
  203.    --  Type:  UTF8_String 
  204.    --  Flags: read-write 
  205.    --  Descr: The currently selected filename. 
  206.    --  See also: Set_Filename and Get_Filename 
  207.    -- 
  208.    --  Name:  Show_Fileops_Property 
  209.    --  Type:  Boolean 
  210.    --  Flags: read-write 
  211.    --  Descr: Whether buttons for creating/manipulating files should 
  212.    --         be displayed. 
  213.    --  See also: Show_Fileop_Buttons and Hide_Fileop_Buttons 
  214.    -- 
  215.    --  Name:  Select_Multiple_Property 
  216.    --  Type:  Boolean 
  217.    --  Descr: Whether to allow multiple files to be selected 
  218.    -- 
  219.    --  </properties> 
  220.  
  221.    Filename_Property        : constant Glib.Properties.Property_String; 
  222.    Show_Fileops_Property    : constant Glib.Properties.Property_Boolean; 
  223.    Select_Multiple_Property : constant Glib.Properties.Property_Boolean; 
  224.  
  225.    ------------- 
  226.    -- Signals -- 
  227.    ------------- 
  228.  
  229.    --  <signals> 
  230.    --  The following new signals are defined for this widget: 
  231.    --  </signals> 
  232.  
  233. private 
  234.    type Gtk_File_Selection_Record is new 
  235.      Gtk.Dialog.Gtk_Dialog_Record with null record; 
  236.  
  237.    Filename_Property     : constant Glib.Properties.Property_String := 
  238.      Glib.Properties.Build ("filename"); 
  239.    Show_Fileops_Property : constant Glib.Properties.Property_Boolean := 
  240.      Glib.Properties.Build ("show_fileops"); 
  241.    Select_Multiple_Property : constant Glib.Properties.Property_Boolean := 
  242.      Glib.Properties.Build ("select-multiple"); 
  243.  
  244.    pragma Import (C, Get_Type, "gtk_file_selection_get_type"); 
  245. end Gtk.File_Selection;