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