PageRenderTime 47ms CodeModel.GetById 35ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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