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