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