author | Claus Gittinger <cg@exept.de> |
Thu, 21 May 1998 14:20:28 +0200 | |
changeset 939 | f6df8fbf6b4a |
parent 938 | dfa1b1666cfa |
child 940 | 418cfd9b298d |
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:[ |
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
40 |
(valueArray := arrayOfString isEmpty) ifTrue: [ |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
41 |
valueArray := #() |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
42 |
] ifFalse:[ |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
43 |
valueArray := (1 to:nLabel) |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
44 |
] |
737 | 45 |
] ifFalse:[ |
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
46 |
valueArray := valueArrayOrNil |
737 | 47 |
]. |
48 |
||
49 |
nLabel ~~ valueArray size ifTrue: [ |
|
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
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 | |
|
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
55 |
|mi v| |
737 | 56 |
|
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
57 |
mi := MenuItem labeled: (arrayOfString at:i) asString. |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
58 |
v := valueArray at: i. |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
59 |
(v isKindOf: Menu) ifTrue: [mi submenu: v]. |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
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:[ |
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
64 |
groupLengths := (menuItems isEmpty) |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
65 |
ifTrue: [Array new: 0] |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
66 |
ifFalse: [Array with: menuItems size] |
737 | 67 |
] ifFalse:[ |
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
68 |
groupLengths := Array new: linesArray size + 1. |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
69 |
groupLengths at: 1 put: linesArray first. |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
70 |
2 to: linesArray size do: [:i | |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
71 |
groupLengths at: i put: (linesArray at: i) - (linesArray at: i - 1) |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
72 |
]. |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
73 |
groupLengths at: groupLengths size put: menuItems size - linesArray last. |
737 | 74 |
]. |
75 |
||
76 |
^ self new |
|
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
77 |
menuItems: menuItems |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
78 |
menuItemGroups: groupLengths |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
79 |
values: valueArray |
737 | 80 |
|
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
81 |
"Modified: / 19.4.1998 / 11:30:18 / 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 |
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
307 |
|n| |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
308 |
|
451 | 309 |
items := aCollectionOfMenuItems. |
579 | 310 |
groupSizes := sizes. |
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
311 |
sizes size > 0 ifTrue:[ |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
312 |
n := sizes inject:0 into:[:sumSoFar :this | sumSoFar + this]. |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
313 |
n = items size ifTrue:[ |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
314 |
groupSizes := sizes copyWithoutLast:1 |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
315 |
] |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
316 |
]. |
451 | 317 |
|
579 | 318 |
values notNil ifTrue:[ |
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
319 |
items with:values do:[:anItem :aValue |anItem value:aValue] |
454 | 320 |
]. |
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
321 |
|
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
322 |
"Modified: / 19.4.1998 / 11:47:34 / cg" |
451 | 323 |
! |
324 |
||
494 | 325 |
numberOfItems |
801 | 326 |
"return the number of items in this menu" |
327 |
||
494 | 328 |
^ items size |
329 |
||
801 | 330 |
"Created: / 6.3.1997 / 15:15:53 / cg" |
331 |
"Modified: / 2.2.1998 / 13:26:40 / cg" |
|
494 | 332 |
! |
333 |
||
579 | 334 |
receiver |
801 | 335 |
"return the receiver of the menu messages" |
579 | 336 |
|
801 | 337 |
^ receiver |
338 |
||
339 |
"Modified: / 2.2.1998 / 13:26:20 / cg" |
|
340 |
! |
|
579 | 341 |
|
342 |
receiver:something |
|
801 | 343 |
"set the receiver of the menu messages" |
579 | 344 |
|
801 | 345 |
receiver := something. |
346 |
||
347 |
"Modified: / 2.2.1998 / 13:26:29 / cg" |
|
348 |
! |
|
579 | 349 |
|
696 | 350 |
removeItem:aMenuItem |
801 | 351 |
"remove an item from the menu" |
352 |
||
696 | 353 |
|idx| |
801 | 354 |
|
696 | 355 |
items notNil ifTrue:[ |
801 | 356 |
idx := items identityIndexOf:aMenuItem. |
357 |
idx ~~ 0 ifTrue:[ |
|
358 |
items removeAtIndex:idx |
|
359 |
] |
|
696 | 360 |
]. |
361 |
||
801 | 362 |
"Created: / 13.9.1997 / 10:27:31 / cg" |
363 |
"Modified: / 2.2.1998 / 13:26:49 / cg" |
|
696 | 364 |
! |
365 |
||
451 | 366 |
valueAt:index |
367 |
"return a collection of values from my items" |
|
368 |
||
369 |
^ (items at:index) value |
|
370 |
||
371 |
"Created: 25.2.1997 / 19:49:41 / cg" |
|
372 |
! |
|
373 |
||
494 | 374 |
valueAt:anIndex put:aValue |
375 |
"put value an an index" |
|
376 |
||
377 |
(items at:anIndex) value:aValue |
|
378 |
||
379 |
"Created: 6.3.1997 / 15:15:48 / cg" |
|
380 |
! |
|
381 |
||
451 | 382 |
values |
383 |
"return a collection of values from my items" |
|
384 |
||
385 |
^ items collect:[:anItem | anItem value] |
|
386 |
||
387 |
"Created: 25.2.1997 / 19:49:29 / cg" |
|
724 | 388 |
! |
389 |
||
390 |
values:aCollectionOfValues |
|
391 |
"return a collection of values from my items" |
|
392 |
||
393 |
|s| |
|
394 |
||
395 |
s := aCollectionOfValues readStream. |
|
396 |
self itemsDo:[:item | |
|
740 | 397 |
|val| |
724 | 398 |
|
740 | 399 |
val := s next. |
400 |
item value:val |
|
724 | 401 |
]. |
402 |
s atEnd ifFalse:[self halt] |
|
403 |
||
404 |
"Created: / 27.10.1997 / 15:15:47 / cg" |
|
405 |
! |
|
406 |
||
407 |
visibleMenuItemGroups |
|
801 | 408 |
|itemGroups visibleItemGroups nextItem| |
724 | 409 |
|
801 | 410 |
itemGroups := OrderedCollection new. |
411 |
nextItem := 1. |
|
412 |
groupSizes do:[:groupSize | |
|
413 |
itemGroups addLast: (items copyFrom:nextItem to:nextItem + groupSize - 1). |
|
414 |
nextItem := nextItem + groupSize |
|
415 |
]. |
|
416 |
self hasHiddenItems ifFalse:[^ itemGroups]. |
|
724 | 417 |
|
801 | 418 |
"Remove the hidden items." |
419 |
visibleItemGroups := OrderedCollection new. |
|
420 |
itemGroups do:[:eachItemGroup | |
|
421 |
|visibleItemGroup| |
|
422 |
||
423 |
visibleItemGroup := eachItemGroup reject:[:eachMenuItem | eachMenuItem hidden]. |
|
424 |
visibleItemGroup isEmpty ifFalse:[ |
|
425 |
visibleItemGroups addLast: visibleItemGroup |
|
426 |
] |
|
427 |
]. |
|
428 |
^ visibleItemGroups |
|
724 | 429 |
|
430 |
"Created: / 27.10.1997 / 15:07:50 / cg" |
|
801 | 431 |
"Modified: / 2.2.1998 / 13:25:52 / cg" |
451 | 432 |
! ! |
433 |
||
582 | 434 |
!Menu methodsFor:'accessing resource'! |
435 |
||
584 | 436 |
findGuiResourcesIn:aResourceContainerOrApplication |
582 | 437 |
"setup a resource owner |
438 |
" |
|
584 | 439 |
aResourceContainerOrApplication notNil ifTrue:[ |
740 | 440 |
items notNil ifTrue:[ |
441 |
items do:[:anItem| anItem findGuiResourcesIn:aResourceContainerOrApplication ] |
|
442 |
] |
|
582 | 443 |
] |
444 |
||
445 |
! ! |
|
446 |
||
451 | 447 |
!Menu methodsFor:'converting'! |
448 |
||
449 |
fromLiteralArrayEncoding:aLiteralEncodedArray |
|
450 |
"read my contents from a aLiteralEncodedArray" |
|
451 |
||
452 |
|items groups values| |
|
453 |
||
454 |
items := (aLiteralEncodedArray at:2) collect:[:item | item decodeAsLiteralArray]. |
|
455 |
groups := aLiteralEncodedArray at:3. |
|
452 | 456 |
values := aLiteralEncodedArray at:4. |
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
457 |
self menuItems:items menuItemGroups:groups values:values. |
451 | 458 |
|
459 |
"extract from PD folder.st: |
|
460 |
#(#Menu #( |
|
740 | 461 |
#(#MenuItem |
462 |
#rawLabel: 'left' |
|
463 |
#value: #left ) |
|
464 |
#(#MenuItem |
|
465 |
#rawLabel: 'center' |
|
466 |
#value: #center ) |
|
467 |
#(#MenuItem |
|
468 |
#rawLabel: 'right' |
|
469 |
#value: #right ) |
|
470 |
) |
|
471 |
#(3 ) |
|
472 |
nil |
|
451 | 473 |
) decodeAsLiteralArray |
474 |
" |
|
452 | 475 |
" |
476 |
#(#Menu #( |
|
740 | 477 |
#(#MenuItem |
478 |
#label: 'Straighten Up' ) |
|
479 |
#(#MenuItem |
|
480 |
#label: 'Inspect' ) |
|
481 |
#(#MenuItem |
|
482 |
#label: 'Coredump' ) |
|
483 |
) |
|
484 |
#(3 ) |
|
485 |
#(#straightenUp #inspect #halt ) |
|
452 | 486 |
) decodeAsLiteralArray startUp |
487 |
" |
|
457 | 488 |
|
454 | 489 |
"extract from iconicBrowser.st: |
452 | 490 |
#(#Menu #( |
740 | 491 |
#(#MenuItem |
492 |
#label: 'Straighten Up' ) |
|
493 |
#(#MenuItem |
|
494 |
#label: 'Inspect' ) |
|
495 |
#(#MenuItem |
|
496 |
#label: 'Coredump' ) |
|
497 |
) |
|
498 |
#(3 ) |
|
499 |
#(1 2 3 ) |
|
452 | 500 |
) decodeAsLiteralArray startUp |
501 |
" |
|
451 | 502 |
|
454 | 503 |
"extract from refactory213.st: |
504 |
#(#Menu #( |
|
740 | 505 |
#(#MenuItem |
506 |
#label: 'File List' |
|
507 |
#accessCharacterPosition: 1 ) |
|
508 |
#(#MenuItem #label: 'File Editor...' |
|
509 |
#accessCharacterPosition: 6 ) |
|
510 |
#(#MenuItem #label: 'Refactoring Tool...' |
|
511 |
#accessCharacterPosition: 1 ) |
|
512 |
#(#MenuItem #label: 'Workspace' |
|
513 |
#accessCharacterPosition: 1 ) |
|
514 |
#(#MenuItem #label: 'New Canvas' |
|
515 |
#accessCharacterPosition: 1 ) |
|
516 |
#(#MenuItem #label: 'Palette' |
|
517 |
#accessCharacterPosition: 1 ) |
|
518 |
#(#MenuItem #label: 'Canvas Tool' |
|
519 |
#accessCharacterPosition: 1 ) |
|
520 |
#(#MenuItem #label: 'Image Editor' |
|
521 |
#accessCharacterPosition: 1 ) |
|
522 |
#(#MenuItem #label: 'Menu Editor' |
|
523 |
#accessCharacterPosition: 1 ) |
|
524 |
#(#MenuItem #label: 'Advanced' |
|
525 |
#accessCharacterPosition: 1 ) |
|
526 |
#(#MenuItem #label: 'DLL and C Connect' |
|
527 |
#accessCharacterPosition: 1 ) |
|
528 |
#(#MenuItem #label: 'System Transcript' |
|
529 |
#accessCharacterPosition: 8 ) |
|
530 |
) |
|
531 |
#(4 5 2 1 ) |
|
532 |
#(#openFileList #openFileEditor #openRefactoringTool #toolsNewWorkspace #toolsNewCanvas #toolsPalette #toolsCanvasTool #toolsMaskEditor #toolsMenuEditor nil #openExternalFinder #toggleSystemTranscript ) |
|
533 |
) decodeAsLiteralArray startUp |
|
454 | 534 |
" |
535 |
||
457 | 536 |
"submenus: |
537 |
#(#Menu #( |
|
740 | 538 |
#(#MenuItem |
539 |
#label: 'Foo' |
|
540 |
#submenu: #(#Menu #( |
|
541 |
#(#MenuItem #label: 'foo 1') |
|
542 |
#(#MenuItem #label: 'foo 2') |
|
543 |
) |
|
544 |
nil |
|
545 |
#(11 22) |
|
546 |
) |
|
547 |
) |
|
548 |
#(#MenuItem |
|
549 |
#label: 'Inspect' ) |
|
550 |
#(#MenuItem |
|
551 |
#label: 'Coredump' ) |
|
552 |
) |
|
553 |
#(3 ) |
|
554 |
#(1 2 3 ) |
|
457 | 555 |
) decodeAsLiteralArray startUp |
556 |
" |
|
557 |
||
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
558 |
"Modified: 20.6.1997 / 10:45:51 / cg" |
489 | 559 |
! |
560 |
||
561 |
literalArrayEncoding |
|
562 |
"return myself encoded as a literal array" |
|
563 |
||
564 |
|coll| |
|
565 |
||
566 |
coll := OrderedCollection new. |
|
567 |
coll add:#Menu. |
|
568 |
coll add:(items literalArrayEncoding). |
|
569 |
coll add:(groupSizes literalArrayEncoding). |
|
570 |
coll add:nil. |
|
579 | 571 |
^ coll asArray |
451 | 572 |
! ! |
573 |
||
584 | 574 |
!Menu methodsFor:'enumerating'! |
575 |
||
665 | 576 |
allItemsDo:aOneArgBlock |
577 |
"evaluate block on each item and submenu items |
|
578 |
" |
|
579 |
self itemsDo:[:anItem| |
|
740 | 580 |
|sub| |
724 | 581 |
|
740 | 582 |
aOneArgBlock value:anItem. |
583 |
(sub := anItem submenu value) notNil ifTrue:[ |
|
584 |
sub allItemsDo:aOneArgBlock |
|
585 |
] |
|
665 | 586 |
] |
724 | 587 |
|
588 |
"Modified: / 27.10.1997 / 15:09:08 / cg" |
|
665 | 589 |
! |
590 |
||
589 | 591 |
itemsDo:aOneArgBlock |
592 |
"evaluate the block for each item in the current menu |
|
593 |
" |
|
594 |
items notNil ifTrue:[items do:aOneArgBlock] |
|
595 |
! |
|
596 |
||
584 | 597 |
menuAndSubmenusDetectItem:aOneArgBlock |
598 |
"evaluate the block for each item in the current menu and all |
|
599 |
submenus. In case that the block returns a non nil argument, |
|
600 |
the item will be returned |
|
601 |
" |
|
724 | 602 |
|item| |
584 | 603 |
|
604 |
items notNil ifTrue:[ |
|
740 | 605 |
items do:[:anItem| |
606 |
|sub| |
|
724 | 607 |
|
740 | 608 |
(aOneArgBlock value:anItem) ifTrue:[ |
609 |
^ anItem |
|
610 |
]. |
|
611 |
(sub := anItem submenu value) notNil ifTrue:[ |
|
612 |
item := sub menuAndSubmenusDetectItem:aOneArgBlock. |
|
613 |
item notNil ifTrue:[ |
|
614 |
^ item |
|
615 |
] |
|
616 |
] |
|
617 |
] |
|
584 | 618 |
]. |
724 | 619 |
^ nil |
620 |
||
621 |
"Modified: / 27.10.1997 / 15:09:43 / cg" |
|
584 | 622 |
! ! |
623 |
||
672
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
624 |
!Menu methodsFor:'kludged fixes'! |
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
625 |
|
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
626 |
destroy |
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
627 |
|
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
628 |
"Created: 28.7.1997 / 10:16:52 / cg" |
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
629 |
! ! |
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
630 |
|
584 | 631 |
!Menu methodsFor:'menu items'! |
632 |
||
740 | 633 |
someMenuItemLabeled:aLabel |
634 |
"get the menu item with that label; in case that the label |
|
635 |
is not found, nil is returned |
|
636 |
" |
|
637 |
^ self someMenuItemLabeled:aLabel ifNone:nil |
|
638 |
||
639 |
"Created: / 14.11.1997 / 20:55:17 / cg" |
|
640 |
! |
|
641 |
||
642 |
someMenuItemLabeled:aLabel ifNone:exceptionBlock |
|
643 |
"get the menu item labeled aLabel; in case that the value |
|
644 |
is not found, the given exceptionBlock is executed and its value returned |
|
645 |
" |
|
646 |
|item| |
|
647 |
||
648 |
item := self menuAndSubmenusDetectItem:[:anItem| anItem label = aLabel]. |
|
649 |
||
650 |
item notNil ifTrue:[ |
|
651 |
^ item |
|
652 |
]. |
|
653 |
^ exceptionBlock value |
|
654 |
||
655 |
"Created: / 14.11.1997 / 20:56:13 / cg" |
|
656 |
! |
|
657 |
||
584 | 658 |
someMenuItemWithValue:aValue |
659 |
"get the menu item assigned with the value; in case that the value |
|
660 |
is not found nil is returned |
|
661 |
" |
|
662 |
^ self someMenuItemWithValue:aValue ifNone:nil |
|
663 |
! |
|
664 |
||
665 |
someMenuItemWithValue:aValue ifNone:exceptionBlock |
|
666 |
"get the menu item assigned with the value; in case that the value |
|
667 |
is not found, the given exceptionBlock is executed and returned |
|
668 |
" |
|
669 |
|item| |
|
670 |
||
671 |
item := self menuAndSubmenusDetectItem:[:anItem| anItem value == aValue]. |
|
672 |
||
673 |
item notNil ifTrue:[ |
|
740 | 674 |
^ item |
584 | 675 |
]. |
676 |
^ exceptionBlock value |
|
677 |
! ! |
|
678 |
||
679 |
!Menu methodsFor:'queries'! |
|
680 |
||
724 | 681 |
hasHiddenItems |
682 |
"test whether any item is hidden" |
|
683 |
||
684 |
self allItemsDo:[:anItem| |
|
740 | 685 |
anItem isHidden ifTrue:[^ true] |
724 | 686 |
]. |
687 |
^ false |
|
688 |
||
689 |
"Modified: / 27.10.1997 / 15:12:44 / cg" |
|
690 |
! |
|
691 |
||
584 | 692 |
hasSubMenuAt:anIndex |
693 |
"test whether the menu item at the given index has a submenu |
|
694 |
" |
|
695 |
^ (self menuItemAt:anIndex) hasSubmenu |
|
696 |
! ! |
|
697 |
||
451 | 698 |
!Menu methodsFor:'startup'! |
699 |
||
729 | 700 |
show |
701 |
"realize the menu at its last position; returns the value associated with the |
|
702 |
selected item, 0 if none was selected" |
|
703 |
||
704 |
^ (MenuPanel menu:self) show ? 0 |
|
705 |
||
706 |
||
707 |
! |
|
708 |
||
709 |
showAt:aPoint |
|
710 |
"realize the menu at aPoint; returns the value associated with the |
|
711 |
selected item, 0 if none was selected" |
|
712 |
||
713 |
^ self showAt:aPoint resizing:true |
|
714 |
||
715 |
||
716 |
! |
|
717 |
||
718 |
showAt:aPoint resizing:aBoolean |
|
719 |
"realize the menu at aPoint; returns the value associated with the |
|
451 | 720 |
selected item, 0 if none was selected" |
721 |
||
729 | 722 |
^ (MenuPanel menu:self) showAt:aPoint resizing:aBoolean ? 0 |
723 |
! |
|
724 |
||
725 |
showAtPointer |
|
726 |
"realize the menu at the current pointer position; returns the value associated with the |
|
727 |
selected item, 0 if none was selected" |
|
728 |
||
729 |
^ self startUp |
|
730 |
! |
|
457 | 731 |
|
729 | 732 |
showCenteredIn:aView |
733 |
"realize the menu visible at the aView center; returns the value associated with the |
|
734 |
selected item, 0 if none was selected" |
|
735 |
||
736 |
^ (MenuPanel menu:self) showCenteredIn:aView ? 0 |
|
737 |
||
738 |
||
739 |
! |
|
740 |
||
741 |
startUp |
|
742 |
"display the menu as a popUp; returns the value associated with the |
|
743 |
selected item, 0 if none was selected" |
|
744 |
||
745 |
^ (MenuPanel menu:self) startUp ? 0 |
|
451 | 746 |
|
579 | 747 |
" |
740 | 748 |
|m| |
579 | 749 |
|
740 | 750 |
m := #(#Menu #( |
751 |
#(#MenuItem |
|
752 |
#rawLabel: 'left' |
|
753 |
#value: #left ) |
|
754 |
#(#MenuItem |
|
755 |
#rawLabel: 'center' |
|
756 |
#value: #center ) |
|
757 |
#(#MenuItem |
|
758 |
#rawLabel: 'right' |
|
759 |
#value: #right ) ) |
|
760 |
#(2) |
|
761 |
nil |
|
762 |
) decodeAsLiteralArray. |
|
451 | 763 |
|
579 | 764 |
Transcript showCR:(m startUp) |
765 |
" |
|
938
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
766 |
! |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
767 |
|
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
768 |
startUpAt:aPoint |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
769 |
"display the menu as a popUp at aPoint; returns the value associated with the |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
770 |
selected item, 0 if none was selected" |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
771 |
|
939 | 772 |
^ ((MenuPanel menu:self) startUpAt:aPoint) ? 0 |
938
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
773 |
|
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
774 |
" |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
775 |
|m| |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
776 |
|
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
777 |
m := #(#Menu #( |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
778 |
#(#MenuItem |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
779 |
#rawLabel: 'left' |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
780 |
#value: #left ) |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
781 |
#(#MenuItem |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
782 |
#rawLabel: 'center' |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
783 |
#value: #center ) |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
784 |
#(#MenuItem |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
785 |
#rawLabel: 'right' |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
786 |
#value: #right ) ) |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
787 |
#(2) |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
788 |
nil |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
789 |
) decodeAsLiteralArray. |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
790 |
|
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
791 |
Transcript showCR:(m startUpAt:100@100) |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
792 |
" |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
793 |
|
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
794 |
"Created: / 21.5.1998 / 14:15:21 / cg" |
939 | 795 |
"Modified: / 21.5.1998 / 14:17:46 / cg" |
451 | 796 |
! ! |
797 |
||
798 |
!Menu class methodsFor:'documentation'! |
|
799 |
||
800 |
version |
|
939 | 801 |
^ '$Header: /cvs/stx/stx/libview2/Menu.st,v 1.29 1998-05-21 12:20:28 cg Exp $' |
451 | 802 |
! ! |