author | Claus Gittinger <cg@exept.de> |
Mon, 03 Nov 1997 16:33:51 +0100 | |
changeset 737 | c8bdd9dd8906 |
parent 729 | 7e22cc23fd1f |
child 738 | f7e6b6cd3855 |
permissions | -rw-r--r-- |
451 | 1 |
Object subclass:#Menu |
579 | 2 |
instanceVariableNames:'items groupSizes receiver' |
451 | 3 |
classVariableNames:'' |
4 |
poolDictionaries:'' |
|
5 |
category:'Views-Support' |
|
6 |
! |
|
7 |
||
8 |
!Menu class methodsFor:'documentation'! |
|
9 |
||
10 |
documentation |
|
11 |
" |
|
12 |
not yet finished Menu class - this will eventually replace |
|
13 |
most of the MenuView and PopUpMenu stuff. |
|
14 |
(and hopefully be ST-80 compatible ...) |
|
15 |
||
16 |
For now, only a subset of the full protocol is implemented. |
|
17 |
||
18 |
[author:] |
|
19 |
Claus Gittinger |
|
20 |
||
21 |
[see also:] |
|
22 |
MenuItem |
|
23 |
PopUpMenu |
|
24 |
" |
|
25 |
! ! |
|
26 |
||
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
27 |
!Menu class methodsFor:'instance creation'! |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
28 |
|
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
29 |
labelArray: arrayOfString lines: linesArray values: valueArrayOrNil |
737 | 30 |
"return a menu with menu items built with labels from arrayOfString (not Symbols). |
31 |
The linesArray describes which menu items are the last menu item in their group. |
|
32 |
The valueArray contains value objects for each menu item |
|
33 |
(or is nil if no value objects are specified)." |
|
34 |
||
35 |
| nLabel valueArray menuItems groupLengths | |
|
36 |
||
37 |
nLabel := arrayOfString size. |
|
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
38 |
|
737 | 39 |
valueArrayOrNil isNil ifTrue:[ |
40 |
valueArray := arrayOfString isEmpty ifTrue: [ |
|
41 |
valueArray := #() |
|
42 |
] ifFalse:[ |
|
43 |
valueArray := (1 to:nLabel) |
|
44 |
] |
|
45 |
] ifFalse:[ |
|
46 |
valueArray := valueArrayOrNil |
|
47 |
]. |
|
48 |
||
49 |
nLabel ~~ valueArray size ifTrue: [ |
|
50 |
^ self error: 'illegal menu combination' |
|
51 |
]. |
|
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
52 |
|
737 | 53 |
menuItems := Array new:nLabel. |
54 |
1 to:nLabel do:[:i | |
|
55 |
|mi v| |
|
56 |
||
57 |
mi := MenuItem labeled: (arrayOfString at:i) asString. |
|
58 |
v := valueArray at: i. |
|
59 |
(v isKindOf: Menu) ifTrue: [mi submenu: v]. |
|
60 |
menuItems at: i put: mi |
|
61 |
]. |
|
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
62 |
|
737 | 63 |
(linesArray == nil or:[linesArray isEmpty]) ifTrue:[ |
64 |
groupLengths := (menuItems isEmpty) |
|
65 |
ifTrue: [Array new: 0] |
|
66 |
ifFalse: [Array with: menuItems size] |
|
67 |
] ifFalse:[ |
|
68 |
groupLengths := Array new: linesArray size + 1. |
|
69 |
groupLengths at: 1 put: linesArray first. |
|
70 |
2 to: linesArray size do: [:i | |
|
71 |
groupLengths at: i put: (linesArray at: i) - (linesArray at: i - 1) |
|
72 |
]. |
|
73 |
groupLengths at: groupLengths size put: menuItems size - linesArray last |
|
74 |
]. |
|
75 |
||
76 |
^ self new |
|
77 |
menuItems: menuItems |
|
78 |
menuItemGroups: groupLengths |
|
79 |
values: valueArray |
|
80 |
||
81 |
"Modified: / 31.10.1997 / 03:19:14 / cg" |
|
696 | 82 |
! |
83 |
||
84 |
labelList:arrayOfGroupStrings values:valueArrayOrNil |
|
85 |
|labels lines| |
|
86 |
||
87 |
lines := arrayOfGroupStrings collect:[:each | each size]. |
|
88 |
labels := OrderedCollection new. |
|
89 |
arrayOfGroupStrings do:[:group | labels addAll:group]. |
|
90 |
^ self labelArray:labels lines:lines values:valueArrayOrNil |
|
91 |
||
92 |
"Modified: 20.6.1997 / 10:46:45 / cg" |
|
93 |
"Created: 13.9.1997 / 10:35:46 / cg" |
|
737 | 94 |
! |
95 |
||
96 |
labels:arrayOfStrings lines:linesArray values:valueArrayOrNil |
|
97 |
^ self |
|
98 |
labelArray:arrayOfStrings |
|
99 |
lines:linesArray |
|
100 |
values:valueArrayOrNil |
|
101 |
||
102 |
"Created: / 31.10.1997 / 03:12:20 / cg" |
|
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
103 |
! ! |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
104 |
|
724 | 105 |
!Menu methodsFor:'ST-80 compatibility'! |
106 |
||
107 |
indexOfMenuItem:anItem |
|
108 |
||
109 |
^ items indexOf:anItem |
|
110 |
||
111 |
"Created: / 27.10.1997 / 16:34:19 / cg" |
|
112 |
! |
|
113 |
||
114 |
menuButtons |
|
115 |
"ST-80 seems to use a special menuButton class here. |
|
116 |
Here, kludge a collection of menuItems." |
|
117 |
||
118 |
^ items |
|
119 |
||
120 |
"Created: / 27.10.1997 / 16:33:35 / cg" |
|
121 |
! ! |
|
122 |
||
451 | 123 |
!Menu methodsFor:'accessing'! |
124 |
||
589 | 125 |
addItem:aMenuItem |
489 | 126 |
items isNil ifTrue:[ |
127 |
items := OrderedCollection new |
|
128 |
]. |
|
129 |
items add:aMenuItem. |
|
589 | 130 |
! |
131 |
||
132 |
addItem:aMenuItem value:aValue |
|
133 |
aMenuItem value:aValue. |
|
134 |
self addItem:aMenuItem. |
|
489 | 135 |
! |
136 |
||
724 | 137 |
addItemGroup:aCollectionOfItems |
138 |
groupSizes isNil ifTrue:[ |
|
139 |
groupSizes := OrderedCollection new |
|
140 |
]. |
|
141 |
groupSizes add:aCollectionOfItems size. |
|
142 |
||
143 |
aCollectionOfItems do:[:item | |
|
144 |
self addItem:item |
|
145 |
]. |
|
146 |
||
147 |
"Created: / 27.10.1997 / 15:02:15 / cg" |
|
148 |
! |
|
149 |
||
489 | 150 |
addItemGroup:aGroup values:values |
151 |
groupSizes isNil ifTrue:[ |
|
152 |
groupSizes := OrderedCollection new |
|
153 |
]. |
|
154 |
groupSizes add:items size. |
|
155 |
||
156 |
aGroup with:values do:[:item :value | |
|
157 |
self addItem:item value:value |
|
158 |
]. |
|
159 |
! |
|
160 |
||
724 | 161 |
addItemGroupLabels:labels values:values |
162 |
|items| |
|
163 |
||
164 |
items := labels with:values |
|
165 |
collect:[:label :value | |
|
166 |
|item| |
|
167 |
||
168 |
item := MenuItem new. |
|
169 |
item label:label. |
|
170 |
item value:value. |
|
171 |
]. |
|
172 |
self addItemGroup:items |
|
173 |
||
174 |
"Created: / 27.10.1997 / 19:49:27 / cg" |
|
175 |
! |
|
176 |
||
177 |
addItemLabel:label value:value |
|
178 |
|item| |
|
179 |
||
180 |
item := MenuItem new. |
|
181 |
item label:label. |
|
182 |
item value:value. |
|
183 |
self addItem:item |
|
184 |
||
185 |
"Created: / 27.10.1997 / 19:47:12 / cg" |
|
186 |
! |
|
187 |
||
696 | 188 |
atNameKey:aNameKey |
724 | 189 |
"return the menuItem for the given nameKey; nil if no such item is in the menu. |
190 |
Searches in allItems (i.e. also in subMenus)" |
|
696 | 191 |
|
724 | 192 |
self allItemsDo:[:anItem| |
193 |
anItem nameKey == aNameKey ifTrue:[^ anItem] |
|
194 |
]. |
|
696 | 195 |
^ nil |
196 |
||
724 | 197 |
"Modified: / 27.10.1997 / 15:12:00 / cg" |
696 | 198 |
! |
199 |
||
578 | 200 |
groupSizes |
201 |
"return the value of the instance variable 'groupSizes' (automatically generated)" |
|
202 |
||
203 |
^ groupSizes! |
|
204 |
||
205 |
groupSizes:something |
|
206 |
"set the value of the instance variable 'groupSizes' (automatically generated)" |
|
207 |
||
208 |
groupSizes := something.! |
|
209 |
||
584 | 210 |
labelAt:anIndex |
211 |
"gets the label of the menu item at the given index or nil |
|
212 |
" |
|
213 |
|item| |
|
214 |
||
215 |
(item := self menuItemAt:anIndex) notNil ifTrue:[ |
|
216 |
^ item label |
|
217 |
]. |
|
218 |
^ nil |
|
219 |
||
220 |
! |
|
221 |
||
222 |
labelAtValue:aValue |
|
223 |
"gets the label of the menu item assigned to value |
|
224 |
" |
|
225 |
|item| |
|
226 |
||
227 |
item := self menuAndSubmenusDetectItem:[:anItem| anItem value == aValue ]. |
|
228 |
||
229 |
item notNil ifTrue:[ |
|
230 |
^ item label |
|
231 |
]. |
|
232 |
^ nil |
|
233 |
||
234 |
! |
|
235 |
||
451 | 236 |
labels |
237 |
"return a collection of labels from my items" |
|
238 |
||
239 |
^ items collect:[:anItem | anItem label] |
|
240 |
||
241 |
"Created: 25.2.1997 / 19:47:53 / cg" |
|
242 |
! |
|
243 |
||
489 | 244 |
lines |
737 | 245 |
"return the indexes of the menu items that are the last menu item in their group (except the very last)." |
489 | 246 |
|
579 | 247 |
| lines | |
737 | 248 |
|
579 | 249 |
groupSizes size <= 1 ifTrue: [^Array new]. |
250 |
lines := Array new: groupSizes size - 1. |
|
251 |
lines at: 1 put: groupSizes first. |
|
252 |
2 to: groupSizes size -1 do: |
|
253 |
[:i | |
|
254 |
lines at: i put: (lines at: i - 1) + (groupSizes at: i)]. |
|
255 |
^lines |
|
489 | 256 |
|
737 | 257 |
"Modified: / 31.10.1997 / 03:19:51 / cg" |
489 | 258 |
! |
259 |
||
260 |
menuItemAt:index |
|
584 | 261 |
"gets the menu item at the given index. When the index is out of bounds |
262 |
nil is returned |
|
263 |
" |
|
264 |
(index > 0 and:[index <= items size]) ifTrue:[ |
|
265 |
^ items at:index |
|
266 |
]. |
|
267 |
^ nil |
|
489 | 268 |
! |
269 |
||
724 | 270 |
menuItemLabeled:anItemLabel |
271 |
"return the menuItem for the given nameKey; nil if no such item is in the menu. |
|
272 |
Searches all items (i.e. also submenu items)" |
|
273 |
||
274 |
self allItemsDo:[:anItem| |
|
275 |
|l| |
|
276 |
||
277 |
((l := anItem label) sameAs: anItemLabel) ifTrue:[ |
|
278 |
^ anItem |
|
279 |
]. |
|
280 |
(l includes:$&) ifTrue:[ |
|
281 |
((l copyWithout:$&) sameAs: anItemLabel) ifTrue:[ |
|
282 |
^ anItem |
|
283 |
] |
|
284 |
] |
|
285 |
]. |
|
286 |
^ nil |
|
287 |
||
288 |
"Created: / 13.9.1997 / 10:25:16 / cg" |
|
289 |
"Modified: / 27.10.1997 / 15:23:33 / cg" |
|
290 |
! |
|
291 |
||
489 | 292 |
menuItems |
293 |
^ items |
|
294 |
! |
|
295 |
||
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
296 |
menuItems:aCollectionOfMenuItems menuItemGroups:sizes values:values |
451 | 297 |
items := aCollectionOfMenuItems. |
579 | 298 |
groupSizes := sizes. |
451 | 299 |
|
579 | 300 |
values notNil ifTrue:[ |
301 |
items with:values do:[:anItem :aValue |anItem value:aValue] |
|
454 | 302 |
]. |
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
303 |
|
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
304 |
"Modified: 20.6.1997 / 10:45:30 / cg" |
451 | 305 |
! |
306 |
||
494 | 307 |
numberOfItems |
308 |
^ items size |
|
309 |
||
310 |
"Created: 6.3.1997 / 15:15:53 / cg" |
|
311 |
! |
|
312 |
||
579 | 313 |
receiver |
314 |
"return the value of the instance variable 'receiver' (automatically generated)" |
|
315 |
||
316 |
^ receiver! |
|
317 |
||
318 |
receiver:something |
|
319 |
"set the value of the instance variable 'receiver' (automatically generated)" |
|
320 |
||
321 |
receiver := something.! |
|
322 |
||
696 | 323 |
removeItem:aMenuItem |
324 |
|idx| |
|
325 |
items notNil ifTrue:[ |
|
326 |
idx := items identityIndexOf:aMenuItem. |
|
327 |
idx ~~ 0 ifTrue:[ |
|
328 |
items removeAtIndex:idx |
|
329 |
] |
|
330 |
]. |
|
331 |
||
332 |
"Created: 13.9.1997 / 10:27:31 / cg" |
|
333 |
! |
|
334 |
||
451 | 335 |
valueAt:index |
336 |
"return a collection of values from my items" |
|
337 |
||
338 |
^ (items at:index) value |
|
339 |
||
340 |
"Created: 25.2.1997 / 19:49:41 / cg" |
|
341 |
! |
|
342 |
||
494 | 343 |
valueAt:anIndex put:aValue |
344 |
"put value an an index" |
|
345 |
||
346 |
(items at:anIndex) value:aValue |
|
347 |
||
348 |
"Created: 6.3.1997 / 15:15:48 / cg" |
|
349 |
! |
|
350 |
||
451 | 351 |
values |
352 |
"return a collection of values from my items" |
|
353 |
||
354 |
^ items collect:[:anItem | anItem value] |
|
355 |
||
356 |
"Created: 25.2.1997 / 19:49:29 / cg" |
|
724 | 357 |
! |
358 |
||
359 |
values:aCollectionOfValues |
|
360 |
"return a collection of values from my items" |
|
361 |
||
362 |
|s| |
|
363 |
||
364 |
s := aCollectionOfValues readStream. |
|
365 |
self itemsDo:[:item | |
|
366 |
|val| |
|
367 |
||
368 |
val := s next. |
|
369 |
item value:val |
|
370 |
]. |
|
371 |
s atEnd ifFalse:[self halt] |
|
372 |
||
373 |
"Created: / 27.10.1997 / 15:15:47 / cg" |
|
374 |
! |
|
375 |
||
376 |
visibleMenuItemGroups |
|
377 |
| itemGroups visibleItemGroups nextItem | |
|
378 |
||
379 |
itemGroups := OrderedCollection new. |
|
380 |
nextItem := 1. |
|
381 |
groupSizes do: [:groupSize | |
|
382 |
itemGroups addLast: (items copyFrom: nextItem to: nextItem + groupSize - 1). |
|
383 |
nextItem := nextItem + groupSize]. |
|
384 |
self hasHiddenItems ifFalse: [^itemGroups]. |
|
385 |
||
386 |
"Remove the hidden items." |
|
387 |
visibleItemGroups := OrderedCollection new. |
|
388 |
itemGroups do: [:eachItemGroup | |
|
389 |
| visibleItemGroup | |
|
390 |
visibleItemGroup := eachItemGroup reject: |
|
391 |
[:eachMenuItem | eachMenuItem hidden]. |
|
392 |
visibleItemGroup isEmpty ifFalse: [ |
|
393 |
visibleItemGroups addLast: visibleItemGroup]]. |
|
394 |
^visibleItemGroups |
|
395 |
||
396 |
"Created: / 27.10.1997 / 15:07:50 / cg" |
|
451 | 397 |
! ! |
398 |
||
582 | 399 |
!Menu methodsFor:'accessing resource'! |
400 |
||
584 | 401 |
findGuiResourcesIn:aResourceContainerOrApplication |
582 | 402 |
"setup a resource owner |
403 |
" |
|
584 | 404 |
aResourceContainerOrApplication notNil ifTrue:[ |
582 | 405 |
items notNil ifTrue:[ |
584 | 406 |
items do:[:anItem| anItem findGuiResourcesIn:aResourceContainerOrApplication ] |
582 | 407 |
] |
408 |
] |
|
409 |
||
410 |
! ! |
|
411 |
||
451 | 412 |
!Menu methodsFor:'converting'! |
413 |
||
414 |
fromLiteralArrayEncoding:aLiteralEncodedArray |
|
415 |
"read my contents from a aLiteralEncodedArray" |
|
416 |
||
417 |
|items groups values| |
|
418 |
||
419 |
items := (aLiteralEncodedArray at:2) collect:[:item | item decodeAsLiteralArray]. |
|
420 |
groups := aLiteralEncodedArray at:3. |
|
452 | 421 |
values := aLiteralEncodedArray at:4. |
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
422 |
self menuItems:items menuItemGroups:groups values:values. |
451 | 423 |
|
424 |
"extract from PD folder.st: |
|
425 |
#(#Menu #( |
|
426 |
#(#MenuItem |
|
427 |
#rawLabel: 'left' |
|
428 |
#value: #left ) |
|
429 |
#(#MenuItem |
|
430 |
#rawLabel: 'center' |
|
431 |
#value: #center ) |
|
432 |
#(#MenuItem |
|
433 |
#rawLabel: 'right' |
|
434 |
#value: #right ) |
|
435 |
) |
|
436 |
#(3 ) |
|
437 |
nil |
|
438 |
) decodeAsLiteralArray |
|
439 |
" |
|
452 | 440 |
" |
441 |
#(#Menu #( |
|
442 |
#(#MenuItem |
|
443 |
#label: 'Straighten Up' ) |
|
444 |
#(#MenuItem |
|
445 |
#label: 'Inspect' ) |
|
446 |
#(#MenuItem |
|
447 |
#label: 'Coredump' ) |
|
448 |
) |
|
449 |
#(3 ) |
|
450 |
#(#straightenUp #inspect #halt ) |
|
451 |
) decodeAsLiteralArray startUp |
|
452 |
" |
|
457 | 453 |
|
454 | 454 |
"extract from iconicBrowser.st: |
452 | 455 |
#(#Menu #( |
456 |
#(#MenuItem |
|
457 |
#label: 'Straighten Up' ) |
|
458 |
#(#MenuItem |
|
459 |
#label: 'Inspect' ) |
|
460 |
#(#MenuItem |
|
461 |
#label: 'Coredump' ) |
|
462 |
) |
|
463 |
#(3 ) |
|
464 |
#(1 2 3 ) |
|
465 |
) decodeAsLiteralArray startUp |
|
466 |
" |
|
451 | 467 |
|
454 | 468 |
"extract from refactory213.st: |
469 |
#(#Menu #( |
|
470 |
#(#MenuItem |
|
471 |
#label: 'File List' |
|
472 |
#accessCharacterPosition: 1 ) |
|
473 |
#(#MenuItem #label: 'File Editor...' |
|
474 |
#accessCharacterPosition: 6 ) |
|
475 |
#(#MenuItem #label: 'Refactoring Tool...' |
|
476 |
#accessCharacterPosition: 1 ) |
|
477 |
#(#MenuItem #label: 'Workspace' |
|
478 |
#accessCharacterPosition: 1 ) |
|
479 |
#(#MenuItem #label: 'New Canvas' |
|
480 |
#accessCharacterPosition: 1 ) |
|
481 |
#(#MenuItem #label: 'Palette' |
|
482 |
#accessCharacterPosition: 1 ) |
|
483 |
#(#MenuItem #label: 'Canvas Tool' |
|
484 |
#accessCharacterPosition: 1 ) |
|
485 |
#(#MenuItem #label: 'Image Editor' |
|
486 |
#accessCharacterPosition: 1 ) |
|
487 |
#(#MenuItem #label: 'Menu Editor' |
|
488 |
#accessCharacterPosition: 1 ) |
|
489 |
#(#MenuItem #label: 'Advanced' |
|
490 |
#accessCharacterPosition: 1 ) |
|
491 |
#(#MenuItem #label: 'DLL and C Connect' |
|
492 |
#accessCharacterPosition: 1 ) |
|
493 |
#(#MenuItem #label: 'System Transcript' |
|
494 |
#accessCharacterPosition: 8 ) |
|
495 |
) |
|
496 |
#(4 5 2 1 ) |
|
497 |
#(#openFileList #openFileEditor #openRefactoringTool #toolsNewWorkspace #toolsNewCanvas #toolsPalette #toolsCanvasTool #toolsMaskEditor #toolsMenuEditor nil #openExternalFinder #toggleSystemTranscript ) |
|
456 | 498 |
) decodeAsLiteralArray startUp |
454 | 499 |
" |
500 |
||
457 | 501 |
"submenus: |
502 |
#(#Menu #( |
|
503 |
#(#MenuItem |
|
504 |
#label: 'Foo' |
|
505 |
#submenu: #(#Menu #( |
|
506 |
#(#MenuItem #label: 'foo 1') |
|
507 |
#(#MenuItem #label: 'foo 2') |
|
508 |
) |
|
509 |
nil |
|
510 |
#(11 22) |
|
511 |
) |
|
512 |
) |
|
513 |
#(#MenuItem |
|
514 |
#label: 'Inspect' ) |
|
515 |
#(#MenuItem |
|
516 |
#label: 'Coredump' ) |
|
517 |
) |
|
518 |
#(3 ) |
|
519 |
#(1 2 3 ) |
|
520 |
) decodeAsLiteralArray startUp |
|
521 |
" |
|
522 |
||
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
523 |
"Modified: 20.6.1997 / 10:45:51 / cg" |
489 | 524 |
! |
525 |
||
526 |
literalArrayEncoding |
|
527 |
"return myself encoded as a literal array" |
|
528 |
||
529 |
|coll| |
|
530 |
||
531 |
coll := OrderedCollection new. |
|
532 |
coll add:#Menu. |
|
533 |
coll add:(items literalArrayEncoding). |
|
534 |
coll add:(groupSizes literalArrayEncoding). |
|
535 |
coll add:nil. |
|
579 | 536 |
^ coll asArray |
451 | 537 |
! ! |
538 |
||
584 | 539 |
!Menu methodsFor:'enumerating'! |
540 |
||
665 | 541 |
allItemsDo:aOneArgBlock |
542 |
"evaluate block on each item and submenu items |
|
543 |
" |
|
544 |
self itemsDo:[:anItem| |
|
724 | 545 |
|sub| |
546 |
||
665 | 547 |
aOneArgBlock value:anItem. |
724 | 548 |
(sub := anItem submenu value) notNil ifTrue:[ |
549 |
sub allItemsDo:aOneArgBlock |
|
665 | 550 |
] |
551 |
] |
|
724 | 552 |
|
553 |
"Modified: / 27.10.1997 / 15:09:08 / cg" |
|
665 | 554 |
! |
555 |
||
589 | 556 |
itemsDo:aOneArgBlock |
557 |
"evaluate the block for each item in the current menu |
|
558 |
" |
|
559 |
items notNil ifTrue:[items do:aOneArgBlock] |
|
560 |
! |
|
561 |
||
584 | 562 |
menuAndSubmenusDetectItem:aOneArgBlock |
563 |
"evaluate the block for each item in the current menu and all |
|
564 |
submenus. In case that the block returns a non nil argument, |
|
565 |
the item will be returned |
|
566 |
" |
|
724 | 567 |
|item| |
584 | 568 |
|
569 |
items notNil ifTrue:[ |
|
570 |
items do:[:anItem| |
|
724 | 571 |
|sub| |
572 |
||
627 | 573 |
(aOneArgBlock value:anItem) ifTrue:[ |
584 | 574 |
^ anItem |
575 |
]. |
|
724 | 576 |
(sub := anItem submenu value) notNil ifTrue:[ |
577 |
item := sub menuAndSubmenusDetectItem:aOneArgBlock. |
|
584 | 578 |
item notNil ifTrue:[ |
579 |
^ item |
|
580 |
] |
|
581 |
] |
|
582 |
] |
|
583 |
]. |
|
724 | 584 |
^ nil |
585 |
||
586 |
"Modified: / 27.10.1997 / 15:09:43 / cg" |
|
584 | 587 |
! ! |
588 |
||
672
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
589 |
!Menu methodsFor:'kludged fixes'! |
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
590 |
|
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
591 |
destroy |
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
592 |
|
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
593 |
"Created: 28.7.1997 / 10:16:52 / cg" |
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
594 |
! ! |
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
595 |
|
584 | 596 |
!Menu methodsFor:'menu items'! |
597 |
||
598 |
someMenuItemWithValue:aValue |
|
599 |
"get the menu item assigned with the value; in case that the value |
|
600 |
is not found nil is returned |
|
601 |
" |
|
602 |
^ self someMenuItemWithValue:aValue ifNone:nil |
|
603 |
! |
|
604 |
||
605 |
someMenuItemWithValue:aValue ifNone:exceptionBlock |
|
606 |
"get the menu item assigned with the value; in case that the value |
|
607 |
is not found, the given exceptionBlock is executed and returned |
|
608 |
" |
|
609 |
|item| |
|
610 |
||
611 |
item := self menuAndSubmenusDetectItem:[:anItem| anItem value == aValue]. |
|
612 |
||
613 |
item notNil ifTrue:[ |
|
614 |
^ item |
|
615 |
]. |
|
616 |
^ exceptionBlock value |
|
617 |
! ! |
|
618 |
||
619 |
!Menu methodsFor:'queries'! |
|
620 |
||
724 | 621 |
hasHiddenItems |
622 |
"test whether any item is hidden" |
|
623 |
||
624 |
self allItemsDo:[:anItem| |
|
625 |
anItem isHidden ifTrue:[^ true] |
|
626 |
]. |
|
627 |
^ false |
|
628 |
||
629 |
"Modified: / 27.10.1997 / 15:12:44 / cg" |
|
630 |
! |
|
631 |
||
584 | 632 |
hasSubMenuAt:anIndex |
633 |
"test whether the menu item at the given index has a submenu |
|
634 |
" |
|
635 |
^ (self menuItemAt:anIndex) hasSubmenu |
|
636 |
! ! |
|
637 |
||
451 | 638 |
!Menu methodsFor:'startup'! |
639 |
||
729 | 640 |
show |
641 |
"realize the menu at its last position; returns the value associated with the |
|
642 |
selected item, 0 if none was selected" |
|
643 |
||
644 |
^ (MenuPanel menu:self) show ? 0 |
|
645 |
||
646 |
||
647 |
! |
|
648 |
||
649 |
showAt:aPoint |
|
650 |
"realize the menu at aPoint; returns the value associated with the |
|
651 |
selected item, 0 if none was selected" |
|
652 |
||
653 |
^ self showAt:aPoint resizing:true |
|
654 |
||
655 |
||
656 |
! |
|
657 |
||
658 |
showAt:aPoint resizing:aBoolean |
|
659 |
"realize the menu at aPoint; returns the value associated with the |
|
451 | 660 |
selected item, 0 if none was selected" |
661 |
||
729 | 662 |
^ (MenuPanel menu:self) showAt:aPoint resizing:aBoolean ? 0 |
663 |
! |
|
664 |
||
665 |
showAtPointer |
|
666 |
"realize the menu at the current pointer position; returns the value associated with the |
|
667 |
selected item, 0 if none was selected" |
|
668 |
||
669 |
^ self startUp |
|
670 |
! |
|
457 | 671 |
|
729 | 672 |
showCenteredIn:aView |
673 |
"realize the menu visible at the aView center; returns the value associated with the |
|
674 |
selected item, 0 if none was selected" |
|
675 |
||
676 |
^ (MenuPanel menu:self) showCenteredIn:aView ? 0 |
|
677 |
||
678 |
||
679 |
! |
|
680 |
||
681 |
startUp |
|
682 |
"display the menu as a popUp; returns the value associated with the |
|
683 |
selected item, 0 if none was selected" |
|
684 |
||
685 |
^ (MenuPanel menu:self) startUp ? 0 |
|
451 | 686 |
|
579 | 687 |
" |
451 | 688 |
|m| |
579 | 689 |
|
451 | 690 |
m := #(#Menu #( |
691 |
#(#MenuItem |
|
692 |
#rawLabel: 'left' |
|
693 |
#value: #left ) |
|
694 |
#(#MenuItem |
|
695 |
#rawLabel: 'center' |
|
696 |
#value: #center ) |
|
697 |
#(#MenuItem |
|
698 |
#rawLabel: 'right' |
|
699 |
#value: #right ) ) |
|
579 | 700 |
#(2) |
451 | 701 |
nil |
702 |
) decodeAsLiteralArray. |
|
703 |
||
579 | 704 |
Transcript showCR:(m startUp) |
705 |
" |
|
451 | 706 |
! ! |
707 |
||
708 |
!Menu class methodsFor:'documentation'! |
|
709 |
||
710 |
version |
|
737 | 711 |
^ '$Header: /cvs/stx/stx/libview2/Menu.st,v 1.21 1997-11-03 15:33:51 cg Exp $' |
451 | 712 |
! ! |