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