author | Claus Gittinger <cg@exept.de> |
Mon, 15 Sep 1997 22:25:21 +0200 | |
changeset 696 | a49928754789 |
parent 679 | 0f94c493751c |
child 724 | 898519684261 |
permissions | -rw-r--r-- |
696 | 1 |
'From Smalltalk/X, Version:3.1.10 on 13-sep-1997 at 10:55:54 pm' ! |
2 |
||
451 | 3 |
Object subclass:#Menu |
579 | 4 |
instanceVariableNames:'items groupSizes receiver' |
451 | 5 |
classVariableNames:'' |
6 |
poolDictionaries:'' |
|
7 |
category:'Views-Support' |
|
8 |
! |
|
9 |
||
10 |
!Menu class methodsFor:'documentation'! |
|
11 |
||
12 |
documentation |
|
13 |
" |
|
14 |
not yet finished Menu class - this will eventually replace |
|
15 |
most of the MenuView and PopUpMenu stuff. |
|
16 |
(and hopefully be ST-80 compatible ...) |
|
17 |
||
18 |
For now, only a subset of the full protocol is implemented. |
|
19 |
||
20 |
[author:] |
|
21 |
Claus Gittinger |
|
22 |
||
23 |
[see also:] |
|
24 |
MenuItem |
|
25 |
PopUpMenu |
|
26 |
" |
|
27 |
! ! |
|
28 |
||
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
29 |
!Menu class methodsFor:'instance creation'! |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
30 |
|
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
31 |
labelArray: arrayOfString lines: linesArray values: valueArrayOrNil |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
32 |
"Answer a menu with menu items with labels from arrayOfString (not Symbols). The linesArray describes which menu items are the last menu item in their group. The valueArray contains value objects for each menu item (or is nil if no value objects are specified)." |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
33 |
|
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
34 |
| valueArray menuItems groupLengths | |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
35 |
valueArrayOrNil isNil |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
36 |
ifTrue: [valueArray := arrayOfString isEmpty |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
37 |
ifTrue: [#()] |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
38 |
ifFalse: [1 to: arrayOfString size]] |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
39 |
ifFalse: [valueArray := valueArrayOrNil]. |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
40 |
arrayOfString size ~= valueArray size |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
41 |
ifTrue: [^self error: 'illegal menu combination']. |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
42 |
|
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
43 |
menuItems := Array new: arrayOfString size. |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
44 |
1 to: arrayOfString size do: |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
45 |
[:i | |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
46 |
| mi v| |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
47 |
mi := MenuItem labeled: (arrayOfString at: i) asString. |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
48 |
v := valueArray at: i. |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
49 |
(v isKindOf: Menu) |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
50 |
ifTrue: [mi submenu: v]. |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
51 |
menuItems at: i put: mi]. |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
52 |
(linesArray == nil or: [linesArray isEmpty]) |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
53 |
ifTrue: [ |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
54 |
groupLengths := (menuItems isEmpty) |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
55 |
ifTrue: [Array new: 0] |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
56 |
ifFalse: [Array with: menuItems size]] |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
57 |
ifFalse: [groupLengths := Array new: linesArray size + 1. |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
58 |
groupLengths at: 1 put: linesArray first. |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
59 |
2 to: linesArray size do: [:i | groupLengths at: i put: (linesArray at: i) - (linesArray at: i - 1)]. |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
60 |
groupLengths at: groupLengths size put: menuItems size - linesArray last]. |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
61 |
^self new menuItems: menuItems menuItemGroups: groupLengths values: valueArray |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
62 |
|
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
63 |
"Modified: 20.6.1997 / 10:46:45 / cg" |
696 | 64 |
! |
65 |
||
66 |
labelList:arrayOfGroupStrings values:valueArrayOrNil |
|
67 |
|labels lines| |
|
68 |
||
69 |
lines := arrayOfGroupStrings collect:[:each | each size]. |
|
70 |
labels := OrderedCollection new. |
|
71 |
arrayOfGroupStrings do:[:group | labels addAll:group]. |
|
72 |
^ self labelArray:labels lines:lines values:valueArrayOrNil |
|
73 |
||
74 |
"Modified: 20.6.1997 / 10:46:45 / cg" |
|
75 |
"Created: 13.9.1997 / 10:35:46 / cg" |
|
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
76 |
! ! |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
77 |
|
451 | 78 |
!Menu methodsFor:'accessing'! |
79 |
||
589 | 80 |
addItem:aMenuItem |
489 | 81 |
items isNil ifTrue:[ |
82 |
items := OrderedCollection new |
|
83 |
]. |
|
84 |
items add:aMenuItem. |
|
589 | 85 |
! |
86 |
||
87 |
addItem:aMenuItem value:aValue |
|
88 |
aMenuItem value:aValue. |
|
89 |
self addItem:aMenuItem. |
|
489 | 90 |
! |
91 |
||
92 |
addItemGroup:aGroup values:values |
|
93 |
groupSizes isNil ifTrue:[ |
|
94 |
groupSizes := OrderedCollection new |
|
95 |
]. |
|
96 |
groupSizes add:items size. |
|
97 |
||
98 |
aGroup with:values do:[:item :value | |
|
99 |
self addItem:item value:value |
|
100 |
]. |
|
101 |
! |
|
102 |
||
696 | 103 |
atNameKey:aNameKey |
104 |
"return the menuItem for the given nameKey; nil if no such item is in the menu." |
|
105 |
||
106 |
items do:[:anItem | anItem nameKey == aNameKey ifTrue:[^ anItem]]. |
|
107 |
^ nil |
|
108 |
||
109 |
"Created: 13.9.1997 / 10:25:16 / cg" |
|
110 |
"Modified: 13.9.1997 / 10:28:44 / cg" |
|
111 |
! |
|
112 |
||
578 | 113 |
groupSizes |
114 |
"return the value of the instance variable 'groupSizes' (automatically generated)" |
|
115 |
||
116 |
^ groupSizes! |
|
117 |
||
118 |
groupSizes:something |
|
119 |
"set the value of the instance variable 'groupSizes' (automatically generated)" |
|
120 |
||
121 |
groupSizes := something.! |
|
122 |
||
584 | 123 |
labelAt:anIndex |
124 |
"gets the label of the menu item at the given index or nil |
|
125 |
" |
|
126 |
|item| |
|
127 |
||
128 |
(item := self menuItemAt:anIndex) notNil ifTrue:[ |
|
129 |
^ item label |
|
130 |
]. |
|
131 |
^ nil |
|
132 |
||
133 |
! |
|
134 |
||
135 |
labelAtValue:aValue |
|
136 |
"gets the label of the menu item assigned to value |
|
137 |
" |
|
138 |
|item| |
|
139 |
||
140 |
item := self menuAndSubmenusDetectItem:[:anItem| anItem value == aValue ]. |
|
141 |
||
142 |
item notNil ifTrue:[ |
|
143 |
^ item label |
|
144 |
]. |
|
145 |
^ nil |
|
146 |
||
147 |
! |
|
148 |
||
451 | 149 |
labels |
150 |
"return a collection of labels from my items" |
|
151 |
||
152 |
^ items collect:[:anItem | anItem label] |
|
153 |
||
154 |
"Created: 25.2.1997 / 19:47:53 / cg" |
|
155 |
! |
|
156 |
||
489 | 157 |
lines |
579 | 158 |
"Answer the indexes of the menu items that are the last menu item in their group (except the very last)." |
489 | 159 |
|
579 | 160 |
| lines | |
161 |
groupSizes size <= 1 ifTrue: [^Array new]. |
|
162 |
lines := Array new: groupSizes size - 1. |
|
163 |
lines at: 1 put: groupSizes first. |
|
164 |
2 to: groupSizes size -1 do: |
|
165 |
[:i | |
|
166 |
lines at: i put: (lines at: i - 1) + (groupSizes at: i)]. |
|
167 |
^lines |
|
489 | 168 |
|
169 |
||
170 |
! |
|
171 |
||
172 |
menuItemAt:index |
|
584 | 173 |
"gets the menu item at the given index. When the index is out of bounds |
174 |
nil is returned |
|
175 |
" |
|
176 |
(index > 0 and:[index <= items size]) ifTrue:[ |
|
177 |
^ items at:index |
|
178 |
]. |
|
179 |
^ nil |
|
489 | 180 |
! |
181 |
||
182 |
menuItems |
|
183 |
^ items |
|
184 |
! |
|
185 |
||
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
186 |
menuItems:aCollectionOfMenuItems menuItemGroups:sizes values:values |
451 | 187 |
items := aCollectionOfMenuItems. |
579 | 188 |
groupSizes := sizes. |
451 | 189 |
|
579 | 190 |
values notNil ifTrue:[ |
191 |
items with:values do:[:anItem :aValue |anItem value:aValue] |
|
454 | 192 |
]. |
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
193 |
|
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
194 |
"Modified: 20.6.1997 / 10:45:30 / cg" |
451 | 195 |
! |
196 |
||
494 | 197 |
numberOfItems |
198 |
^ items size |
|
199 |
||
200 |
"Created: 6.3.1997 / 15:15:53 / cg" |
|
201 |
! |
|
202 |
||
579 | 203 |
receiver |
204 |
"return the value of the instance variable 'receiver' (automatically generated)" |
|
205 |
||
206 |
^ receiver! |
|
207 |
||
208 |
receiver:something |
|
209 |
"set the value of the instance variable 'receiver' (automatically generated)" |
|
210 |
||
211 |
receiver := something.! |
|
212 |
||
696 | 213 |
removeItem:aMenuItem |
214 |
|idx| |
|
215 |
items notNil ifTrue:[ |
|
216 |
idx := items identityIndexOf:aMenuItem. |
|
217 |
idx ~~ 0 ifTrue:[ |
|
218 |
items removeAtIndex:idx |
|
219 |
] |
|
220 |
]. |
|
221 |
||
222 |
"Created: 13.9.1997 / 10:27:31 / cg" |
|
223 |
! |
|
224 |
||
451 | 225 |
valueAt:index |
226 |
"return a collection of values from my items" |
|
227 |
||
228 |
^ (items at:index) value |
|
229 |
||
230 |
"Created: 25.2.1997 / 19:49:41 / cg" |
|
231 |
! |
|
232 |
||
494 | 233 |
valueAt:anIndex put:aValue |
234 |
"put value an an index" |
|
235 |
||
236 |
(items at:anIndex) value:aValue |
|
237 |
||
238 |
"Created: 6.3.1997 / 15:15:48 / cg" |
|
239 |
! |
|
240 |
||
451 | 241 |
values |
242 |
"return a collection of values from my items" |
|
243 |
||
244 |
^ items collect:[:anItem | anItem value] |
|
245 |
||
246 |
"Created: 25.2.1997 / 19:49:29 / cg" |
|
247 |
! ! |
|
248 |
||
582 | 249 |
!Menu methodsFor:'accessing resource'! |
250 |
||
584 | 251 |
findGuiResourcesIn:aResourceContainerOrApplication |
582 | 252 |
"setup a resource owner |
253 |
" |
|
584 | 254 |
aResourceContainerOrApplication notNil ifTrue:[ |
582 | 255 |
items notNil ifTrue:[ |
584 | 256 |
items do:[:anItem| anItem findGuiResourcesIn:aResourceContainerOrApplication ] |
582 | 257 |
] |
258 |
] |
|
259 |
||
260 |
! ! |
|
261 |
||
451 | 262 |
!Menu methodsFor:'converting'! |
263 |
||
264 |
fromLiteralArrayEncoding:aLiteralEncodedArray |
|
265 |
"read my contents from a aLiteralEncodedArray" |
|
266 |
||
267 |
|items groups values| |
|
268 |
||
269 |
items := (aLiteralEncodedArray at:2) collect:[:item | item decodeAsLiteralArray]. |
|
270 |
groups := aLiteralEncodedArray at:3. |
|
452 | 271 |
values := aLiteralEncodedArray at:4. |
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
272 |
self menuItems:items menuItemGroups:groups values:values. |
451 | 273 |
|
274 |
"extract from PD folder.st: |
|
275 |
#(#Menu #( |
|
276 |
#(#MenuItem |
|
277 |
#rawLabel: 'left' |
|
278 |
#value: #left ) |
|
279 |
#(#MenuItem |
|
280 |
#rawLabel: 'center' |
|
281 |
#value: #center ) |
|
282 |
#(#MenuItem |
|
283 |
#rawLabel: 'right' |
|
284 |
#value: #right ) |
|
285 |
) |
|
286 |
#(3 ) |
|
287 |
nil |
|
288 |
) decodeAsLiteralArray |
|
289 |
" |
|
452 | 290 |
" |
291 |
#(#Menu #( |
|
292 |
#(#MenuItem |
|
293 |
#label: 'Straighten Up' ) |
|
294 |
#(#MenuItem |
|
295 |
#label: 'Inspect' ) |
|
296 |
#(#MenuItem |
|
297 |
#label: 'Coredump' ) |
|
298 |
) |
|
299 |
#(3 ) |
|
300 |
#(#straightenUp #inspect #halt ) |
|
301 |
) decodeAsLiteralArray startUp |
|
302 |
" |
|
457 | 303 |
|
454 | 304 |
"extract from iconicBrowser.st: |
452 | 305 |
#(#Menu #( |
306 |
#(#MenuItem |
|
307 |
#label: 'Straighten Up' ) |
|
308 |
#(#MenuItem |
|
309 |
#label: 'Inspect' ) |
|
310 |
#(#MenuItem |
|
311 |
#label: 'Coredump' ) |
|
312 |
) |
|
313 |
#(3 ) |
|
314 |
#(1 2 3 ) |
|
315 |
) decodeAsLiteralArray startUp |
|
316 |
" |
|
451 | 317 |
|
454 | 318 |
"extract from refactory213.st: |
319 |
#(#Menu #( |
|
320 |
#(#MenuItem |
|
321 |
#label: 'File List' |
|
322 |
#accessCharacterPosition: 1 ) |
|
323 |
#(#MenuItem #label: 'File Editor...' |
|
324 |
#accessCharacterPosition: 6 ) |
|
325 |
#(#MenuItem #label: 'Refactoring Tool...' |
|
326 |
#accessCharacterPosition: 1 ) |
|
327 |
#(#MenuItem #label: 'Workspace' |
|
328 |
#accessCharacterPosition: 1 ) |
|
329 |
#(#MenuItem #label: 'New Canvas' |
|
330 |
#accessCharacterPosition: 1 ) |
|
331 |
#(#MenuItem #label: 'Palette' |
|
332 |
#accessCharacterPosition: 1 ) |
|
333 |
#(#MenuItem #label: 'Canvas Tool' |
|
334 |
#accessCharacterPosition: 1 ) |
|
335 |
#(#MenuItem #label: 'Image Editor' |
|
336 |
#accessCharacterPosition: 1 ) |
|
337 |
#(#MenuItem #label: 'Menu Editor' |
|
338 |
#accessCharacterPosition: 1 ) |
|
339 |
#(#MenuItem #label: 'Advanced' |
|
340 |
#accessCharacterPosition: 1 ) |
|
341 |
#(#MenuItem #label: 'DLL and C Connect' |
|
342 |
#accessCharacterPosition: 1 ) |
|
343 |
#(#MenuItem #label: 'System Transcript' |
|
344 |
#accessCharacterPosition: 8 ) |
|
345 |
) |
|
346 |
#(4 5 2 1 ) |
|
347 |
#(#openFileList #openFileEditor #openRefactoringTool #toolsNewWorkspace #toolsNewCanvas #toolsPalette #toolsCanvasTool #toolsMaskEditor #toolsMenuEditor nil #openExternalFinder #toggleSystemTranscript ) |
|
456 | 348 |
) decodeAsLiteralArray startUp |
454 | 349 |
" |
350 |
||
457 | 351 |
"submenus: |
352 |
#(#Menu #( |
|
353 |
#(#MenuItem |
|
354 |
#label: 'Foo' |
|
355 |
#submenu: #(#Menu #( |
|
356 |
#(#MenuItem #label: 'foo 1') |
|
357 |
#(#MenuItem #label: 'foo 2') |
|
358 |
) |
|
359 |
nil |
|
360 |
#(11 22) |
|
361 |
) |
|
362 |
) |
|
363 |
#(#MenuItem |
|
364 |
#label: 'Inspect' ) |
|
365 |
#(#MenuItem |
|
366 |
#label: 'Coredump' ) |
|
367 |
) |
|
368 |
#(3 ) |
|
369 |
#(1 2 3 ) |
|
370 |
) decodeAsLiteralArray startUp |
|
371 |
" |
|
372 |
||
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
373 |
"Modified: 20.6.1997 / 10:45:51 / cg" |
489 | 374 |
! |
375 |
||
376 |
literalArrayEncoding |
|
377 |
"return myself encoded as a literal array" |
|
378 |
||
379 |
|coll| |
|
380 |
||
381 |
coll := OrderedCollection new. |
|
382 |
coll add:#Menu. |
|
383 |
coll add:(items literalArrayEncoding). |
|
384 |
coll add:(groupSizes literalArrayEncoding). |
|
385 |
coll add:nil. |
|
579 | 386 |
^ coll asArray |
451 | 387 |
! ! |
388 |
||
584 | 389 |
!Menu methodsFor:'enumerating'! |
390 |
||
665 | 391 |
allItemsDo:aOneArgBlock |
392 |
"evaluate block on each item and submenu items |
|
393 |
" |
|
394 |
self itemsDo:[:anItem| |
|
395 |
aOneArgBlock value:anItem. |
|
396 |
anItem submenu notNil ifTrue:[ |
|
397 |
anItem submenu itemsDo:aOneArgBlock |
|
398 |
] |
|
399 |
] |
|
400 |
! |
|
401 |
||
589 | 402 |
itemsDo:aOneArgBlock |
403 |
"evaluate the block for each item in the current menu |
|
404 |
" |
|
405 |
items notNil ifTrue:[items do:aOneArgBlock] |
|
406 |
! |
|
407 |
||
584 | 408 |
menuAndSubmenusDetectItem:aOneArgBlock |
409 |
"evaluate the block for each item in the current menu and all |
|
410 |
submenus. In case that the block returns a non nil argument, |
|
411 |
the item will be returned |
|
412 |
" |
|
413 |
|sm item| |
|
414 |
||
415 |
items notNil ifTrue:[ |
|
416 |
items do:[:anItem| |
|
627 | 417 |
(aOneArgBlock value:anItem) ifTrue:[ |
584 | 418 |
^ anItem |
419 |
]. |
|
420 |
(sm := anItem submenu) notNil ifTrue:[ |
|
421 |
item := anItem submenu menuAndSubmenusDetectItem:aOneArgBlock. |
|
422 |
item notNil ifTrue:[ |
|
423 |
^ item |
|
424 |
] |
|
425 |
] |
|
426 |
] |
|
427 |
]. |
|
428 |
^ nil |
|
429 |
! ! |
|
430 |
||
672
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
431 |
!Menu methodsFor:'kludged fixes'! |
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
432 |
|
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
433 |
destroy |
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
434 |
|
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
435 |
"Created: 28.7.1997 / 10:16:52 / cg" |
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
436 |
! ! |
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
437 |
|
584 | 438 |
!Menu methodsFor:'menu items'! |
439 |
||
440 |
someMenuItemWithValue:aValue |
|
441 |
"get the menu item assigned with the value; in case that the value |
|
442 |
is not found nil is returned |
|
443 |
" |
|
444 |
^ self someMenuItemWithValue:aValue ifNone:nil |
|
445 |
! |
|
446 |
||
447 |
someMenuItemWithValue:aValue ifNone:exceptionBlock |
|
448 |
"get the menu item assigned with the value; in case that the value |
|
449 |
is not found, the given exceptionBlock is executed and returned |
|
450 |
" |
|
451 |
|item| |
|
452 |
||
453 |
item := self menuAndSubmenusDetectItem:[:anItem| anItem value == aValue]. |
|
454 |
||
455 |
item notNil ifTrue:[ |
|
456 |
^ item |
|
457 |
]. |
|
458 |
^ exceptionBlock value |
|
459 |
! ! |
|
460 |
||
461 |
!Menu methodsFor:'queries'! |
|
462 |
||
463 |
hasSubMenuAt:anIndex |
|
464 |
"test whether the menu item at the given index has a submenu |
|
465 |
" |
|
466 |
^ (self menuItemAt:anIndex) hasSubmenu |
|
467 |
! ! |
|
468 |
||
451 | 469 |
!Menu methodsFor:'startup'! |
470 |
||
471 |
startUp |
|
472 |
"display the menu as a popUp; return the value associated with the |
|
473 |
selected item, 0 if none was selected" |
|
474 |
||
584 | 475 |
|menu result| |
457 | 476 |
|
579 | 477 |
menu := MenuPanel menu:self. |
584 | 478 |
result := menu startUp. |
479 |
^ result ? 0 |
|
451 | 480 |
|
579 | 481 |
" |
451 | 482 |
|m| |
579 | 483 |
|
451 | 484 |
m := #(#Menu #( |
485 |
#(#MenuItem |
|
486 |
#rawLabel: 'left' |
|
487 |
#value: #left ) |
|
488 |
#(#MenuItem |
|
489 |
#rawLabel: 'center' |
|
490 |
#value: #center ) |
|
491 |
#(#MenuItem |
|
492 |
#rawLabel: 'right' |
|
493 |
#value: #right ) ) |
|
579 | 494 |
#(2) |
451 | 495 |
nil |
496 |
) decodeAsLiteralArray. |
|
497 |
||
579 | 498 |
Transcript showCR:(m startUp) |
499 |
" |
|
451 | 500 |
! ! |
501 |
||
502 |
!Menu class methodsFor:'documentation'! |
|
503 |
||
504 |
version |
|
696 | 505 |
^ '$Header: /cvs/stx/stx/libview2/Menu.st,v 1.18 1997-09-15 20:25:21 cg Exp $' |
451 | 506 |
! ! |