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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 61974 - (show annotations)
Sun Jul 30 06:06:20 2006 UTC (13 years, 7 months ago) by manus
File size: 12533 byte(s)
EiffelStudio docking branch. It only contains modified classes needed to get the docking version of EiffelStudio.
1 indexing
2 description: "Command that lets the user add new external commands to the tools menus"
3 legal: "See notice at end of class."
4 status: "See notice at end of class."
5 author: "Xavier Rousselot"
6 date: "$Date$"
7 revision: "$Revision$"
8
9 class
10 EB_EXTERNAL_COMMANDS_EDITOR
11
12 inherit
13 EB_TOOLBARABLE_AND_MENUABLE_COMMAND
14 redefine
15 name,
16 executable,
17 new_toolbar_item
18 end
19
20 EB_CONSTANTS
21 export
22 {NONE} all
23 end
24
25 EB_SHARED_PREFERENCES
26 export
27 {NONE} all
28 end
29
30 EB_SHARED_MANAGERS
31
32 create
33 make
34
35 feature {NONE} -- Initialization
36
37 make is
38 -- Initialize `Current'.
39 local
40 i: INTEGER
41 s: STRING
42 c: EB_EXTERNAL_COMMAND
43 do
44 if not loaded.item then
45 loaded.set_item (True)
46 from
47 until
48 i > 9
49 loop
50 s := preferences.external_command_data.i_th_external_preference_value (i)
51 if not s.is_empty and not s.is_equal (" ") then
52 create c.make_from_string (s)
53 end
54 i := i + 1
55 end
56 end
57 enable_displayed
58 end
59
60 loaded: BOOLEAN_REF is
61 -- Has `Current' already loaded the preferences?
62 once
63 create Result
64 end
65
66 feature -- Status report
67
68 menus: LIST [EB_COMMAND_MENU_ITEM] is
69 -- Create a list of menu items that represent the list of external commands.
70 local
71 i: INTEGER
72 do
73 from
74 create {ARRAYED_LIST [EB_COMMAND_MENU_ITEM]} Result.make (10)
75 until
76 i > 9
77 loop
78 if commands @ i /= Void then
79 Result.extend ((commands @ i).new_menu_item)
80 end
81 i := i + 1
82 end
83 end
84
85 commands: ARRAY [EB_EXTERNAL_COMMAND] is
86 -- Array of external commands.
87 once
88 create Result.make (0, 9)
89 end
90
91 accelerators: ARRAY [EV_ACCELERATOR] is
92 -- Accelerators for `commands'.
93 local
94 l_shortcut: SHORTCUT_PREFERENCE
95 i: INTEGER
96 once
97 create Result.make (0, 9)
98 from
99 i := 0
100 until
101 i > 9
102 loop
103 l_shortcut := preferences.external_command_data.shortcuts.item ("shortcut_" + i.out)
104 l_shortcut.change_actions.extend (agent on_shortcut_change (i))
105 Result.put (create{EV_ACCELERATOR}.make_with_key_combination (l_shortcut.key, l_shortcut.is_ctrl, l_shortcut.is_alt, l_shortcut.is_shift), i)
106 Result.item (i).actions.extend (agent execute_command_at_position (i))
107 i := i + 1
108 end
109 ensure
110 Result_attached: Result /= Void
111 end
112
113 pixmap: EV_PIXMAP is
114 -- Pixmap representing the command.
115 do
116 Result := pixmaps.icon_pixmaps.tool_external_commands_icon
117 end
118
119 tooltip: STRING is
120 -- Tooltip for the toolbar button.
121 do
122 Result := description
123 end
124
125 name: STRING is "External commands"
126 -- Name of the command. Use to store the command in the
127 -- preferences.
128
129 description: STRING is
130 -- Pop up help on the toolbar button.
131 do
132 Result := Interface_names.l_manage_external_commands
133 end
134
135 executable: BOOLEAN is
136 -- Is Current command executable?
137 -- (True by default)
138 do
139 Result := is_sensitive
140 end
141
142 new_toolbar_item (display_text: BOOLEAN): EB_COMMAND_TOOL_BAR_BUTTON is
143 -- Create a new toolbar button for this command.
144 do
145 Result := Precursor (display_text)
146 Result.set_pixmap (pixmap)
147 Result.set_tooltip (tooltip)
148 end
149
150 feature -- Actions
151
152 on_shortcut_change (i: INTEGER) is
153 -- Action to be performed when shortcut for an external command changes
154 require
155 i_valid: i >= 0 and i <= 9
156 local
157 l_shortcut: SHORTCUT_PREFERENCE
158 do
159 l_shortcut := preferences.editor_data.shortcuts.item ("shortcut_" + i.out)
160 accelerators.put (create{EV_ACCELERATOR}.make_with_key_combination (l_shortcut.key, l_shortcut.is_ctrl, l_shortcut.is_alt, l_shortcut.is_shift), i)
161 accelerators.item (i).actions.extend (agent execute_command_at_position (i))
162 end
163
164 feature -- Basic operations
165
166 execute is
167 -- Pop up a dialog that lets the user customize external commands.
168 do
169 if dialog = Void then
170 create_dialog
171 dialog.show_modal_to_window (Window_manager.last_focused_development_window.window)
172 else
173 dialog.hide
174 dialog.show_modal_to_window (Window_manager.last_focused_development_window.window)
175 end
176 end
177
178 execute_command_at_position (a_pos: INTEGER) is
179 -- Execute command at position `a_pos'.
180 require
181 a_pos_valid: a_pos >=0 and a_pos <= 9
182 do
183 if commands.item (a_pos) /= Void then
184 commands.item (a_pos).execute
185 end
186 end
187
188 feature{EB_EXTERNAL_OUTPUT_TOOL} -- Synchronizing features used by EB_EXTERNAL_OUTPUT_TOOL
189
190 refresh_list_from_outside is
191 -- Refresh command list from EB_EXTERNAL_OUTPUT_TOOL
192 do
193 if list /= Void then
194 refresh_list
195 end
196 end
197 update_menus_from_outside is
198 -- Update external menu items from EB_EXTERNAL_OUTPUT_TOOL
199 do
200 update_menus
201 end
202
203 feature {NONE} -- Widgets
204
205 dialog: EV_DIALOG
206 -- Dialog that contains all widgets and lets the user edit the list of external commands.
207
208 add_button: EV_BUTTON
209 -- Button that lets the user add an external command.
210
211 edit_button: EV_BUTTON
212 -- Button that lets the user edit an external command.
213
214 delete_button: EV_BUTTON
215 -- Button that lets the user delete an external command.
216
217 close_button: EV_BUTTON
218 -- Button to close dialog.
219
220 list: EV_LIST
221 -- List that represents the available external commands.
222
223 feature {NONE} -- Implementation
224
225 create_dialog is
226 -- Initialize all widgets and build `dialog'.
227 local
228 hb: EV_HORIZONTAL_BOX
229 vb: EV_VERTICAL_BOX
230 f: EV_FRAME
231 do
232 -- Create widgets.
233 create dialog
234 create list
235 create add_button.make_with_text (Interface_names.b_New_command)
236 create edit_button.make_with_text (Interface_names.b_Edit_command)
237 create delete_button.make_with_text (Interface_names.b_Delete_command)
238 create close_button.make_with_text (Interface_names.b_Close)
239
240 -- Organize widgets.
241 create vb
242 vb.set_padding (Layout_constants.Default_padding_size)
243 vb.extend (add_button)
244 vb.disable_item_expand (add_button)
245 vb.extend (edit_button)
246 vb.disable_item_expand (edit_button)
247 vb.extend (delete_button)
248 vb.disable_item_expand (delete_button)
249 vb.extend (create {EV_CELL})
250 vb.extend (close_button)
251 vb.disable_item_expand (close_button)
252
253 create hb
254 hb.set_padding (Layout_constants.Default_padding_size)
255 hb.set_border_width (Layout_constants.Default_border_size)
256
257 create f
258 f.set_style ({EV_FRAME_CONSTANTS}.Ev_frame_lowered)
259 f.extend (list)
260
261 hb.extend (f)
262 hb.extend (vb)
263 hb.disable_item_expand (vb)
264
265 dialog.extend (hb)
266
267 -- Set widget properties.
268 refresh_list
269 update_edit_buttons
270 if not commands.has (Void) then
271 -- All command indices are already taken.
272 add_button.disable_sensitive
273 end
274 dialog.set_title (Interface_names.t_external_commands)
275 dialog.set_icon_pixmap (pixmaps.icon_pixmaps.general_dialog_icon)
276 dialog.set_default_push_button (close_button)
277 dialog.set_default_cancel_button (close_button)
278 list.disable_multiple_selection
279 list.set_minimum_width (100)
280 Layout_constants.set_default_size_for_button (close_button)
281 Layout_constants.set_default_size_for_button (add_button)
282 Layout_constants.set_default_size_for_button (edit_button)
283 Layout_constants.set_default_size_for_button (delete_button)
284 dialog.set_size (300, 200)
285
286 -- Set up events.
287 list.select_actions.extend (agent update_edit_buttons)
288 list.deselect_actions.extend (agent update_edit_buttons)
289 list.key_press_actions.extend (agent on_key)
290 close_button.select_actions.extend (agent destroy_dialog)
291 add_button.select_actions.extend (agent add_command)
292 edit_button.select_actions.extend (agent edit_command)
293 delete_button.select_actions.extend (agent delete_command)
294
295 if commands.has (Void) then
296 -- It is not full
297 dialog.show_actions.extend (agent add_button.set_focus)
298 end
299 end
300
301 destroy_dialog is
302 -- Free all widgets.
303 local
304 i: INTEGER
305 do
306 check
307 dialog /= Void
308 --| FIXME XR: We shouldn't be able to call destroy_dialog more than once, but it occurred...
309 end
310 if dialog /= Void then
311 dialog.destroy
312 end
313 dialog := Void
314 add_button := Void
315 edit_button := Void
316 delete_button := Void
317 list := Void
318 update_menus
319 from
320 until
321 i > 9
322 loop
323 if commands @ i /= Void then
324 preferences.external_command_data.i_th_external_preference (i).set_value ((commands @ i).resource)
325 else
326 -- We use an empty string as value, because this is how the
327 -- preferences are initialized. That way, the entry is actually
328 -- removed from the preferences.
329 preferences.external_command_data.i_th_external_preference (i).set_value ("")
330 end
331 i := i + 1
332 end
333 end
334
335 refresh_list is
336 -- Rebuild the list of available commands.
337 require
338 list_exists: list /= Void
339 local
340 i: INTEGER
341 tmp_lst: ARRAYED_LIST [EV_LIST_ITEM]
342 litem: EV_LIST_ITEM
343 do
344 from
345 create tmp_lst.make (10)
346 until
347 i > 9
348 loop
349 if commands @ i /= Void then
350 create litem
351 litem.set_text ((commands @ i).name)
352 litem.set_data (commands @ i)
353 tmp_lst.extend (litem)
354 end
355 i := i + 1
356 end
357 list.wipe_out
358 list.append (tmp_lst)
359 end
360
361 update_edit_buttons is
362 -- Update the sensitivity of the buttons that alter the list.
363 require
364 initialized: list /= Void
365 do
366 if list.selected_item /= Void then
367 edit_button.enable_sensitive
368 delete_button.enable_sensitive
369 else
370 edit_button.disable_sensitive
371 delete_button.disable_sensitive
372 end
373 end
374
375 add_command is
376 -- Create a new command.
377 require
378 dialog_exists: dialog /= Void and then not dialog.is_destroyed
379 room_left: commands.has (Void)
380 local
381 new_command: EB_EXTERNAL_COMMAND
382 do
383 create new_command.make (dialog)
384 refresh_list
385 if not commands.has (Void) then
386 add_button.disable_sensitive
387 close_button.set_focus
388 end
389 update_edit_buttons
390 end
391
392 edit_command is
393 -- Edit an existing command.
394 require
395 dialog_exists: list /= Void and dialog /= Void and not dialog.is_destroyed
396 has_selection: list.selected_item /= Void
397 local
398 comm: EB_EXTERNAL_COMMAND
399 do
400 comm ?= list.selected_item.data
401 comm.edit_properties (dialog)
402 refresh_list
403 update_edit_buttons
404 end
405
406 delete_command is
407 -- Delete an existing command.
408 require
409 dialog_exists: list /= Void and dialog /= Void and not dialog.is_destroyed
410 has_selection: list.selected_item /= Void
411 local
412 comm: EB_EXTERNAL_COMMAND
413 do
414 comm ?= list.selected_item.data
415 commands.put (Void, comm.index)
416 refresh_list
417 update_edit_buttons
418 add_button.enable_sensitive
419 add_button.set_focus
420 external_output_manager.synchronize_command_list (Void)
421 end
422
423 on_key (k: EV_KEY) is
424 -- A key was pressed in the list. Process it.
425 do
426 if k.code = {EV_KEY_CONSTANTS}.Key_delete then
427 if list /= Void and list.selected_item /= Void then
428 delete_command
429 end
430 end
431 end
432
433 update_menus is
434 -- Refresh the 'tools' menus of all development windows.
435 do
436 Window_manager.for_all_development_windows (agent {EB_DEVELOPMENT_WINDOW}.rebuild_tools_menu)
437 end
438
439 feature {NONE} -- Properties
440
441 menu_name: STRING is
442 -- Name of `Current' as it appears in menus.
443 do
444 Result := interface_names.m_Edit_external_commands
445 end
446
447 invariant
448 invariant_clause: True -- Your invariant here
449
450 indexing
451 copyright: "Copyright (c) 1984-2006, Eiffel Software"
452 license: "GPL version 2 (see http://www.eiffel.com/licensing/gpl.txt)"
453 licensing_options: "http://www.eiffel.com/licensing"
454 copying: "[
455 This file is part of Eiffel Software's Eiffel Development Environment.
456
457 Eiffel Software's Eiffel Development Environment is free
458 software; you can redistribute it and/or modify it under
459 the terms of the GNU General Public License as published
460 by the Free Software Foundation, version 2 of the License
461 (available at the URL listed under "license" above).
462
463 Eiffel Software's Eiffel Development Environment is
464 distributed in the hope that it will be useful, but
465 WITHOUT ANY WARRANTY; without even the implied warranty
466 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
467 See the GNU General Public License for more details.
468
469 You should have received a copy of the GNU General Public
470 License along with Eiffel Software's Eiffel Development
471 Environment; if not, write to the Free Software Foundation,
472 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
473 ]"
474 source: "[
475 Eiffel Software
476 356 Storke Road, Goleta, CA 93117 USA
477 Telephone 805-685-1006, Fax 805-685-6869
478 Website http://www.eiffel.com
479 Customer support http://support.eiffel.com
480 ]"
481
482 end -- class EB_EXTERNAL_COMMANDS_EDITOR

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23