/src/wrappers/gtk/library/gtk_file_chooser.e

http://github.com/tybor/Liberty · Specman e · 1252 lines · 419 code · 224 blank · 609 comment · 12 complexity · 091f669a93c8761680968a04ddaeb48d MD5 · raw file

  1. indexing
  2. description: "GtkFileChooser -- File chooser interface used by GtkFileChooserWidget and GtkFileChooserDialog."
  3. copyright: "[
  4. Copyright (C) 2006 eiffel-libraries team, 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 hope 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. date: "$Date:$"
  19. revision: "$Revision:$"
  20. deferred class GTK_FILE_CHOOSER
  21. -- GtkFileChooser is an interface that can be implemented by file
  22. -- selection widgets. In GTK+, the main objects that implement this
  23. -- interface are GtkFileChooserWidget, GtkFileChooserDialog, and
  24. -- GtkFileChooserButton. You do not need to write an object that
  25. -- implements the GtkFileChooser interface unless you are trying to
  26. -- adapt an existing file selector to expose a standard programming
  27. -- interface.
  28. -- GtkFileChooser allows for shortcuts to various places in the
  29. -- filesystem. In the default implementation these are displayed in
  30. -- the left pane. It may be a bit confusing at first taht these
  31. -- shortcuts come from various sources and in various flavours, so
  32. -- lets explain the terminology here:
  33. -- Bookmarks are created by the user, by dragging folders from the
  34. -- right pane to the left pane, or by using the "Add". Bookmarks
  35. -- can be renamed and deleted by the user.
  36. -- Shortcuts can be provided by the application or by the
  37. -- underlying filesystem abstraction (e.g. both the gnome-vfs and
  38. -- the Windows filesystems provide "Desktop" shortcuts). Shortcuts
  39. -- cannot be modified by the user.
  40. -- Volumes are provided by the underlying filesystem
  41. -- abstraction. They are the "roots" of the filesystem.
  42. -- File Names and Encodings: When the user is finished selecting
  43. -- files in a GtkFileChooser, your program can get the selected
  44. -- names either as filenames or as URIs. For URIs, the normal
  45. -- escaping rules are applied if the URI contains non-ASCII
  46. -- characters. However, filenames are always returned in the
  47. -- character set specified by the G_FILENAME_ENCODING environment
  48. -- variable. Please see the Glib documentation for more details
  49. -- about this variable.
  50. -- Important: This means that while you can pass the result of
  51. -- gtk_file_chooser_get_filename() to open(2) or fopen(3), you may
  52. -- not be able to directly set it as the text of a GtkLabel widget
  53. -- unless you convert it first to UTF-8, which all GTK+ widgets
  54. -- expect. You should use g_filename_to_utf8() to convert filenames
  55. -- into strings that can be passed to GTK+ widgets.
  56. -- Adding a Preview Widget: You can add a custom preview widget to
  57. -- a file chooser and then get notification about when the preview
  58. -- needs to be updated. To install a preview widget, use
  59. -- gtk_file_chooser_set_preview_widget(). Then, connect to the
  60. -- GtkFileChooser::update-preview signal to get notified when you
  61. -- need to update the contents of the preview.
  62. -- Your callback should use gtk_file_chooser_get_preview_filename()
  63. -- to see what needs previewing. Once you have generated the
  64. -- preview for the corresponding file, you must call
  65. -- gtk_file_chooser_set_preview_widget_active() with a boolean flag
  66. -- that indicates whether your callback could successfully generate
  67. -- a preview.
  68. -- TODO: Eiffellize Example 2. Sample Usage
  69. -- {
  70. -- GtkImage *preview;
  71. -- ...
  72. -- preview = gtk_image_new ();
  73. -- gtk_file_chooser_set_preview_widget (my_file_chooser, preview);
  74. -- g_signal_connect (my_file_chooser, "update-preview",
  75. -- G_CALLBACK (update_preview_cb), preview);
  76. -- }
  77. -- static void
  78. -- update_preview_cb (GtkFileChooser *file_chooser, gpointer data)
  79. -- {
  80. -- GtkWidget *preview;
  81. -- char *filename;
  82. -- GdkPixbuf *pixbuf;
  83. -- gboolean have_preview;
  84. -- preview = GTK_WIDGET (data);
  85. -- filename = gtk_file_chooser_get_preview_filename (file_chooser);
  86. -- pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 128, 128, NULL);
  87. -- have_preview = (pixbuf != NULL);
  88. -- g_free (filename);
  89. -- gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf);
  90. -- if (pixbuf)
  91. -- gdk_pixbuf_unref (pixbuf);
  92. -- gtk_file_chooser_set_preview_widget_active (file_chooser, have_preview);
  93. -- }
  94. -- Adding Extra Widgets
  95. -- You can add extra widgets to a file chooser to provide options that are not present in the default design. For example, you can add a toggle button to give the user the option to open a file in read-only mode. You can use gtk_file_chooser_set_extra_widget() to insert additional widgets in a file chooser.
  96. -- TODO: Eiffelize Example 3. Sample Usage
  97. -- {
  98. -- GtkWidget *toggle;
  99. -- ...
  100. -- toggle = gtk_check_button_new_with_label ("Open file read-only");
  101. -- gtk_widget_show (toggle);
  102. -- gtk_file_chooser_set_extra_widget (my_file_chooser, toggle);
  103. -- }
  104. -- Note
  105. -- If you want to set more than one extra widget in the file chooser, you can a container such as a GtkVBox or a GtkTable and include your widgets in it. Then, set the container as the whole extra widget.
  106. -- Key Bindings
  107. -- Internally, GTK+ implements a file chooser's graphical user interface with the private GtkFileChooserDefaultClass. This widget has several key bindings and their associated signals. This section describes the available key binding signals.
  108. -- TODO: Eiffellize Example 4. GtkFileChooser key binding example
  109. -- The default keys that activate the key-binding signals in GtkFileChooserDefaultClass are as follows:
  110. -- Signal name Default key combinations
  111. -- location-popup Control-L; /
  112. -- up-folder Alt-Up[a] ; Backspace
  113. -- down-folder Alt-Down
  114. -- home-folder Alt-Home
  115. -- [a] Both the individual Up key and the numeric keypad's Up key are supported.
  116. -- You can change these defaults to something else. For example, to add a Shift modifier to a few of the default bindings, you can include the following fragment in your .gtkrc-2.0 file:
  117. -- binding "my-own-gtkfilechooser-bindings" {
  118. -- bind "<Alt><Shift>Up" {
  119. -- "up-folder" ()
  120. -- }
  121. -- bind "<Alt><Shift>Down" {
  122. -- "down-folder" ()
  123. -- }
  124. -- bind "<Alt><Shift>Home" {
  125. -- "home-folder" ()
  126. -- }
  127. -- }
  128. -- class "GtkFileChooserDefault" binding "my-own-gtkfilechooser-bindings"
  129. -- The "GtkFileChooserDefault::location-popup" signal
  130. -- void user_function (GtkFileChooserDefault
  131. -- *chooser, const char *path, gpointer user_data);
  132. -- This is used to make the file chooser show a "Location" dialog which the user can use to manually type the name of the file he wishes to select. The path argument is a string that gets put in the text entry for the file name. By default this is bound to Control-L with a path string of "" (the empty string); it is also bound to / with a path string of "/" (a slash): this lets you type / and immediately type a path name.
  133. -- chooser : the object which received the signal.
  134. -- path : default contents for the text entry for the file name
  135. -- user_data : user data set when the signal handler was connected.
  136. -- Tip
  137. -- You can create your own bindings for the location-popup
  138. -- signal with custom path strings, and have a crude form of
  139. -- easily-to-type bookmarks. For example, say you access the
  140. -- path /home/username/misc very frequently. You could then
  141. -- create an Alt-M shortcut by including the following in
  142. -- your .gtkrc-2.0:
  143. -- binding "misc-shortcut" {
  144. -- bind "<Alt>M" {
  145. -- "location-popup" ("/home/username/misc")
  146. -- }
  147. -- }
  148. -- class "GtkFileChooserDefault" binding "misc-shortcut"
  149. -- The "GtkFileChooserDefault::up-folder" signal
  150. -- void user_function (GtkFileChooserDefault
  151. -- *chooser, gpointer user_data);
  152. -- This is used to make the file chooser go to the parent of the current folder in the file hierarchy. By default this is bound to Backspace and Alt-Up (the Up key in the numeric keypad also works).
  153. -- chooser : the object which received the signal.
  154. -- user_data : user data set when the signal handler was connected.
  155. -- The "GtkFileChooserDefault::down-folder" signal
  156. -- void user_function (GtkFileChooserDefault *chooser,
  157. -- gpointer user_data);
  158. -- This is used to make the file chooser go to a child of the current folder in the file hierarchy. The subfolder that will be used is displayed in the path bar widget of the file chooser. For example, if the path bar is showing "/foo/bar/baz", then this will cause the file chooser to switch to the "baz" subfolder. By default this is bound to Alt-Down (the Down key in the numeric keypad also works).
  159. -- chooser : the object which received the signal.
  160. -- user_data : user data set when the signal handler was connected.
  161. -- The "GtkFileChooserDefault::home-folder" signal
  162. -- void user_function (GtkFileChooserDefault *chooser,
  163. -- gpointer user_data);
  164. -- This is used to make the file chooser show the user's home folder in the file list. By default this is bound to Alt-Home (the Home key in the numeric keypad also works).
  165. -- chooser : the object which received the signal.
  166. -- user_data : user data set when the signal handler was connected.
  167. inherit
  168. -- "Prerequisites: GtkFileChooser requires GtkWidget." IMHO this
  169. -- means that GTK_FILE_CHOOSER is a
  170. GTK_WIDGET
  171. -- Known Implementations: GtkFileChooser is implemented by
  172. -- GtkFileChooserWidget, GtkFileChooserButton and
  173. -- GtkFileChooserDialog.
  174. insert
  175. GTK_FILE_CHOOSER_EXTERNALS
  176. GTK_FILE_CHOOSER_CONFIRMATION
  177. GTK_FILE_CHOOSER_ERROR
  178. GTK_FILE_CHOOSER_ACTION
  179. -- Here this renaming is not useful; BTW, it produce incorrect code into GTK_FILE_CHOOSER's heirs
  180. -- rename
  181. -- gtk_file_chooser_action_open as open_action,
  182. -- gtk_file_chooser_action_save as save_action,
  183. -- gtk_file_chooser_action_select_folder as select_folder_action,
  184. -- gtk_file_chooser_action_create_folder as create_folder_action,
  185. -- is_valid_gtk_file_chooser_action as is_valid_gtk_action
  186. -- end
  187. feature -- Actions
  188. set_open_action is
  189. -- Set open mode. The file chooser will only let the user
  190. -- pick an existing file.
  191. do
  192. gtk_file_chooser_set_action (handle,gtk_file_chooser_action_open)
  193. end
  194. set_save_action is
  195. -- Set save mode. The file chooser will let the user pick an
  196. -- existing file, or type in a new filename.
  197. do
  198. gtk_file_chooser_set_action (handle,gtk_file_chooser_action_save)
  199. end
  200. set_select_folder_action is
  201. -- Select open mode for selecting folders. The file chooser
  202. -- will let the user pick an existing folder.
  203. do
  204. gtk_file_chooser_set_action (handle,gtk_file_chooser_action_select_folder)
  205. end
  206. set_create_folder_action is
  207. -- Select a mode to create a new folder. The file chooser
  208. -- will let the user name an existing or new folder.
  209. do
  210. gtk_file_chooser_set_action (handle,gtk_file_chooser_action_create_folder)
  211. end
  212. -- GETTERS
  213. is_action_open: BOOLEAN is
  214. -- Set open mode. The file chooser will only let the user
  215. -- pick an existing file.
  216. do
  217. Result := (gtk_file_chooser_get_action(handle)=gtk_file_chooser_action_open)
  218. end
  219. is_action_save: BOOLEAN is
  220. -- Set save mode. The file chooser will let the user pick an
  221. -- existing file, or type in a new filename.
  222. do
  223. Result := (gtk_file_chooser_get_action(handle)=gtk_file_chooser_action_save)
  224. end
  225. is_action_select_folder: BOOLEAN is
  226. -- Select open mode for selecting folders. The file chooser
  227. -- will let the user pick an existing folder.
  228. do
  229. Result := (gtk_file_chooser_get_action(handle)=gtk_file_chooser_action_select_folder)
  230. end
  231. is_action_create_folder: BOOLEAN is
  232. -- Select a mode to create a new folder. The file chooser
  233. -- will let the user name an existing or new folder.
  234. do
  235. Result := (gtk_file_chooser_get_action(handle)=gtk_file_chooser_action_create_folder)
  236. end
  237. feature -- Locality
  238. set_local_only is
  239. -- Makes only local files selectable in the file
  240. -- selector. The selected file are files are guaranteed to be
  241. -- accessible through the operating systems native file file
  242. -- system and therefore the application only needs to worry
  243. -- about the filename functions in GTK_FILE_CHOOSER, like
  244. -- GTK_FILE_CHOOSER.filename, rather than the URI functions
  245. -- like GTK_FILE_CHOOSER.uri
  246. do
  247. gtk_file_chooser_set_local_only (handle,1)
  248. ensure is_local_only
  249. end
  250. unset_local_only is
  251. -- Makes non-local files selectable in the file selector.
  252. do
  253. gtk_file_chooser_set_local_only (handle,0)
  254. ensure not is_local_only
  255. end
  256. is_local_only: BOOLEAN is
  257. -- Are only local files selectable in the file selector?. See `set_local_only'
  258. do
  259. Result:=(gtk_file_chooser_get_local_only (handle)).to_boolean
  260. end
  261. feature -- Multiple selections
  262. allow_multiple_selections is
  263. -- Makes multiple files selectable in the file selector. This
  264. -- is only relevant if `is_open_action' or
  265. -- `is_save_action'. It cannot be set with either of the
  266. -- folder actions (i.e.: if either `is_action_select_folder'
  267. -- or `is_action_create_folder' are True)
  268. require no_folder_actions: not (is_action_select_folder or is_action_create_folder)
  269. do
  270. gtk_file_chooser_set_select_multiple (handle, 1)
  271. ensure are_multiple_selection_allowed
  272. end
  273. forbid_multiple_selections is
  274. -- Makes multiple files not selectable in the file selector.
  275. do
  276. gtk_file_chooser_set_select_multiple (handle, 0)
  277. ensure not are_multiple_selection_allowed
  278. end
  279. are_multiple_selection_allowed: BOOLEAN is
  280. -- Are multiple files can be selected in the file selector?
  281. do
  282. Result := (gtk_file_chooser_get_select_multiple(handle)).to_boolean
  283. end
  284. feature -- Hidden files handling
  285. show_hidden is
  286. -- Make hidden files and folders displayed in the file
  287. -- selector.
  288. do
  289. gtk_file_chooser_set_show_hidden (handle,1)
  290. end
  291. hide_hidden is
  292. -- Make hidden files and folders not displayed in the file
  293. -- selector.
  294. do
  295. gtk_file_chooser_set_show_hidden (handle,0)
  296. end
  297. are_hidden_shown: BOOLEAN is
  298. -- Are hidden files and folders displayed in the file
  299. -- selector? See `GTK_FILE_CHOOSER.show_hidden'.
  300. do
  301. Result:=(gtk_file_chooser_get_show_hidden(handle)).to_boolean
  302. end
  303. feature -- Overwrite confirmation
  304. set_overwrite_confirmation is
  305. -- Makes a file chooser in GTK_FILE_CHOOSER_ACTION_SAVE mode
  306. -- present a confirmation dialog if the user types a file
  307. -- name that already exists. Regardless of this setting, the
  308. -- chooser will emit the "confirm-overwrite" signal when
  309. -- appropriate. If all you need is the stock confirmation
  310. -- dialog, set this property. You can override the way
  311. -- confirmation is done by actually handling the
  312. -- "confirm-overwrite" signal; please refer to its
  313. -- documentation for the details.
  314. do
  315. gtk_file_chooser_set_do_overwrite_confirmation (handle, 1)
  316. ensure shall_overwrite_be_confirmed
  317. end
  318. unset_overwrite_confirmation is
  319. -- Makes a file chooser in GTK_FILE_CHOOSER_ACTION_SAVE mode
  320. -- present a confirmation dialog if the user types a file
  321. -- name that already exists. Regardless of this setting, the
  322. -- chooser will emit the "confirm-overwrite" signal when
  323. -- appropriate. If all you need is the stock confirmation
  324. -- dialog, set this property. You can override the way
  325. -- confirmation is done by actually handling the
  326. -- "confirm-overwrite" signal; please refer to its
  327. -- documentation for the details.
  328. do
  329. gtk_file_chooser_set_do_overwrite_confirmation (handle, 0)
  330. ensure not shall_overwrite_be_confirmed
  331. end
  332. shall_overwrite_be_confirmed: BOOLEAN is
  333. -- Is a file chooser set to confirm for overwriting when the
  334. -- user types a file name that already exists? Note: this
  335. -- query wraps C's
  336. -- `gtk_file_chooser_get_do_overwrite_confirmation'
  337. do
  338. Result:=(gtk_file_chooser_get_do_overwrite_confirmation (handle)).to_boolean
  339. end
  340. feature -- Name, filenames and uris
  341. filename: STRING is
  342. -- The filename for the currently selected file in the file
  343. -- selector. If multiple files are selected, one of the
  344. -- filenames will be returned at random. If the file chooser
  345. -- is in folder mode, this function returns the selected
  346. -- folder.
  347. local ptr: POINTER
  348. do
  349. ptr := gtk_file_chooser_get_filename(handle)
  350. -- Returns : The currently selected filename, or NULL if no
  351. -- file is selected, or the selected file can't be
  352. -- represented with a local filename. Free with g_free().
  353. if ptr.is_not_null
  354. then create Result.from_external(ptr)
  355. -- else check Result=Void end
  356. end
  357. end
  358. set_current_name (a_name: STRING) is
  359. -- Sets the current name in the file selector, as if entered
  360. -- by the user. Note that the name passed in here is a UTF-8
  361. -- string rather than a filename. This function is meant for
  362. -- such uses as a suggested name in a "Save As..." dialog.
  363. -- If you want to preselect a particular existing file, you
  364. -- should use `GTK_FILE_CHOOSER.set_filename' or
  365. -- `GTK_FILE_CHOOSER.set_uri' instead. Please see the
  366. -- documentation for those functions for an example of using
  367. -- gtk_file_chooser_set_current_name() as well.
  368. -- TODO: `a_name' should be UNICODE_STRING: the filename to
  369. -- use, as a UTF-8 string
  370. require a_name /= Void
  371. do
  372. gtk_file_chooser_set_current_name (handle, a_name.to_external)
  373. end
  374. is_last_action_successful: BOOLEAN
  375. -- Returns : TRUE if both the folder could be changed and the file was selected successfully, FALSE otherwise.
  376. set_filename (a_filename: STRING) is
  377. -- Sets filename as the current filename for the file
  378. -- chooser, by changing to the file's parent folder and
  379. -- actually selecting the file in list. If the chooser is in
  380. -- GTK_FILE_CHOOSER_ACTION_SAVE mode, the file's base name
  381. -- will also appear in the dialog's file name entry.
  382. -- If the file name isn't in the current folder of chooser,
  383. -- then the current folder of chooser will be changed to the
  384. -- folder containing filename. This is equivalent to a
  385. -- sequence of `unselect_all' followed by `select_filename'.
  386. -- Note that the file must exist, or nothing will be done
  387. -- except for the directory change.
  388. -- If you are implementing a File/Save As... dialog, you
  389. -- should use this function if you already have a file name
  390. -- to which the user may save; for example, when the user
  391. -- opens an existing file and then does File/Save As... on
  392. -- it. If you don't have a file name already -- for example,
  393. -- if the user just created a new file and is saving it for
  394. -- the first time, do not call this function. Instead, use
  395. -- something similar to this: TODO Eiffelize this
  396. -- if (document_is_new) -- { /* the user just created a new
  397. -- document */ gtk_file_chooser_set_current_folder (chooser,
  398. -- default_folder_for_saving);
  399. -- gtk_file_chooser_set_current_name (chooser, "Untitled
  400. -- document"); -- } -- else -- { /* the user edited an
  401. -- existing document */ gtk_file_chooser_set_filename
  402. -- (chooser, existing_filename); -- }
  403. -- `is_last_action_successful' will be True if both the
  404. -- folder could be changed and the file was selected
  405. -- successfully, False otherwise.
  406. require valid_filename: a_filename/=Void
  407. do
  408. is_last_action_successful := (gtk_file_chooser_set_filename (handle, a_filename.to_external)).to_boolean
  409. end
  410. select_filename (a_filename: STRING) is
  411. -- Selects `a_filename'. If the file name isn't in the
  412. -- current folder of chooser, then the current folder of
  413. -- chooser will be changed to the folder containing filename.
  414. -- `is_last_action_successful' will be True if both the
  415. -- folder could be changed and the file was selected
  416. -- successfully, False otherwise.
  417. require valid_filename: a_filename/=Void
  418. do
  419. is_last_action_successful := (gtk_file_chooser_select_filename (handle, a_filename.to_external)).to_boolean
  420. end
  421. unselect_filename (a_filename: STRING) is
  422. -- Unselects a currently selected filename. If the `a_filename'
  423. -- is not in the current directory, does not exist, or is
  424. -- otherwise not currently selected, does nothing.
  425. require valid_filename: a_filename/=Void
  426. do
  427. gtk_file_chooser_unselect_filename (handle, a_filename.to_external)
  428. end
  429. select_all is
  430. -- Selects all the files in the current folder of a file
  431. -- chooser.
  432. do
  433. gtk_file_chooser_select_all (handle)
  434. end
  435. unselect_all is
  436. -- Unselects all the files in the current folder of a file
  437. -- chooser.
  438. do
  439. gtk_file_chooser_unselect_all (handle)
  440. end
  441. filenames: G_SLIST_STRING is
  442. -- all the selected files and subfolders in the current
  443. -- folder of chooser. The names are full absolute paths. If
  444. -- files in the current folder cannot be represented as local
  445. -- filenames they will be ignored. (See `uris')
  446. do
  447. create Result.from_external_pointer (gtk_file_chooser_get_filenames (handle))
  448. -- TODO: the GSList returned contains the filenames of all
  449. -- selected files and subfolders in the current folder. Free
  450. -- the returned list with g_slist_free(), and the filenames
  451. -- with g_free().
  452. end
  453. set_current_folder (a_folder_name: STRING) is
  454. -- Sets the current folder for chooser from a local
  455. -- filename. The user will be shown the full contents of the
  456. -- current folder, plus user interface elements for
  457. -- navigating to other folders. `a_folder_name' is the full
  458. -- path of the new current folder.
  459. -- `is_last_action_successful' will be True if both the
  460. -- folder could be changed and the file was selected
  461. -- successfully, False otherwise.
  462. require valid_folder_name: a_folder_name/=Void
  463. do
  464. is_last_action_successful := (gtk_file_chooser_set_current_folder(handle,
  465. a_folder_name.to_external)).to_boolean
  466. end
  467. current_folder: STRING is
  468. -- the current folder of chooser as a local filename. See
  469. -- `set_current_folder'. Void if the current path cannot be
  470. -- represented as a local filename
  471. local ptr: POINTER
  472. do
  473. ptr := gtk_file_chooser_get_current_folder (handle)
  474. -- ptr is the (gchar *) the full path of the current folder,
  475. -- or NULL if the current path cannot be represented as a
  476. -- local filename. Free with g_free().
  477. if ptr.is_not_null
  478. then create Result.from_external (ptr)
  479. --else check Result=Void end
  480. end
  481. end
  482. uri: STRING is
  483. -- the URI for the currently selected file in the file
  484. -- selector. If multiple files are selected, one of the
  485. -- filenames will be returned at random. If the file chooser
  486. -- is in folder mode, this function returns the selected
  487. -- folder. Void if no file is selected
  488. local ptr: POINTER
  489. do
  490. ptr := gtk_file_chooser_get_uri (handle)
  491. if ptr.is_not_null
  492. then create Result.from_external (ptr)
  493. --else check Result=Void end
  494. end
  495. end
  496. set_uri (an_uri: STRING) is
  497. -- Sets the file referred to by `an_uri' as the current file
  498. -- for the file chooser, by changing to the URI's parent
  499. -- folder and actually selecting the URI in the list. If the
  500. -- chooser `is_action_save' mode, the URI's base name will
  501. -- also appear in the dialog's file name entry.
  502. -- If `an_uri' isn't in the current folder of chooser, then
  503. -- the current folder of chooser will be changed to the
  504. -- folder containing uri. This is equivalent to a sequence of
  505. -- `unselect_all' followed by `select_uri'.
  506. -- Note that the URI must exist, or nothing will be done
  507. -- except for the directory change. If you are implementing a
  508. -- File/Save As... dialog, you should use this function if
  509. -- you already have a file name to which the user may save;
  510. -- for example, when the user opens an existing file and then
  511. -- does File/Save As... on it. If you don't have a file name
  512. -- already -- for example, if the user just created a new
  513. -- file and is saving it for the first time, do not call this
  514. -- function. Instead, use something similar to this:
  515. -- if (document_is_new) { /* the user just created a new
  516. -- document */ gtk_file_chooser_set_current_folder_uri
  517. -- (chooser, default_folder_for_saving);
  518. -- gtk_file_chooser_set_current_name (chooser, "Untitled
  519. -- document"); } else { /* the user edited an existing
  520. -- document */ gtk_file_chooser_set_uri (chooser,
  521. -- existing_uri); }
  522. -- `is_last_action_successful' will be True if both the
  523. -- folder could be changed and the file was selected
  524. -- successfully, False otherwise.
  525. require valid_uri: an_uri/=Void
  526. do
  527. is_last_action_successful := (gtk_file_chooser_set_uri (handle,an_uri.to_external)).to_boolean
  528. end
  529. select_uri (an_uri: STRING) is
  530. -- Selects the file to by `an_uri'. If `an_uri' doesn't refer
  531. -- to a file in the current folder of chooser, then the
  532. -- current folder of chooser will be changed to the folder
  533. -- containing filename.
  534. -- `is_last_action_successful' will be True if both the
  535. -- folder could be changed and the file was selected
  536. -- successfully, False otherwise.
  537. require valid_uri: an_uri/=Void
  538. do
  539. is_last_action_successful:=(gtk_file_chooser_select_uri(handle,an_uri.to_external)).to_boolean
  540. end
  541. unselect_uri (an_uri: STRING) is
  542. -- Unselects the file referred to by `an_uri'. If the file is
  543. -- not in the current directory, does not exist, or is
  544. -- otherwise not currently selected, does nothing.
  545. require valid_uri: an_uri/=Void
  546. do
  547. gtk_file_chooser_unselect_uri (handle, an_uri.to_external)
  548. end
  549. uris: G_SLIST_STRING is
  550. -- selected files and subfolders in the current folder of
  551. -- chooser. The names are full absolute URIs.
  552. do
  553. create Result.from_external_pointer (gtk_file_chooser_get_uris (handle))
  554. ensure uri_not_void: Result/=Void
  555. end
  556. set_current_folder_uri (an_uri: STRING) is
  557. -- Sets the current folder for chooser from `an_uri'. The user
  558. -- will be shown the full contents of the current folder, plus
  559. -- user interface elements for navigating to other folders.
  560. -- `is_last_action_successful' will be True if both the
  561. -- folder could be changed and the file was selected
  562. -- successfully, False otherwise.
  563. require valid_uri: an_uri /= Void
  564. do
  565. is_last_action_successful:=(gtk_file_chooser_set_current_folder_uri (handle, an_uri.to_external)).to_boolean
  566. end
  567. get_current_folder_uri: STRING is
  568. -- the current folder of chooser as an
  569. -- URI. `set_current_folder_uri'. Can be Void if the file
  570. -- chooser was unable to load the last folder that was
  571. -- requested from it; for example, as would be for calling
  572. -- `set_current_folder_uri' on a nonexistent folder.
  573. local ptr: POINTER
  574. do
  575. -- TODO: when creating a string shall we use from_external or from_external_copy
  576. ptr := gtk_file_chooser_get_current_folder_uri(handle)
  577. if ptr.is_not_null
  578. then create Result.from_external (ptr) -- TODO: this assumes that STRING calls g_free
  579. end
  580. end
  581. feature -- Preview
  582. set_preview_widget (a_widget: GTK_WIDGET) is
  583. -- Sets an application-supplied widget to use to display a
  584. -- custom preview of the currently selected file. To
  585. -- implement a preview, after setting the preview widget, you
  586. -- connect to the `::update-preview' signal, and call
  587. -- `preview_filename' or `preview_uri' on each change. If you
  588. -- can display a preview of the new file, update your widget
  589. -- and set the preview active using
  590. -- `set_preview_widget_active'. Otherwise, set the preview
  591. -- inactive.
  592. -- When there is no application-supplied preview widget, or
  593. -- the application-supplied preview widget is not active, the
  594. -- file chooser may display an internally generated preview
  595. -- of the current file or it may display no preview at all.
  596. require valid_widget: a_widget/=Void
  597. do
  598. gtk_file_chooser_set_preview_widget (handle, a_widget.handle)
  599. end
  600. preview_widget: GTK_WIDGET is
  601. -- the current preview widget; can be Void; see `set_preview_widget'.
  602. local factory: G_OBJECT_FACTORY [GTK_WIDGET]
  603. do
  604. Result := factory.wrapper_or_void (gtk_file_chooser_get_preview_widget(handle))
  605. end
  606. set_preview_widget_active is
  607. -- Show the preview widget set by `set_preview_widget'. See
  608. -- `set_preview_widget' for more details.
  609. do
  610. gtk_file_chooser_set_preview_widget_active (handle,1)
  611. end
  612. set_preview_widget_inactive is
  613. -- Hide the preview widget set by `set_preview_widget'. The
  614. -- file chooser may display an internally generated preview
  615. -- of the current file or it may display no preview at
  616. -- all. See `set_preview_widget' for more details.
  617. do
  618. gtk_file_chooser_set_preview_widget_active (handle,1)
  619. end
  620. is_preview_widget_active: BOOLEAN is
  621. -- Is the preview widget set by `set_preview_widget' shown
  622. -- for the current filename. See `set_preview_widget_active'.
  623. do
  624. Result:=(gtk_file_chooser_get_preview_widget_active(handle)).to_boolean
  625. end
  626. use_preview_label is
  627. -- Makes the file chooser display a stock label with the name
  628. -- of the file that is being previewed; the default is
  629. -- True. Applications that want to draw the whole preview
  630. -- area themselves should set this to False and display the
  631. -- name themselves in their preview widget.
  632. -- See also: `set_preview_widget'
  633. do
  634. gtk_file_chooser_set_use_preview_label (handle,1)
  635. ensure is_preview_label_used
  636. end
  637. use_no_preview_label is
  638. -- Remove from the file chooser the stock label with the name
  639. -- of the file that is being previewed; applications that want to draw the whole preview
  640. -- area themselves should call this feature and display the
  641. -- name themselves in their preview widget.
  642. -- See also: `set_preview_widget'
  643. do
  644. gtk_file_chooser_set_use_preview_label (handle,0)
  645. ensure not is_preview_label_used
  646. end
  647. is_preview_label_used: BOOLEAN is
  648. -- Is a stock label drawn with the name of the previewed
  649. -- file? See `use_preview_label'.
  650. do
  651. Result:=gtk_file_chooser_get_use_preview_label(handle).to_boolean
  652. end
  653. preview_filename: STRING is
  654. -- the filename that should be previewed in a custom preview
  655. -- widget. See `set_preview_widget'. Can be Void if no file
  656. -- is selected, or if the selected file cannot be represented
  657. -- as a local filename.
  658. local cstr: POINTER
  659. do
  660. cstr:=gtk_file_chooser_get_preview_filename (handle)
  661. if cstr.is_not_null then
  662. create Result.from_external (cstr)
  663. -- Free with g_free()
  664. end
  665. end
  666. preview_uri: STRING is
  667. -- the URI that should be previewed in a custom preview
  668. -- widget. See `set_preview_widget'. Can be Void if no file
  669. -- is selected.
  670. local cstr: POINTER
  671. do
  672. cstr:=gtk_file_chooser_get_preview_uri(handle)
  673. if cstr.is_not_null then
  674. create Result.from_external (cstr)
  675. -- TODO: Free with g_free()
  676. end
  677. end
  678. feature -- Extra widget
  679. set_extra_widget (a_widget: GTK_WIDGET) is
  680. -- Sets an application-supplied widget to provide extra
  681. -- options to the user.
  682. require valid_widget: a_widget/=Void
  683. do
  684. gtk_file_chooser_set_extra_widget (handle, a_widget.handle)
  685. end
  686. extra_widget: GTK_WIDGET is
  687. -- the current preview widget; see `set_extra_widget'. Can be Void
  688. local widget_ptr: POINTER
  689. do
  690. widget_ptr := gtk_file_chooser_get_extra_widget(handle)
  691. if widget_ptr.is_not_null
  692. then
  693. -- retrieve the Eiffel object stored as a pointer with the key `eiffel_key_label'
  694. not_yet_implemented
  695. end
  696. end
  697. feature -- Filters
  698. add_filter (a_filter: GTK_FILE_FILTER) is
  699. -- Adds `a_filter' to the list of filters that the user can
  700. -- select between. When a filter is selected, only files that
  701. -- are passed by that filter are displayed.
  702. -- TODO: Eiffelize this: Note that the chooser takes ownership of the filter, so
  703. -- you have to ref and sink it if you want to keep a
  704. -- reference.
  705. require valid_filter: a_filter /= Void
  706. do
  707. gtk_file_chooser_add_filter (handle, a_filter.handle)
  708. end
  709. remove_filter (a_filter: GTK_FILE_FILTER) is
  710. -- Removes `a_filter' from the list of filters that the user
  711. -- can select between.
  712. require valid_filter: a_filter /= Void
  713. do
  714. gtk_file_chooser_remove_filter (handle, a_filter.handle)
  715. end
  716. filters: G_SLIST [GTK_FILE_FILTER] is
  717. -- The current set of user-selectable filters; see `add_filter', `remove_filter'.
  718. do
  719. create {G_OBJECT_SLIST [GTK_FILE_FILTER]}
  720. Result.from_external_pointer (gtk_file_chooser_list_filters (handle))
  721. end
  722. set_filter (a_filter: GTK_FILE_FILTER) is
  723. -- Sets the current filter; only the files that pass the
  724. -- filter will be displayed. If the user-selectable list of
  725. -- filters is non-empty, then the filter should be one of the
  726. -- filters in that list. Setting the current filter when the
  727. -- list of filters is empty is useful if you want to restrict
  728. -- the displayed set of files without letting the user change
  729. -- it.
  730. require
  731. valid_filter: a_filter /= Void
  732. -- TODO: The following should implement the manifest
  733. -- precondition "If the user-selectable list of filters is
  734. -- non-empty, then the filter should be one of the filters in
  735. -- that list."
  736. filter_is_in_filters: (not filters.is_empty) implies filters.has (a_filter)
  737. do
  738. gtk_file_chooser_set_filter (handle, a_filter.handle)
  739. end
  740. filter: GTK_FILE_FILTER is
  741. -- The current filter; can be Void
  742. local filter_ptr: POINTER
  743. do
  744. filter_ptr := gtk_file_chooser_get_filter (handle)
  745. if filter_ptr.is_not_null
  746. then create Result.from_external_pointer (filter_ptr)
  747. end
  748. end
  749. feature -- Shortcuts folders
  750. add_shortcut_folder (a_folder: STRING) is
  751. -- Adds a folder to be displayed with the shortcut folders in
  752. -- a file chooser. Note that shortcut folders do not get
  753. -- saved, as they are provided by the application. For
  754. -- example, you can use this to add a
  755. -- "/usr/share/mydrawprogram/Clipart" folder to the volume
  756. -- list.
  757. -- `is_last_action_successful' will be True if both the
  758. -- folder could be changed and the file was selected
  759. -- successfully, False otherwise. In that case (TODO)
  760. -- `last_error' will be filled with the cause
  761. require valid_folder: a_folder /= Void
  762. do
  763. -- chooser : a GtkFileChooser
  764. -- folder : filename of the folder to add
  765. -- error : location to store error, or NULL
  766. -- Returns : TRUE if the folder could be added successfully, FALSE otherwise. In the latter case, the error will be set as appropriate.
  767. -- TODO: Create G_ERROR
  768. is_last_action_successful := gtk_file_chooser_add_shortcut_folder (handle,
  769. a_folder.to_external,
  770. default_pointer -- TODO: it will be last_error.handle when G_ERROR exists
  771. ).to_boolean
  772. end
  773. remove_shortcut_folder (a_folder: STRING) is
  774. -- Removes `a_folder' from a file chooser's list of shortcut
  775. -- folders.
  776. -- `is_last_action_successful' will be True if both the
  777. -- folder could be changed and the file was selected
  778. -- successfully, False otherwise. In that case (TODO)
  779. -- `last_error' will be filled with the cause
  780. require valid_folder: a_folder /= Void
  781. do
  782. is_last_action_successful := gtk_file_chooser_remove_shortcut_folder (handle,
  783. a_folder.to_external,
  784. default_pointer -- TODO: it will be last_error.handle when G_ERROR exists
  785. ).to_boolean
  786. end
  787. shortcut_folders: G_SLIST_STRING is
  788. -- The list of shortcut folders in the file chooser, as set
  789. -- by `add_shortcut_folder'.
  790. -- `is_last_action_successful' will be True if both the
  791. -- folder could be changed and the file was selected
  792. -- successfully, False otherwise. In that case (TODO)
  793. -- `last_error' will be filled with the cause
  794. local folders_ptr: POINTER
  795. do
  796. folders_ptr := gtk_file_chooser_list_shortcut_folders (handle)
  797. if folders_ptr.is_not_null
  798. then create Result.from_external_pointer (folders_ptr)
  799. -- TODO: handle this peculiar memory management: . Free
  800. -- the returned list with g_slist_free(), and the
  801. -- filenames with g_free().
  802. end
  803. end
  804. add_shortcut_folder_uri (an_uri: STRING) is
  805. -- Adds a folder URI to be displayed with the shortcut
  806. -- folders in a file chooser. Note that shortcut folders do
  807. -- not get saved, as they are provided by the
  808. -- application. For example, you can use this to add a
  809. -- "file:///usr/share/mydrawprogram/Clipart" folder to the
  810. -- volume list.
  811. -- `is_last_action_successful' will be True if both the
  812. -- folder could be changed and the file was selected
  813. -- successfully, False otherwise. In that case (TODO)
  814. -- `last_error' will be filled with the cause
  815. require valid_uri: an_uri /= Void
  816. do
  817. is_last_action_successful := ( gtk_file_chooser_add_shortcut_folder_uri
  818. (handle, an_uri.to_external,
  819. default_pointer -- TODO: it will be last_error.handle when G_ERROR exists
  820. ).to_boolean )
  821. end
  822. remove_shortcut_folder_uri (an_uri: STRING) is
  823. -- Removes a folder URI from a file chooser's list of
  824. -- shortcut folders.
  825. require valid_uri: an_uri /= Void
  826. do
  827. is_last_action_successful := ( gtk_file_chooser_remove_shortcut_folder_uri
  828. (handle, an_uri.to_external,
  829. default_pointer -- TODO: it will be last_error.handle when G_ERROR exists
  830. ).to_boolean )
  831. end
  832. shortcut_folder_uris: G_SLIST_STRING is
  833. -- The list of shortcut folders in the file chooser, as set by `add_shortcut_folder_uri'.
  834. local a_gslist: POINTER
  835. do
  836. a_gslist := gtk_file_chooser_list_shortcut_folder_uris (handle)
  837. if a_gslist.is_not_null
  838. then create Result.from_external_pointer (a_gslist)
  839. -- TODO: handle this peculiar memory management: Free the
  840. -- returned list with g_slist_free(), and the URIs with
  841. -- g_free().
  842. end
  843. end
  844. -- Property Details
  845. -- The "action" property
  846. -- "action" GtkFileChooserAction : Read / Write
  847. -- The type of operation that the file selector is performing.
  848. -- Default value: GTK_FILE_CHOOSER_ACTION_OPEN
  849. -- The "do-overwrite-confirmation" property
  850. -- "do-overwrite-confirmation" gboolean : Read / Write
  851. -- Whether a file chooser in GTK_FILE_CHOOSER_ACTION_SAVE will present an overwrite confirmation dialog if the user selects a file name that already exists.
  852. -- Default value: FALSE
  853. -- Since 2.8
  854. -- The "extra-widget" property
  855. -- "extra-widget" GtkWidget : Read / Write
  856. -- Application supplied widget for extra options.
  857. -- The "file-system-backend" property
  858. -- "file-system-backend" gchararray : Write / Construct Only
  859. -- Name of file system backend to use.
  860. -- Default value: NULL
  861. -- The "filter" property
  862. -- "filter" GtkFileFilter : Read / Write
  863. -- The current filter for selecting which files are displayed.
  864. -- The "local-only" property
  865. -- "local-only" gboolean : Read / Write
  866. -- Whether the selected file(s) should be limited to local file: URLs.
  867. -- Default value: TRUE
  868. -- The "preview-widget" property
  869. -- "preview-widget" GtkWidget : Read / Write
  870. -- Application supplied widget for custom previews.
  871. -- The "preview-widget-active" property
  872. -- "preview-widget-active" gboolean : Read / Write
  873. -- Whether the application supplied widget for custom previews should be shown.
  874. -- Default value: TRUE
  875. -- The "select-multiple" property
  876. -- "select-multiple" gboolean : Read / Write
  877. -- Whether to allow multiple files to be selected.
  878. -- Default value: FALSE
  879. -- The "show-hidden" property
  880. -- "show-hidden" gboolean : Read / Write
  881. -- Whether the hidden files and folders should be displayed.
  882. -- Default value: FALSE
  883. -- The "use-preview-label" property
  884. -- "use-preview-label" gboolean : Read / Write
  885. -- Whether to display a stock label with the name of the previewed file.
  886. -- Default value: TRUE
  887. -- Signal Details
  888. -- The "confirm-overwrite" signal
  889. -- GtkFileChooserConfirmationuser_function (GtkFileChooser *filechooser,
  890. -- gpointer user_data);
  891. -- This signal gets emitted whenever it is appropriate to present a confirmation dialog when the user has selected a file name that already exists. The signal only gets emitted when the file chooser is in GTK_FILE_CHOOSER_ACTION_SAVE mode.
  892. -- Most applications just need to turn on the do-overwrite-confirmation property (or call the gtk_file_chooser_set_do_overwrite_confirmation() function), and they will automatically get a stock confirmation dialog. Applications which need to customize this behavior should do that, and also connect to the confirm-overwrite signal.
  893. -- A signal handler for this signal must return a GtkFileChooserConfirmation value, which indicates the action to take. If the handler determines that the user wants to select a different filename, it should return GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN. If it determines that the user is satisfied with his choice of file name, it should return GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME. On the other hand, if it determines that the stock confirmation dialog should be used, it should return GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM. The following example illustrates this.
  894. -- Example 5. Custom confirmation
  895. -- static GtkFileChooserConfirmation
  896. -- confirm_overwrite_callback (GtkFileChooser *chooser, gpointer data)
  897. -- {
  898. -- char *uri;
  899. -- uri = gtk_file_chooser_get_uri (chooser);
  900. -- if (is_uri_read_only (uri))
  901. -- {
  902. -- if (user_wants_to_replace_read_only_file (uri))
  903. -- return GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME;
  904. -- else
  905. -- return GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN;
  906. -- } else
  907. -- return GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM; /* fall back to the default dialog */
  908. -- }
  909. -- ...
  910. -- chooser = gtk_file_chooser_dialog_new (...);
  911. -- gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
  912. -- g_signal_connect (chooser, "confirm-overwrite",
  913. -- G_CALLBACK (confirm_overwrite_callback), NULL);
  914. -- if (gtk_dialog_run (chooser) == GTK_RESPONSE_ACCEPT)
  915. -- save_to_file (gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
  916. -- gtk_widget_destroy (chooser);
  917. -- filechooser : the object which received the signal.
  918. -- user_data : user data set when the signal handler was connected.
  919. -- Returns : GtkFileChooserConfirmation value that indicates which action to take after emitting the signal.
  920. -- Since 2.8
  921. -- The "current-folder-changed" signal
  922. -- void user_function (GtkFileChooser *chooser,
  923. -- gpointer user_data);
  924. -- This signal is emitted when the current folder in a GtkFileChooser changes. This can happen due to the user performing some action that changes folders, such as selecting a bookmark or visiting a folder on the file list. It can also happen as a result of calling a function to explicitly change the current folder in a file chooser.
  925. -- Normally you do not need to connect to this signal, unless you need to keep track of which folder a file chooser is showing.
  926. -- See also: gtk_file_chooser_set_current_folder(), gtk_file_chooser_get_current_folder(), gtk_file_chooser_set_current_folder_uri(), gtk_file_chooser_get_current_folder_uri().
  927. -- chooser : the object which received the signal.
  928. -- user_data : user data set when the signal handler was connected.
  929. feature -- The "file-activated" signal
  930. -- This signal is emitted when the user "activates" a file in
  931. -- the file chooser. This can happen by double-clicking on a file
  932. -- in the file list, or by pressing Enter.
  933. -- Normally you do not need to connect to this signal. It is
  934. -- used internally by GtkFileChooserDialog to know when to activate
  935. -- the default button in the dialog.
  936. file_activated_signal_name: STRING is "file-activated"
  937. -- void user_function (GtkFileChooser *chooser,
  938. -- gpointer user_data);
  939. enable_on_file_activated is
  940. -- Connects "file-activated" signal to `on_file_activated' feature.
  941. do
  942. connect (Current, file_activated_signal_name, $on_file_activated)
  943. end
  944. on_file_activated is
  945. do
  946. end
  947. connect_agent_to_file_activated_signal (a_procedure: PROCEDURE [ANY, TUPLE [GTK_FILE_CHOOSER]]) is
  948. -- chooser : the object which received the signal.
  949. require
  950. valid_procedure: a_procedure /= Void
  951. local
  952. file_activated_callback: FILE_ACTIVATED_CALLBACK
  953. do
  954. create file_activated_callback.make
  955. file_activated_callback.connect (Current, a_procedure)
  956. end
  957. feature -- The "selection-changed" signal
  958. -- This signal is emitted when there is a change in the set of selected
  959. -- files in a GtkFileChooser. This can happen when the user modifies the
  960. -- selection with the mouse or the keyboard, or when explicitly calling
  961. -- functions to change the selection.
  962. -- Normally you do not need to connect to this signal, as it is easier
  963. -- to wait for the file chooser to finish running, and then to get the list
  964. -- of selected files using the functions mentioned below.
  965. -- See also: gtk_file_chooser_select_filename(),
  966. -- gtk_file_chooser_unselect_filename(), gtk_file_chooser_get_filename(),
  967. -- gtk_file_chooser_get_filenames(), gtk_file_chooser_select_uri(),
  968. -- gtk_file_chooser_unselect_uri(), gtk_file_chooser_get_uri(),
  969. -- gtk_file_chooser_get_uris().
  970. selection_changed_signal_name: STRING is "selection-changed"
  971. enable_on_selection_changed is
  972. -- Connects "selection-changed" signal to `on_selection_changed' feature.
  973. do
  974. connect (Current, selection_changed_signal_name, $on_selection_changed)
  975. end
  976. on_selection_changed is
  977. do
  978. end
  979. connect_agent_to_selection_changed_signal (a_procedure: PROCEDURE [ANY, TUPLE [GTK_FILE_CHOOSER]]) is
  980. -- chooser : the object which received the signal.
  981. require
  982. valid_procedure: a_procedure /= Void
  983. local
  984. selection_changed_callback: SELECTION_CHANGED_CALLBACK
  985. do
  986. create selection_changed_callback.make
  987. selection_changed_callback.connect (Current, a_procedure)
  988. end
  989. feature -- The "update-preview" signal
  990. -- This signal is emitted when the preview in a file chooser should be
  991. -- regenerated. For example, this can happen when the currently selected
  992. -- file changes. You should use this signal if you want your file chooser
  993. -- to have a preview widget.
  994. -- Once you have installed a preview widget with
  995. -- gtk_file_chooser_set_preview_widget(), you should update it when this
  996. -- signal is emitted. You can use the functions
  997. -- gtk_file_chooser_get_preview_filename() or
  998. -- gtk_file_chooser_get_preview_uri() to get the name of the file to
  999. -- preview. Your widget may not be able to preview all kinds of files;
  1000. -- your callback must call gtk_file_chooser_set_preview_wiget_active()
  1001. -- to inform the file chooser about whether the preview was generated
  1002. -- successfully or not.
  1003. -- See also: gtk_file_chooser_set_preview_widget(),
  1004. -- gtk_file_chooser_set_preview_widget_active(),
  1005. -- gtk_file_chooser_set_use_preview_label(),
  1006. -- gtk_file_chooser_get_preview_filename(),
  1007. -- gtk_file_chooser_get_preview_uri().
  1008. update_preview_signal_name: STRING is "update-preview"
  1009. -- void user_function (GtkFileChooser *chooser, gpointer user_data);
  1010. enable_on_update_preview is
  1011. -- Connects "update-preview" signal to `on_update_preview' feature.
  1012. do
  1013. connect (Current, update_preview_signal_name, $on_update_preview)
  1014. end
  1015. on_update_preview is
  1016. do
  1017. end
  1018. connect_agent_to_update_preview_signal (a_procedure: PROCEDURE [ANY, TUPLE [GTK_FILE_CHOOSER]]) is
  1019. -- chooser: the object which received the signal.
  1020. require
  1021. valid_procedure: a_procedure /= Void
  1022. local
  1023. update_preview_callback: UPDATE_PREVIEW_CALLBACK
  1024. do
  1025. create update_preview_callback.make
  1026. update_preview_callback.connect (Current, a_procedure)
  1027. end
  1028. end