PageRenderTime 22ms CodeModel.GetById 10ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

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