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

Contents of /branches/Eiffel_57_docking/Src/Eiffel/interface/new_graphical/commands/eb_class_header_command.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: 11109 byte(s)
First commit docking tabbed Eiffel Studio.
1 indexing
2 description : "Command to edit class headers."
3 legal: "See notice at end of class."
4 status: "See notice at end of class."
5 date : "$Date$"
6 revision : "$Revision$"
7
8 class
9 EB_CLASS_HEADER_COMMAND
10
11 inherit
12 EB_CONTEXT_DIAGRAM_COMMAND
13 redefine
14 new_toolbar_item
15 end
16
17 SHARED_EIFFEL_PARSER
18
19 SHARED_ERROR_HANDLER
20
21 EV_DIALOG_CONSTANTS
22
23 create
24 make
25
26 feature -- Basic operations
27
28 execute is
29 -- Display information about `Current'.
30 do
31 create explain_dialog.make_with_text (Interface_names.e_Diagram_class_header)
32 explain_dialog.show_modal_to_window (tool.develop_window.window)
33 end
34
35 feature -- Access
36
37 pixmap: EV_PIXMAP is
38 -- Pixmap representing the command.
39 do
40 Result := Pixmaps.Icon_class_header
41 end
42
43 tooltip: STRING is
44 -- Tooltip for the toolbar button.
45 do
46 Result := Interface_names.f_diagram_change_header
47 end
48
49 stone_as: CLASS_AS
50 -- AST of class dropped.
51 -- Used to check syntax before and after renaming.
52
53 name: STRING is "Class_header_hole"
54 -- Name of the command. Used to store the command in the
55 -- preferences.
56
57 change_name_dialog: EB_CLASS_HEADER_DIALOG
58 -- Dialog where new class name is typed.
59
60 invalid_name_dialog: EV_WARNING_DIALOG
61 -- Dialog displaying error messages.
62
63 explain_dialog: EB_INFORMATION_DIALOG
64 -- Dialog explaining how to use `Current'.
65
66 new_toolbar_item (display_text: BOOLEAN): EB_COMMAND_TOOL_BAR_BUTTON is
67 -- Create a new toolbar button for this command.
68 do
69 Result := Precursor (display_text)
70 Result.drop_actions.extend (agent execute_with_stone)
71 end
72
73 feature {NONE} -- Implementation
74
75 execute_with_stone (a_stone: CLASSI_STONE) is
76 -- Create a development window and process `a_stone'.
77 local
78 src: ES_CLASS
79 s, g, old_name, old_generics, stone_text: STRING
80 cnr: CLASS_NAME_REPLACER
81 cfs: CLASSI_FIGURE_STONE
82 invalid_name: BOOLEAN
83 class_file: PLAIN_TEXT_FILE
84 confirmation: EV_CONFIRMATION_DIALOG
85 do
86 cfs ?= a_stone
87 if cfs /= Void then
88 src := cfs.source.model
89 end
90 if src /= Void then
91 create class_file.make (src.class_i.file_name)
92 if class_file.exists and then class_file.is_writable and not src.class_i.is_read_only then
93 from
94 invalid_name := True
95 until
96 not invalid_name
97 loop
98 old_name := src.name.twin
99 create change_name_dialog
100 change_name_dialog.set_name (src.name)
101 if src.generics /= Void then
102 change_name_dialog.set_generics (src.generics)
103 old_generics := src.generics.twin
104 else
105 change_name_dialog.set_generics ("")
106 old_generics := ""
107 end
108 change_name_dialog.show_modal_to_window (tool.develop_window.window)
109 if change_name_dialog.ok_pressed then
110 create cnr
111 s := change_name_dialog.name
112 if s /= Void then
113 s.to_upper
114 else
115 s := ""
116 end
117 if not cnr.valid_new_class_name (s) then
118 create invalid_name_dialog.make_with_text (Warning_messages.w_Wrong_class_name)
119 invalid_name_dialog.show_modal_to_window (tool.develop_window.window)
120 else
121 if cnr.class_name_in_use (s) then
122 create confirmation.make_with_text (Warning_messages.w_Class_already_exists_info (s))
123 confirmation.button (ev_ok).set_text (ev_yes)
124 confirmation.button (ev_cancel).set_text (ev_no)
125 confirmation.show_modal_to_window (tool.develop_window.window)
126 end
127 if confirmation = Void or else confirmation.selected_button.is_equal (ev_ok) then
128 g := change_name_dialog.generics
129 if g = Void or g.occurrences (' ') = g.count then
130 g := ""
131 end
132 stone_text := src.class_i.text
133 parse_string (stone_text)
134 if stone_as = Void then
135 create invalid_name_dialog.make_with_text (
136 Warning_messages.w_Class_header_syntax_error (src.class_i.name))
137 invalid_name_dialog.show_modal_to_window (tool.develop_window.window)
138 else
139 try_change_name (stone_text, s, g)
140 parse_string (stone_text)
141 if stone_as = Void then
142 create invalid_name_dialog.make_with_text (Warning_messages.w_Wrong_class_name)
143 invalid_name_dialog.show_modal_to_window (tool.develop_window.window)
144 else
145 if not change_name_dialog.global_replace then
146 history.do_named_undoable (
147 Interface_names.t_Diagram_rename_class_locally_cmd (old_name, s),
148 agent change_name_locally (src, s, g),
149 agent change_name_locally (src, old_name, old_generics))
150 invalid_name := False
151 else
152 if change_name_dialog.global_replace_universe then
153 history.do_named_undoable (
154 Interface_names.t_Diagram_rename_class_globally_cmd (old_name, s),
155 [<<agent tool_disable_sensitive,
156 agent change_name_universe_classes (src, cnr, old_name, s, g),
157 agent tool_enable_sensitive>>],
158 [<<agent tool_disable_sensitive,
159 agent change_name_universe_classes (src, cnr, s, old_name, old_generics),
160 agent tool_enable_sensitive>>])
161 invalid_name := False
162 else
163 history.do_named_undoable (
164 Interface_names.t_Diagram_rename_class_globally_cmd (old_name, s),
165 [<<agent tool_disable_sensitive,
166 agent change_name_compiled_classes (src, cnr, old_name, s, g),
167 agent tool_enable_sensitive>>],
168 [<<agent tool_disable_sensitive,
169 agent change_name_compiled_classes (src, cnr, s, old_name, old_generics),
170 agent tool_enable_sensitive>>])
171 invalid_name := False
172 end
173 end
174 end
175 end
176 end
177 end
178 else
179 invalid_name := False
180 end
181 end
182 else
183 create invalid_name_dialog.make_with_text ("Class is not editable")
184 invalid_name_dialog.show_modal_to_window (tool.develop_window.window)
185 end
186 else
187 create invalid_name_dialog.make_with_text ("Class must be on the diagram")
188 invalid_name_dialog.show_modal_to_window (tool.develop_window.window)
189 end
190 tool.projector.project
191 end
192
193 change_name_locally (a_class: ES_CLASS; new_name, new_generics: STRING) is
194 -- Change name of `a_class' to `new_name'.
195 require
196 a_class_not_void: a_class /= Void
197 new_name_not_void: new_name /= Void
198 local
199 cg: CLASS_TEXT_MODIFIER
200 do
201 cg := a_class.code_generator
202 cg.prepare_for_modification
203 if cg.valid_syntax then
204 cg.set_class_name_declaration (
205 new_name,
206 new_generics
207 )
208 cg.set_end_mark (new_name)
209 cg.commit_modification
210 a_class.set_name (new_name)
211 if not new_generics.is_empty then
212 a_class.set_generics (new_generics)
213 else
214 a_class.set_generics (Void)
215 end
216 end
217 end
218
219 change_name_compiled_classes (a_class: ES_CLASS; cnr: CLASS_NAME_REPLACER; old_name, new_name, new_generics: STRING) is
220 -- Change name of `a_class' to `new_name' in compiled classes.
221 require
222 cnr_not_void: cnr /= Void
223 names_not_void: new_name /= Void and old_name /= Void
224 a_class_not_void: a_class /= Void
225 local
226 l_status_bar: EB_DEVELOPMENT_WINDOW_STATUS_BAR
227 do
228 l_status_bar := tool.develop_window.status_bar
229 tool.develop_window.window.set_pointer_style (tool.Default_pixmaps.Wait_cursor)
230 change_name_locally (a_class, new_name, new_generics)
231 l_status_bar.display_message ("Updating references in compiled classes")
232 cnr.global_class_name_replace (old_name, new_name, True, l_status_bar)
233 tool.develop_window.window.set_pointer_style (tool.Default_pixmaps.Standard_cursor)
234 end
235
236 change_name_universe_classes (a_class: ES_CLASS; cnr: CLASS_NAME_REPLACER; old_name, new_name, new_generics: STRING) is
237 -- Change name of `a_class' to `new_name' in the whole universe.
238 require
239 cnr_not_void: cnr /= Void
240 names_not_void: new_name /= Void and old_name /= Void
241 a_class_not_void: a_class /= Void
242 local
243 l_status_bar: EB_DEVELOPMENT_WINDOW_STATUS_BAR
244 do
245 l_status_bar := tool.develop_window.status_bar
246 tool.develop_window.window.set_pointer_style (tool.Default_pixmaps.Wait_cursor)
247 change_name_locally (a_class, new_name, new_generics)
248 l_status_bar.display_message ("Updating references in cluster universe")
249 cnr.global_class_name_replace (old_name, new_name, False, tool.develop_window.status_bar)
250 tool.develop_window.window.set_pointer_style (tool.Default_pixmaps.Standard_cursor)
251 end
252
253 parse_string (str: STRING) is
254 -- Build `stone_as' corresponding to class text in `str'.
255 local
256 retried: BOOLEAN
257 do
258 if retried then
259 stone_as := Void
260 else
261 Eiffel_parser.parse_from_string (str)
262 stone_as := Eiffel_parser.root_node
263 end
264 rescue
265 retried := True
266 Error_handler.error_list.wipe_out
267 retry
268 end
269
270 try_change_name (text, new_name, new_generics: STRING) is
271 -- Change header in `text'.
272 local
273 click_ast: CLICK_AST
274 sp, ep: INTEGER
275 do
276 check
277 text_has_correct_syntax: stone_as /= Void
278 end
279 click_ast := stone_as.click_ast
280 sp := click_ast.start_position
281 if stone_as.generics_end_position > 0 then
282 ep := stone_as.generics_end_position
283 else
284 ep := click_ast.end_position
285 end
286 text.replace_substring (new_name, sp, ep)
287 if not new_generics.is_empty then
288 text.insert_string (" " + new_generics, sp + new_name.count)
289 end
290 end
291
292 tool_disable_sensitive is
293 -- Make diagram unsensitive to user input.
294 do
295 tool.disable_toolbar
296 tool.area_as_widget.disable_sensitive
297 end
298
299 tool_enable_sensitive is
300 -- Make diagram sensitive to user input.
301 do
302 tool.enable_toolbar
303 tool.area_as_widget.enable_sensitive
304 end
305
306 indexing
307 copyright: "Copyright (c) 1984-2006, Eiffel Software"
308 license: "GPL version 2 (see http://www.eiffel.com/licensing/gpl.txt)"
309 licensing_options: "http://www.eiffel.com/licensing"
310 copying: "[
311 This file is part of Eiffel Software's Eiffel Development Environment.
312
313 Eiffel Software's Eiffel Development Environment is free
314 software; you can redistribute it and/or modify it under
315 the terms of the GNU General Public License as published
316 by the Free Software Foundation, version 2 of the License
317 (available at the URL listed under "license" above).
318
319 Eiffel Software's Eiffel Development Environment is
320 distributed in the hope that it will be useful, but
321 WITHOUT ANY WARRANTY; without even the implied warranty
322 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
323 See the GNU General Public License for more details.
324
325 You should have received a copy of the GNU General Public
326 License along with Eiffel Software's Eiffel Development
327 Environment; if not, write to the Free Software Foundation,
328 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
329 ]"
330 source: "[
331 Eiffel Software
332 356 Storke Road, Goleta, CA 93117 USA
333 Telephone 805-685-1006, Fax 805-685-6869
334 Website http://www.eiffel.com
335 Customer support http://support.eiffel.com
336 ]"
337
338 end -- class EB_CLASS_HEADER_COMMAND

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23