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