author | Claus Gittinger <cg@exept.de> |
Sat, 15 Nov 1997 15:22:24 +0100 | |
changeset 740 | 4f45cc61d4e0 |
parent 739 | 3a1354a9f3a2 |
child 759 | 405baa7e92d4 |
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:] |
|
740 | 19 |
Claus Gittinger |
451 | 20 |
|
21 |
[see also:] |
|
740 | 22 |
MenuItem |
23 |
PopUpMenu |
|
451 | 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:[ |
740 | 40 |
(valueArray := arrayOfString isEmpty) ifTrue: [ |
41 |
valueArray := #() |
|
42 |
] ifFalse:[ |
|
43 |
valueArray := (1 to:nLabel) |
|
44 |
] |
|
737 | 45 |
] ifFalse:[ |
740 | 46 |
valueArray := valueArrayOrNil |
737 | 47 |
]. |
48 |
||
49 |
nLabel ~~ valueArray size ifTrue: [ |
|
740 | 50 |
^ self error: 'illegal menu combination' |
737 | 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 | |
|
740 | 55 |
|mi v| |
737 | 56 |
|
740 | 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 |
|
737 | 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:[ |
740 | 64 |
groupLengths := (menuItems isEmpty) |
65 |
ifTrue: [Array new: 0] |
|
66 |
ifFalse: [Array with: menuItems size] |
|
737 | 67 |
] ifFalse:[ |
740 | 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 |
|
737 | 74 |
]. |
75 |
||
76 |
^ self new |
|
740 | 77 |
menuItems: menuItems |
78 |
menuItemGroups: groupLengths |
|
79 |
values: valueArray |
|
737 | 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 |
740 | 98 |
labelArray:(aString asCollectionOfLines) |
99 |
lines:linesArray |
|
100 |
values:valueArrayOrNil |
|
737 | 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:[ |
740 | 128 |
items := OrderedCollection new |
489 | 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:[ |
|
740 | 140 |
groupSizes := OrderedCollection new |
724 | 141 |
]. |
142 |
groupSizes add:aCollectionOfItems size. |
|
143 |
||
144 |
aCollectionOfItems do:[:item | |
|
740 | 145 |
self addItem:item |
724 | 146 |
]. |
147 |
||
148 |
"Created: / 27.10.1997 / 15:02:15 / cg" |
|
149 |
! |
|
150 |
||
489 | 151 |
addItemGroup:aGroup values:values |
152 |
groupSizes isNil ifTrue:[ |
|
740 | 153 |
groupSizes := OrderedCollection new |
489 | 154 |
]. |
155 |
groupSizes add:items size. |
|
156 |
||
157 |
aGroup with:values do:[:item :value | |
|
740 | 158 |
self addItem:item value:value |
489 | 159 |
]. |
160 |
! |
|
161 |
||
724 | 162 |
addItemGroupLabels:labels values:values |
163 |
|items| |
|
164 |
||
165 |
items := labels with:values |
|
740 | 166 |
collect:[:label :value | |
167 |
|item| |
|
724 | 168 |
|
740 | 169 |
item := MenuItem new. |
170 |
item label:label. |
|
171 |
item value:value. |
|
172 |
]. |
|
724 | 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| |
740 | 194 |
anItem nameKey == aNameKey ifTrue:[^ anItem] |
724 | 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:[ |
|
740 | 217 |
^ item label |
584 | 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:[ |
|
740 | 231 |
^ item label |
584 | 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: |
|
740 | 254 |
[:i | |
255 |
lines at: i put: (lines at: i - 1) + (groupSizes at: i)]. |
|
579 | 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:[ |
|
740 | 266 |
^ items at:index |
584 | 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| |
|
740 | 276 |
|l| |
724 | 277 |
|
740 | 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 |
]. |
|
724 | 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:[ |
740 | 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:[ |
|
740 | 327 |
idx := items identityIndexOf:aMenuItem. |
328 |
idx ~~ 0 ifTrue:[ |
|
329 |
items removeAtIndex:idx |
|
330 |
] |
|
696 | 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 | |
|
740 | 367 |
|val| |
724 | 368 |
|
740 | 369 |
val := s next. |
370 |
item value:val |
|
724 | 371 |
]. |
372 |
s atEnd ifFalse:[self halt] |
|
373 |
||
374 |
"Created: / 27.10.1997 / 15:15:47 / cg" |
|
375 |
! |
|
376 |
||
377 |
visibleMenuItemGroups |
|
740 | 378 |
| itemGroups visibleItemGroups nextItem | |
724 | 379 |
|
740 | 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]. |
|
724 | 386 |
|
740 | 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 |
|
724 | 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:[ |
740 | 406 |
items notNil ifTrue:[ |
407 |
items do:[:anItem| anItem findGuiResourcesIn:aResourceContainerOrApplication ] |
|
408 |
] |
|
582 | 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 #( |
|
740 | 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 |
|
451 | 439 |
) decodeAsLiteralArray |
440 |
" |
|
452 | 441 |
" |
442 |
#(#Menu #( |
|
740 | 443 |
#(#MenuItem |
444 |
#label: 'Straighten Up' ) |
|
445 |
#(#MenuItem |
|
446 |
#label: 'Inspect' ) |
|
447 |
#(#MenuItem |
|
448 |
#label: 'Coredump' ) |
|
449 |
) |
|
450 |
#(3 ) |
|
451 |
#(#straightenUp #inspect #halt ) |
|
452 | 452 |
) decodeAsLiteralArray startUp |
453 |
" |
|
457 | 454 |
|
454 | 455 |
"extract from iconicBrowser.st: |
452 | 456 |
#(#Menu #( |
740 | 457 |
#(#MenuItem |
458 |
#label: 'Straighten Up' ) |
|
459 |
#(#MenuItem |
|
460 |
#label: 'Inspect' ) |
|
461 |
#(#MenuItem |
|
462 |
#label: 'Coredump' ) |
|
463 |
) |
|
464 |
#(3 ) |
|
465 |
#(1 2 3 ) |
|
452 | 466 |
) decodeAsLiteralArray startUp |
467 |
" |
|
451 | 468 |
|
454 | 469 |
"extract from refactory213.st: |
470 |
#(#Menu #( |
|
740 | 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 ) |
|
499 |
) decodeAsLiteralArray startUp |
|
454 | 500 |
" |
501 |
||
457 | 502 |
"submenus: |
503 |
#(#Menu #( |
|
740 | 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 ) |
|
457 | 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| |
|
740 | 546 |
|sub| |
724 | 547 |
|
740 | 548 |
aOneArgBlock value:anItem. |
549 |
(sub := anItem submenu value) notNil ifTrue:[ |
|
550 |
sub allItemsDo:aOneArgBlock |
|
551 |
] |
|
665 | 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:[ |
|
740 | 571 |
items do:[:anItem| |
572 |
|sub| |
|
724 | 573 |
|
740 | 574 |
(aOneArgBlock value:anItem) ifTrue:[ |
575 |
^ anItem |
|
576 |
]. |
|
577 |
(sub := anItem submenu value) notNil ifTrue:[ |
|
578 |
item := sub menuAndSubmenusDetectItem:aOneArgBlock. |
|
579 |
item notNil ifTrue:[ |
|
580 |
^ item |
|
581 |
] |
|
582 |
] |
|
583 |
] |
|
584 | 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 |
||
740 | 599 |
someMenuItemLabeled:aLabel |
600 |
"get the menu item with that label; in case that the label |
|
601 |
is not found, nil is returned |
|
602 |
" |
|
603 |
^ self someMenuItemLabeled:aLabel ifNone:nil |
|
604 |
||
605 |
"Created: / 14.11.1997 / 20:55:17 / cg" |
|
606 |
! |
|
607 |
||
608 |
someMenuItemLabeled:aLabel ifNone:exceptionBlock |
|
609 |
"get the menu item labeled aLabel; in case that the value |
|
610 |
is not found, the given exceptionBlock is executed and its value returned |
|
611 |
" |
|
612 |
|item| |
|
613 |
||
614 |
item := self menuAndSubmenusDetectItem:[:anItem| anItem label = aLabel]. |
|
615 |
||
616 |
item notNil ifTrue:[ |
|
617 |
^ item |
|
618 |
]. |
|
619 |
^ exceptionBlock value |
|
620 |
||
621 |
"Created: / 14.11.1997 / 20:56:13 / cg" |
|
622 |
! |
|
623 |
||
584 | 624 |
someMenuItemWithValue:aValue |
625 |
"get the menu item assigned with the value; in case that the value |
|
626 |
is not found nil is returned |
|
627 |
" |
|
628 |
^ self someMenuItemWithValue:aValue ifNone:nil |
|
629 |
! |
|
630 |
||
631 |
someMenuItemWithValue:aValue ifNone:exceptionBlock |
|
632 |
"get the menu item assigned with the value; in case that the value |
|
633 |
is not found, the given exceptionBlock is executed and returned |
|
634 |
" |
|
635 |
|item| |
|
636 |
||
637 |
item := self menuAndSubmenusDetectItem:[:anItem| anItem value == aValue]. |
|
638 |
||
639 |
item notNil ifTrue:[ |
|
740 | 640 |
^ item |
584 | 641 |
]. |
642 |
^ exceptionBlock value |
|
643 |
! ! |
|
644 |
||
645 |
!Menu methodsFor:'queries'! |
|
646 |
||
724 | 647 |
hasHiddenItems |
648 |
"test whether any item is hidden" |
|
649 |
||
650 |
self allItemsDo:[:anItem| |
|
740 | 651 |
anItem isHidden ifTrue:[^ true] |
724 | 652 |
]. |
653 |
^ false |
|
654 |
||
655 |
"Modified: / 27.10.1997 / 15:12:44 / cg" |
|
656 |
! |
|
657 |
||
584 | 658 |
hasSubMenuAt:anIndex |
659 |
"test whether the menu item at the given index has a submenu |
|
660 |
" |
|
661 |
^ (self menuItemAt:anIndex) hasSubmenu |
|
662 |
! ! |
|
663 |
||
451 | 664 |
!Menu methodsFor:'startup'! |
665 |
||
729 | 666 |
show |
667 |
"realize the menu at its last position; returns the value associated with the |
|
668 |
selected item, 0 if none was selected" |
|
669 |
||
670 |
^ (MenuPanel menu:self) show ? 0 |
|
671 |
||
672 |
||
673 |
! |
|
674 |
||
675 |
showAt:aPoint |
|
676 |
"realize the menu at aPoint; returns the value associated with the |
|
677 |
selected item, 0 if none was selected" |
|
678 |
||
679 |
^ self showAt:aPoint resizing:true |
|
680 |
||
681 |
||
682 |
! |
|
683 |
||
684 |
showAt:aPoint resizing:aBoolean |
|
685 |
"realize the menu at aPoint; returns the value associated with the |
|
451 | 686 |
selected item, 0 if none was selected" |
687 |
||
729 | 688 |
^ (MenuPanel menu:self) showAt:aPoint resizing:aBoolean ? 0 |
689 |
! |
|
690 |
||
691 |
showAtPointer |
|
692 |
"realize the menu at the current pointer position; returns the value associated with the |
|
693 |
selected item, 0 if none was selected" |
|
694 |
||
695 |
^ self startUp |
|
696 |
! |
|
457 | 697 |
|
729 | 698 |
showCenteredIn:aView |
699 |
"realize the menu visible at the aView center; returns the value associated with the |
|
700 |
selected item, 0 if none was selected" |
|
701 |
||
702 |
^ (MenuPanel menu:self) showCenteredIn:aView ? 0 |
|
703 |
||
704 |
||
705 |
! |
|
706 |
||
707 |
startUp |
|
708 |
"display the menu as a popUp; returns the value associated with the |
|
709 |
selected item, 0 if none was selected" |
|
710 |
||
711 |
^ (MenuPanel menu:self) startUp ? 0 |
|
451 | 712 |
|
579 | 713 |
" |
740 | 714 |
|m| |
579 | 715 |
|
740 | 716 |
m := #(#Menu #( |
717 |
#(#MenuItem |
|
718 |
#rawLabel: 'left' |
|
719 |
#value: #left ) |
|
720 |
#(#MenuItem |
|
721 |
#rawLabel: 'center' |
|
722 |
#value: #center ) |
|
723 |
#(#MenuItem |
|
724 |
#rawLabel: 'right' |
|
725 |
#value: #right ) ) |
|
726 |
#(2) |
|
727 |
nil |
|
728 |
) decodeAsLiteralArray. |
|
451 | 729 |
|
579 | 730 |
Transcript showCR:(m startUp) |
731 |
" |
|
451 | 732 |
! ! |
733 |
||
734 |
!Menu class methodsFor:'documentation'! |
|
735 |
||
736 |
version |
|
740 | 737 |
^ '$Header: /cvs/stx/stx/libview2/Menu.st,v 1.24 1997-11-15 14:22:24 cg Exp $' |
451 | 738 |
! ! |