/src/wrappers/gtk/library/gtk_file_chooser_dialog.e

http://github.com/tybor/Liberty · Specman e · 206 lines · 58 code · 44 blank · 104 comment · 6 complexity · e648218737c68d937c8dd2188344ec03 MD5 · raw file

  1. indexing
  2. description: "GtkFileChooserDialog A file chooser dialog, suitable for `File/Open' or `File/Save' commands."
  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. class GTK_FILE_CHOOSER_DIALOG
  21. -- GtkFileChooserDialog is a dialog box suitable for use with
  22. -- "File/Open" or "File/Save as" commands. This widget works by
  23. -- putting a GtkFileChooserWidget inside a GtkDialog. It exposes
  24. -- the GtkFileChooserIface interface, so you can use all of the
  25. -- GtkFileChooser functions on the file chooser dialog as well as
  26. -- those for GtkDialog.
  27. -- Note that GtkFileChooserDialog does not have any methods of its
  28. -- own. Instead, you should use the functions that work on a
  29. -- GtkFileChooser.
  30. -- TODO: Eiffellize Example 7. Typical usage
  31. -- In the simplest of cases, you can the following code to use GtkFileChooserDialog to select a file for opening:
  32. -- GtkWidget *dialog;
  33. -- dialog = gtk_file_chooser_dialog_new ("Open File",
  34. -- parent_window,
  35. -- GTK_FILE_CHOOSER_ACTION_OPEN,
  36. -- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
  37. -- GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
  38. -- NULL);
  39. -- if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
  40. -- {
  41. -- char *filename;
  42. -- filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
  43. -- open_file (filename);
  44. -- g_free (filename);
  45. -- }
  46. -- gtk_widget_destroy (dialog);
  47. -- To use a dialog for saving, you can use this:
  48. -- GtkWidget *dialog;
  49. -- dialog = gtk_file_chooser_dialog_new ("Save File",
  50. -- parent_window,
  51. -- GTK_FILE_CHOOSER_ACTION_SAVE,
  52. -- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
  53. -- GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
  54. -- NULL);
  55. -- gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
  56. -- if (user_edited_a_new_document)
  57. -- {
  58. -- gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), default_folder_for_saving);
  59. -- gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), "Untitled document");
  60. -- }
  61. -- else
  62. -- gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), filename_for_existing_document);
  63. -- if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
  64. -- {
  65. -- char *filename;
  66. -- filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
  67. -- save_to_file (filename);
  68. -- g_free (filename);
  69. -- }
  70. -- gtk_widget_destroy (dialog);
  71. -- Response Codes
  72. -- GtkFileChooserDialog inherits from GtkDialog, so buttons that go in its action area have response codes such as GTK_RESPONSE_ACCEPT and GTK_RESPONSE_CANCEL. For example, you could call gtk_file_chooser_dialog_new() as follows:
  73. -- GtkWidget *dialog;
  74. -- dialog = gtk_file_chooser_dialog_new ("Open File",
  75. -- parent_window,
  76. -- GTK_FILE_CHOOSER_ACTION_OPEN,
  77. -- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
  78. -- GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
  79. -- NULL);
  80. -- This will create buttons for "Cancel" and "Open" that use stock response identifiers from GtkResponseType. For most dialog boxes you can use your own custom response codes rather than the ones in GtkResponseType, but GtkFileChooserDialog assumes that its "accept"-type action, e.g. an "Open" or "Save" button, will have one of the following response codes:
  81. -- GTK_RESPONSE_ACCEPT
  82. -- GTK_RESPONSE_OK
  83. -- GTK_RESPONSE_YES
  84. -- GTK_RESPONSE_APPLY
  85. -- This is because GtkFileChooserDialog must intercept
  86. -- responses and switch to folders if appropriate, rather
  87. -- than letting the dialog terminate %G —%@
  88. -- the implementation uses these known response codes to know
  89. -- which responses can be blocked if appropriate. -- Note
  90. -- To summarize, make sure you use a stock response code when
  91. -- you use GtkFileChooserDialog to ensure proper operation.
  92. inherit
  93. GTK_DIALOG redefine struct_size end
  94. GTK_FILE_CHOOSER
  95. -- Implemented Interfaces: GtkFileChooserDialog implements
  96. -- AtkImplementorIface and GtkFileChooser.
  97. insert
  98. GTK_FILE_CHOOSER_DIALOG_EXTERNALS
  99. creation
  100. make_open, make_save, from_external_pointer
  101. feature {} -- Creation
  102. make_open (a_title: STRING; a_parent: GTK_WINDOW; some_buttons: COLLECTION[TUPLE[STRING,INTEGER]]) is
  103. -- Creates a new GTK_FILE_CHOOSER_DIALOG to open a file. `a_title' is the title of
  104. -- the dialog, or Void; `a_parent' - if not Void - is the
  105. -- transient parent of the dialog;
  106. -- first_button_text : stock ID or text to go in the first button, or NULL
  107. -- ... : response ID for the first button, then additional (button, id) pairs, ending with NULL
  108. -- Returns : a new GtkFileChooserDialog
  109. do
  110. making (a_title, a_parent, gtk_file_chooser_action_open, some_buttons)
  111. end
  112. make_save (a_title: STRING; a_parent: GTK_WINDOW; some_buttons: COLLECTION[TUPLE[STRING,INTEGER]]) is
  113. -- Creates a new GTK_FILE_CHOOSER_DIALOG to save a file. `a_title' is the title of
  114. -- the dialog, or Void; `a_parent' - if not Void - is the
  115. -- transient parent of the dialog;
  116. -- first_button_text : stock ID or text to go in the first button, or NULL
  117. -- ... : response ID for the first button, then additional (button, id) pairs, ending with NULL
  118. -- Returns : a new GtkFileChooserDialog
  119. do
  120. making (a_title, a_parent, gtk_file_chooser_action_save, some_buttons)
  121. end
  122. making (a_title: STRING; a_parent: GTK_WINDOW; an_action: INTEGER; some_buttons: COLLECTION[TUPLE[STRING,INTEGER]]) is
  123. -- Creates a new GTK_FILE_CHOOSER_DIALOG. `a_title' is the title of
  124. -- the dialog, or Void; `a_parent' - if not Void - is the
  125. -- transient parent of the dialog; `an_action' is the Open or save mode for the dialog
  126. -- first_button_text : stock ID or text to go in the first button, or NULL
  127. -- ... : response ID for the first button, then additional (button, id) pairs, ending with NULL
  128. -- Returns : a new GtkFileChooserDialog
  129. local title_ptr, parent_ptr: POINTER; iterator: ITERATOR[TUPLE[STRING,INTEGER]]
  130. do
  131. if a_title/=Void then title_ptr := a_title.to_external end
  132. if a_parent/=Void then parent_ptr := a_parent.handle end
  133. from_external_pointer (gtk_file_chooser_dialog_new
  134. (title_ptr, parent_ptr, an_action, default_pointer))
  135. if some_buttons/=Void then
  136. from iterator := some_buttons.get_new_iterator; iterator.start
  137. until iterator.is_off
  138. loop
  139. add_button (iterator.item.item_1, iterator.item.item_2)
  140. iterator.next
  141. end
  142. end
  143. end
  144. -- TODO: gtk_file_chooser_dialog_new_with_backend ()
  145. -- GtkWidget* gtk_file_chooser_dialog_new_with_backend (const gchar
  146. -- *title, GtkWindow *parent, GtkFileChooserAction action, const
  147. -- gchar *backend, const gchar *first_button_text, ...);
  148. -- Creates a new GtkFileChooserDialog with a specified backend. This is especially useful if you use gtk_file_chooser_set_local_only() to allow non-local files and you use a more expressive vfs, such as gnome-vfs, to load files.
  149. -- title : Title of the dialog, or NULL
  150. -- parent : Transient parent of the dialog, or NULL
  151. -- action : Open or save mode for the dialog
  152. -- backend : The name of the specific filesystem backend to use.
  153. -- first_button_text : stock ID or text to go in the first button, or NULL
  154. -- ... : response ID for the first button, then additional (button, id) pairs, ending with NULL
  155. -- Returns : a new GtkFileChooserDialog
  156. -- Since 2.4
  157. feature
  158. struct_size: INTEGER is
  159. external "C inline use <gtk/gtk.h>"
  160. alias "sizeof(GtkFileChooserDialog)"
  161. end
  162. end