/src/wrappers/gtk/library/gtk_file_selection.e

http://github.com/tybor/Liberty · Specman e · 226 lines · 80 code · 32 blank · 114 comment · 4 complexity · 77b5531b8a1170a513af5e1b695393ff MD5 · raw file

  1. indexing
  2. description: "GtkFileSelection: Prompt the user for a file or directory name."
  3. copyright: "[
  4. Copyright (C) 2007 Paolo Redaelli, GTK+ team
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public License
  7. as published by the Free Software Foundation; either version 2.1 of
  8. the License, or (at your option) any later version.
  9. This library is distributed in the hopeOA that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. 02110-1301 USA
  17. ]"
  18. wrapped_version: "2.10.6"
  19. class GTK_FILE_SELECTION
  20. -- GtkFileSelection has been superseded by the newer GtkFileChooser family
  21. -- of widgets.
  22. --
  23. -- GtkFileSelection should be used to retrieve file or directory names from
  24. -- the user. It will create a new dialog window containing a directory list,
  25. -- and a file list corresponding to the current working directory. The
  26. -- filesystem can be navigated using the directory list or the drop-down
  27. -- history menu. Alternatively, the TAB key can be used to navigate using
  28. -- filename completion - common in text based editors such as emacs and jed.
  29. -- File selection dialogs are created with a call to `make'.
  30. -- The default filename can be set using `set_filename' and the selected
  31. -- filename retrieved using `filename'.
  32. -- Use gtk_file_selection_complete() to display files and directories that
  33. -- match a given pattern. This can be used for example, to show only *.txt
  34. -- files, or only files beginning with gtk*.
  35. -- Simple file operations; create directory, delete file, and rename file,
  36. -- are available from buttons at the top of the dialog. These can be hidden
  37. -- using gtk_file_selection_hide_fileop_buttons() and shown again using
  38. -- gtk_file_selection_show_fileop_buttons().
  39. -- Example 1. Getting a filename from the user.
  40. --
  41. --
  42. -- /* The file selection widget and the string to store the chosen filename */
  43. --
  44. -- void store_filename (GtkWidget *widget, gpointer user_data) {
  45. -- GtkWidget *file_selector = GTK_WIDGET (user_data);
  46. -- const gchar *selected_filename;
  47. --
  48. -- selected_filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (file_selector));
  49. -- g_print ("Selected filename: %s\n", selected_filename);
  50. -- }
  51. --
  52. -- void create_file_selection (void) {
  53. --
  54. -- GtkWidget *file_selector;
  55. --
  56. -- /* Create the selector */
  57. --
  58. -- file_selector = gtk_file_selection_new ("Please select a file for editing.");
  59. --
  60. -- g_signal_connect (GTK_FILE_SELECTION (file_selector)->ok_button,
  61. -- "clicked",
  62. -- G_CALLBACK (store_filename),
  63. -- file_selector);
  64. --
  65. -- /* Ensure that the dialog box is destroyed when the user clicks a button. */
  66. --
  67. -- g_signal_connect_swapped (GTK_FILE_SELECTION (file_selector)->ok_button,
  68. -- "clicked",
  69. -- G_CALLBACK (gtk_widget_destroy),
  70. -- file_selector);
  71. --
  72. -- g_signal_connect_swapped (GTK_FILE_SELECTION (file_selector)->cancel_button,
  73. -- "clicked",
  74. -- G_CALLBACK (gtk_widget_destroy),
  75. -- file_selector);
  76. --
  77. -- /* Display that dialog */
  78. --
  79. -- gtk_widget_show (file_selector);
  80. -- }
  81. obsolete
  82. "This class is deprecated and only here for compatibility. Use the %
  83. % GTK_FILE_CHOOSER family of widgets instead."
  84. inherit
  85. GTK_DIALOG
  86. undefine
  87. struct_size,
  88. get_action_area
  89. end
  90. -- GtkFileSelection implements AtkImplementorIface.
  91. insert
  92. GTK_FILE_SELECTION_EXTERNALS
  93. GTK_FILE_SELECTION_STRUCT
  94. undefine
  95. copy,
  96. is_equal
  97. end
  98. creation make, from_external_pointer
  99. feature {} -- Creation
  100. with_title (a_title: STRING) is
  101. -- Creates a new file selection dialog box. By default it will contain
  102. -- a GtkTreeView of the application's current working directory, and a
  103. -- file listing. Operation buttons that allow the user to create a
  104. -- directory, delete files and rename files, are also present.
  105. -- `a_title': a message that will be placed in the file requestor's
  106. -- titlebar.
  107. require title_not_void: a_title/=Void
  108. do
  109. from_external_pointer(gtk_file_selection_new(a_title.to_external))
  110. end
  111. feature
  112. set_filename (a_filename: STRING) is
  113. -- Sets a default path for the file requestor. If filename includes a
  114. -- directory path, then the requestor will open with that path as its
  115. -- current working directory.
  116. -- This has the consequence that in order to open the requestor with a
  117. -- working directory and an empty filename, filename must have a
  118. -- trailing directory separator.
  119. -- The encoding of filename is preferred GLib file name encoding, which
  120. -- may not be UTF-8. See g_filename_from_utf8().
  121. -- `a_filename': a string to set as the default file name.
  122. require filename_not_void: a_filename/=Void
  123. do
  124. gtk_file_selection_set_filename (handle, a_filename.to_external)
  125. end
  126. filename: CONST_STRING is
  127. -- the selected filename in the GLib file name encoding. To convert to
  128. -- UTF-8, call g_filename_to_utf8 (TODO: Eiffellize).
  129. -- If no file is selected then the selected directory path is returned.
  130. do
  131. -- The string returned gtk_file_selection_get_filename by points to a
  132. -- statically allocated buffer and should be copied if you plan to keep
  133. -- it around.
  134. create Result.from_external(gtk_file_selection_get_filename(handle))
  135. end
  136. complete (a_pattern: STRING) is
  137. -- Will attempt to match pattern to a valid filenames or subdirectories
  138. -- in the current directory. If a match can be made, the matched
  139. -- filename will appear in the text entry field of the file selection
  140. -- dialog. If a partial match can be made, the "Files" list will
  141. -- contain those file names which have been partially matched, and the
  142. -- "Folders" list those directories which have been partially matched.
  143. -- `a_pattern': a string of characters which may or may not match any
  144. -- filenames in the current directory.
  145. do
  146. gtk_file_selection_complete(handle, a_pattern.to_external)
  147. end
  148. show_fileop_buttons is
  149. -- Shows the file operation buttons, if they have previously been
  150. -- hidden. The rest of the widgets in the dialog will be resized
  151. -- accordingly.
  152. do
  153. gtk_file_selection_show_fileop_buttons(handle)
  154. end
  155. hide_fileop_buttons is
  156. -- Hides the file operation buttons that normally appear at the top of
  157. -- the dialog. Useful if you wish to create a custom file selector,
  158. -- based on GtkFileSelection.
  159. do
  160. gtk_file_selection_hide_fileop_buttons(handle)
  161. end
  162. selections: STRING_ARRAY is
  163. -- the list of file selections the user has made in the dialog box.
  164. -- This function is intended for use when the user can select multiple
  165. -- files in the file list.
  166. -- The filenames are in the GLib file name encoding. To convert to
  167. -- UTF-8, call g_filename_to_utf8 (TODO) on each string.
  168. local ptr: POINTER
  169. do
  170. ptr:=gtk_file_selection_get_selections(handle)
  171. create Result.from_external_null_array(ptr)
  172. -- Note: even if the C documentation says that the newly-allocated
  173. -- NULL-terminated array of strings returned by
  174. -- gtk_file_selection_get_selections must be freed with g_strfreev(),
  175. -- we will not do it; infact creating a STRING_ARRAY from the obtained
  176. -- pointer we pass the burden of memory handling to the garbage
  177. -- collector.
  178. end
  179. set_select_multiple (a_setting: BOOLEAN) is
  180. -- Sets whether the user is allowed to select multiple files in the
  181. -- file list. Use `selections' to get the list of selected files.
  182. do
  183. gtk_file_selection_set_select_multiple(handle,a_setting.to_integer)
  184. ensure set: a_setting = are_multiple_selection_allowed
  185. end
  186. are_multiple_selection_allowed: BOOLEAN is
  187. -- Is the user allowed to select multiple files in the file list?
  188. do
  189. Result:=gtk_file_selection_get_select_multiple(handle).to_boolean
  190. end
  191. -- Note: "filename", "select-multiple" and "show-fileops"
  192. -- properties already have strongly-typed setter and getter
  193. -- features, so they don't need to be wrapped.
  194. end -- class GTK_FILE_SELECTION