/[eiffelstudio]/branches/Eiffel_57_docking/Src/Eiffel/interface/new_graphical/commands/eb_open_file_cmd.e
ViewVC logotype

Contents of /branches/Eiffel_57_docking/Src/Eiffel/interface/new_graphical/commands/eb_open_file_cmd.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 62171 - (show annotations)
Tue Aug 1 01:27:17 2006 UTC (13 years, 4 months ago) by larryl
File size: 7766 byte(s)
First commit docking tabbed Eiffel Studio.
1 indexing
2 description : "Command to open a file"
3 legal: "See notice at end of class."
4 status: "See notice at end of class."
5 date : "$Date$"
6 revision : "$Revision$"
7 author : "Arnaud PICHERY [ aranud@mail.dotcom.fr ]"
8 class
9 EB_OPEN_FILE_COMMAND
10
11 inherit
12 EB_FILEABLE_COMMAND
13 redefine
14 initialize
15 end
16
17 EB_TOOLBARABLE_AND_MENUABLE_COMMAND
18 redefine
19 tooltext
20 end
21
22 EB_CONFIRM_SAVE_CALLBACK
23 export
24 {NONE} all
25 end
26
27 SHARED_EIFFEL_PROJECT
28 export
29 {NONE} all
30 end
31
32 EB_SHARED_WINDOW_MANAGER
33 export
34 {NONE} all
35 end
36
37 EB_CONSTANTS
38 export
39 {NONE} all
40 end
41
42 EB_FILE_DIALOG_CONSTANTS
43 export
44 {NONE} all
45 end
46
47 EB_SHARED_PREFERENCES
48 export
49 {NONE} all
50 end
51
52 create
53 make
54
55 feature {NONE} -- Initialization
56
57 initialize is
58 -- Initialize default values.
59 do
60 create accelerator.make_with_key_combination (
61 create {EV_KEY}.make_with_code ({EV_KEY_CONSTANTS}.Key_o),
62 True, False, False)
63 accelerator.actions.extend (agent execute)
64 end
65
66 feature -- Basic operation
67
68 execute is
69 -- Open a file.
70 local
71 csd: EB_CONFIRM_SAVE_DIALOG
72 do
73 if is_sensitive then
74 if target.changed then
75 -- Ask confirmation if content has changed.
76 create csd.make_and_launch (target, Current)
77 else
78 process
79 end
80 end
81 end
82
83 feature -- Properties
84
85 menu_name: STRING is
86 do
87 Result := Interface_names.m_Open_new
88 end
89
90 pixmap: EV_PIXMAP is
91 do
92 Result := pixmaps.icon_pixmaps.general_open_icon
93 end
94
95 pixel_buffer: EV_PIXEL_BUFFER is
96 -- Pixel buffer representing the command.
97 do
98 Result := pixmaps.icon_pixmaps.general_open_icon_buffer
99 end
100
101 name: STRING is "Open_file"
102
103 description: STRING is
104 do
105 Result := Interface_names.e_Open_file
106 end
107
108 tooltip: STRING is
109 do
110 Result := description
111 end
112
113 tooltext: STRING is
114 -- Text of toolbar button
115 do
116 Result := Interface_names.b_Open
117 end
118
119
120 feature {NONE} -- Implementation
121
122 process is
123 local
124 fod: EB_FILE_OPEN_DIALOG
125 do
126 create fod.make_with_preference (preferences.dialog_data.last_opened_file_directory_preference)
127 set_dialog_filters_and_add_all (fod, <<eiffel_class_files_filter>>)
128 fod.open_actions.extend (agent execute_callback (fod))
129 fod.show_modal_to_window (window_manager.last_focused_development_window.window)
130 end
131
132 execute_callback (dialog: EB_FILE_OPEN_DIALOG) is
133 -- Open a file.
134 local
135 fn: FILE_NAME
136 f: PLAIN_TEXT_FILE
137 efs: EXTERNAL_FILE_STONE
138 bckfn: FILE_NAME
139 backup_file: PLAIN_TEXT_FILE
140 cd: EV_CONFIRMATION_DIALOG
141 class_i: CLASS_I
142 class_stone: CLASSI_STONE
143 wd: EV_WARNING_DIALOG
144 do
145 create fn.make_from_string (dialog.file_name)
146 if not fn.is_empty then
147 bckfn := fn.twin
148 bckfn.add_extension ("swp")
149 create backup_file.make (bckfn)
150 open_backup := False
151 if backup_file.exists then
152 ask_whether_to_open_backup
153 end
154 if open_backup then
155 create f.make (bckfn)
156 else
157 create f.make (fn)
158 end
159 if f.exists and then f.is_readable and then f.is_plain then
160 conf_todo
161 -- class_i := Eiffel_universe.class_with_file_name (fn)
162 if class_i = Void then
163 if allow_external_files_in_ide then
164 create efs.make (f)
165 target.set_stone (efs)
166 else
167 create wd.make_with_text (Warning_messages.w_Cannot_open_any_file)
168 wd.show_modal_to_window (window_manager.last_focused_development_window.window)
169 end
170 else
171 if class_i.compiled then
172 create {CLASSC_STONE} class_stone.make (class_i.compiled_class)
173 else
174 create {CLASSI_STONE} class_stone.make (class_i)
175 end
176 target.set_stone (class_stone)
177 end
178 elseif f.exists and then not f.is_plain then
179 create cd.make_with_text (Warning_messages.w_Not_a_file_retry (fn))
180 cd.button ("OK").select_actions.extend (agent execute)
181 cd.show_modal_to_window (window_manager.last_focused_development_window.window)
182 else
183 create cd.make_with_text (Warning_messages.w_Cannot_read_file_retry (fn))
184 cd.button ("OK").select_actions.extend (agent execute)
185 cd.show_modal_to_window (window_manager.last_focused_development_window.window)
186 end
187 else
188 create cd.make_with_text (Warning_messages.w_Not_a_file_retry (fn))
189 cd.button ("OK").select_actions.extend (agent execute)
190 cd.show_modal_to_window (window_manager.last_focused_development_window.window)
191 end
192 end
193
194 ask_whether_to_open_backup is
195 -- Display a dialog asking the user whether he wants to open
196 -- the original file or the backup one, and set `open_backup' accordingly.
197 local
198 dial: EV_DIALOG
199 butbackup, butnormal: EV_BUTTON
200 lab: EV_LABEL
201 butcont: EV_HORIZONTAL_BOX
202 maincont: EV_VERTICAL_BOX
203 do
204 create dial
205 create butcont
206 create maincont
207 create butbackup.make_with_text (Interface_names.b_Open_backup)
208 butbackup.select_actions.extend (agent open_backup_selected)
209 butbackup.select_actions.extend (agent dial.destroy)
210 create butnormal.make_with_text (Interface_names.b_Open_original)
211 butnormal.select_actions.extend (agent open_normal_selected)
212 butnormal.select_actions.extend (agent dial.destroy)
213 create lab.make_with_text (Warning_messages.w_Found_backup)
214 butcont.set_padding (3)
215 butcont.extend (create {EV_CELL})
216 butcont.extend (butbackup)
217 butcont.disable_item_expand (butbackup)
218 butcont.extend (butnormal)
219 butcont.disable_item_expand (butnormal)
220 butcont.extend (create {EV_CELL})
221 maincont.set_padding (5)
222 maincont.set_border_width (3)
223 maincont.extend (lab)
224 maincont.disable_item_expand (lab)
225 maincont.extend (butcont)
226 maincont.disable_item_expand (butcont)
227 dial.set_title ("Backup found")
228 dial.set_icon_pixmap (pixmaps.icon_pixmaps.general_dialog_icon)
229 dial.extend (maincont)
230 dial.set_size (dial.minimum_width, dial.minimum_height)
231 dial.disable_user_resize
232 dial.set_default_push_button (butbackup)
233 dial.show_modal_to_window (window_manager.last_focused_development_window.window)
234 end
235
236 open_normal_selected is
237 -- The open normal button was pushed.
238 do
239 open_backup := False
240 end
241
242 open_backup_selected is
243 -- The open backup button was pushed.
244 do
245 open_backup := True
246 end
247
248 open_backup: BOOLEAN
249 -- If a backup file is present, indicates whether it should be opened or not.
250
251 allow_external_files_in_ide: BOOLEAN is False;
252 -- Flag to determine if we can load non-eiffel files in the environment
253
254 indexing
255 copyright: "Copyright (c) 1984-2006, Eiffel Software"
256 license: "GPL version 2 (see http://www.eiffel.com/licensing/gpl.txt)"
257 licensing_options: "http://www.eiffel.com/licensing"
258 copying: "[
259 This file is part of Eiffel Software's Eiffel Development Environment.
260
261 Eiffel Software's Eiffel Development Environment is free
262 software; you can redistribute it and/or modify it under
263 the terms of the GNU General Public License as published
264 by the Free Software Foundation, version 2 of the License
265 (available at the URL listed under "license" above).
266
267 Eiffel Software's Eiffel Development Environment is
268 distributed in the hope that it will be useful, but
269 WITHOUT ANY WARRANTY; without even the implied warranty
270 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
271 See the GNU General Public License for more details.
272
273 You should have received a copy of the GNU General Public
274 License along with Eiffel Software's Eiffel Development
275 Environment; if not, write to the Free Software Foundation,
276 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
277 ]"
278 source: "[
279 Eiffel Software
280 356 Storke Road, Goleta, CA 93117 USA
281 Telephone 805-685-1006, Fax 805-685-6869
282 Website http://www.eiffel.com
283 Customer support http://support.eiffel.com
284 ]"
285
286 end -- class EB_OPEN_FILE_CMD

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23