author | Claus Gittinger <cg@exept.de> |
Wed, 11 Jan 2006 15:46:27 +0100 | |
changeset 2081 | 52ba70a79ce9 |
parent 2080 | 4fe491fe114c |
child 2092 | 8c85812b46c4 |
permissions | -rw-r--r-- |
1354 | 1 |
" |
2 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
||
14 |
||
1367 | 15 |
"{ Package: 'stx:libview2' }" |
16 |
||
451 | 17 |
Object subclass:#Menu |
579 | 18 |
instanceVariableNames:'items groupSizes receiver' |
451 | 19 |
classVariableNames:'' |
20 |
poolDictionaries:'' |
|
21 |
category:'Views-Support' |
|
22 |
! |
|
23 |
||
24 |
!Menu class methodsFor:'documentation'! |
|
25 |
||
1354 | 26 |
copyright |
27 |
" |
|
28 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
29 |
All Rights Reserved |
|
30 |
||
31 |
This software is furnished under a license and may be used |
|
32 |
only in accordance with the terms of that license and with the |
|
33 |
inclusion of the above copyright notice. This software may not |
|
34 |
be provided or otherwise made available to, or used by, any |
|
35 |
other person. No title to or ownership of the software is |
|
36 |
hereby transferred. |
|
37 |
" |
|
38 |
||
39 |
||
40 |
! |
|
41 |
||
451 | 42 |
documentation |
43 |
" |
|
44 |
not yet finished Menu class - this will eventually replace |
|
45 |
most of the MenuView and PopUpMenu stuff. |
|
46 |
(and hopefully be ST-80 compatible ...) |
|
47 |
||
48 |
For now, only a subset of the full protocol is implemented. |
|
49 |
||
50 |
[author:] |
|
740 | 51 |
Claus Gittinger |
451 | 52 |
|
53 |
[see also:] |
|
740 | 54 |
MenuItem |
55 |
PopUpMenu |
|
451 | 56 |
" |
57 |
! ! |
|
58 |
||
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
59 |
!Menu class methodsFor:'instance creation'! |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
60 |
|
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
61 |
labelArray:arrayOfString lines:linesArray values:valueArrayOrNil |
737 | 62 |
"return a menu with menu items built with labels from arrayOfString (not Symbols). |
63 |
The linesArray describes which menu items are the last menu item in their group. |
|
64 |
The valueArray contains value objects for each menu item |
|
65 |
(or is nil if no value objects are specified)." |
|
66 |
||
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
67 |
|nLabel valueArray menuItems groupLengths| |
737 | 68 |
|
69 |
nLabel := arrayOfString size. |
|
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
70 |
|
737 | 71 |
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
|
72 |
(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
|
73 |
valueArray := #() |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
74 |
] ifFalse:[ |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
75 |
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
|
76 |
] |
737 | 77 |
] 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
|
78 |
valueArray := valueArrayOrNil |
737 | 79 |
]. |
80 |
||
81 |
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
|
82 |
^ self error: 'illegal menu combination' |
737 | 83 |
]. |
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
84 |
|
737 | 85 |
menuItems := Array new:nLabel. |
86 |
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
|
87 |
|mi v| |
737 | 88 |
|
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
89 |
mi := MenuItem labeled:(arrayOfString at:i) asString. |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
90 |
v := valueArray at:i. |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
91 |
(v isKindOf:Menu) ifTrue:[mi submenu:v]. |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
92 |
menuItems at:i put:mi |
737 | 93 |
]. |
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
94 |
|
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
95 |
(linesArray size == 0) 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
|
96 |
groupLengths := (menuItems isEmpty) |
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
97 |
ifTrue: [Array new:0] |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
98 |
ifFalse: [Array with:menuItems size] |
737 | 99 |
] ifFalse:[ |
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
100 |
groupLengths := Array new:(linesArray size + 1). |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
101 |
groupLengths at:1 put:linesArray first. |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
102 |
2 to:linesArray size do: [:i | |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
103 |
groupLengths at:i put:((linesArray at:i) - (linesArray at:i - 1)) |
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
104 |
]. |
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
105 |
groupLengths at:groupLengths size put:(menuItems size - linesArray last). |
737 | 106 |
]. |
107 |
||
108 |
^ self new |
|
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
109 |
menuItems:menuItems |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
110 |
menuItemGroups:groupLengths |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
111 |
values:valueArray |
737 | 112 |
|
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
113 |
"Modified: / 19.4.1998 / 11:30:18 / cg" |
696 | 114 |
! |
115 |
||
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
116 |
labelArray:arrayOfString values:valueArrayOrNil |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
117 |
"return a menu with menu items built with labels from arrayOfString (not Symbols). |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
118 |
The valueArray contains value objects for each menu item |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
119 |
(or is nil if no value objects are specified)." |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
120 |
|
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
121 |
^ self |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
122 |
labelArray:arrayOfString |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
123 |
lines:nil |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
124 |
values: valueArrayOrNil |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
125 |
|
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
126 |
! |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
127 |
|
696 | 128 |
labelList:arrayOfGroupStrings values:valueArrayOrNil |
129 |
|labels lines| |
|
130 |
||
131 |
lines := arrayOfGroupStrings collect:[:each | each size]. |
|
2017 | 132 |
labels := arrayOfGroupStrings collectAll:[:eachGroup | eachGroup]. |
696 | 133 |
^ self labelArray:labels lines:lines values:valueArrayOrNil |
134 |
||
135 |
"Modified: 20.6.1997 / 10:46:45 / cg" |
|
136 |
"Created: 13.9.1997 / 10:35:46 / cg" |
|
737 | 137 |
! |
138 |
||
738 | 139 |
labels:aString lines:linesArray values:valueArrayOrNil |
737 | 140 |
^ self |
740 | 141 |
labelArray:(aString asCollectionOfLines) |
142 |
lines:linesArray |
|
143 |
values:valueArrayOrNil |
|
737 | 144 |
|
145 |
"Created: / 31.10.1997 / 03:12:20 / cg" |
|
738 | 146 |
"Modified: / 31.10.1997 / 03:23:42 / cg" |
1525 | 147 |
! |
148 |
||
149 |
labels:aString values:valueArrayOrNil |
|
150 |
^ self |
|
151 |
labelArray:(aString asCollectionOfLines) |
|
152 |
lines:#() |
|
153 |
values:valueArrayOrNil |
|
154 |
||
155 |
"Modified: / 31.10.1997 / 03:23:42 / cg" |
|
156 |
"Created: / 12.11.2001 / 16:06:36 / cg" |
|
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
157 |
! ! |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
158 |
|
1764 | 159 |
!Menu methodsFor:'Compatibility-ST80'! |
724 | 160 |
|
161 |
indexOfMenuItem:anItem |
|
162 |
||
163 |
^ items indexOf:anItem |
|
164 |
||
165 |
"Created: / 27.10.1997 / 16:34:19 / cg" |
|
166 |
! |
|
167 |
||
168 |
menuButtons |
|
169 |
"ST-80 seems to use a special menuButton class here. |
|
170 |
Here, kludge a collection of menuItems." |
|
171 |
||
172 |
^ items |
|
173 |
||
174 |
"Created: / 27.10.1997 / 16:33:35 / cg" |
|
175 |
! ! |
|
176 |
||
1782 | 177 |
!Menu methodsFor:'Compatibility-Squeak'! |
178 |
||
179 |
labels:labels lines:lines selections:selections |
|
180 |
|labelArray| |
|
181 |
||
182 |
labels isString ifTrue:[ |
|
183 |
labelArray := labels asCollectionOfLines. |
|
184 |
] ifFalse:[ |
|
185 |
labelArray := labels. |
|
186 |
]. |
|
187 |
||
188 |
1 to:labelArray size do:[:idx | |
|
189 |
|item| |
|
190 |
||
191 |
item := MenuItem new. |
|
192 |
item label:(labelArray at:idx). |
|
193 |
item value:(selections at:idx). |
|
194 |
self addItem:item. |
|
195 |
||
196 |
(lines includes:idx) ifTrue:[ |
|
197 |
self addSeparator. |
|
198 |
]. |
|
199 |
]. |
|
200 |
! ! |
|
201 |
||
451 | 202 |
!Menu methodsFor:'accessing'! |
203 |
||
696 | 204 |
atNameKey:aNameKey |
724 | 205 |
"return the menuItem for the given nameKey; nil if no such item is in the menu. |
206 |
Searches in allItems (i.e. also in subMenus)" |
|
696 | 207 |
|
724 | 208 |
self allItemsDo:[:anItem| |
740 | 209 |
anItem nameKey == aNameKey ifTrue:[^ anItem] |
724 | 210 |
]. |
696 | 211 |
^ nil |
212 |
||
724 | 213 |
"Modified: / 27.10.1997 / 15:12:00 / cg" |
696 | 214 |
! |
215 |
||
578 | 216 |
groupSizes |
217 |
"return the value of the instance variable 'groupSizes' (automatically generated)" |
|
218 |
||
1500 | 219 |
^ groupSizes |
220 |
! |
|
578 | 221 |
|
222 |
groupSizes:something |
|
223 |
"set the value of the instance variable 'groupSizes' (automatically generated)" |
|
224 |
||
1500 | 225 |
groupSizes := something. |
226 |
! |
|
578 | 227 |
|
1986 | 228 |
items |
229 |
^ items |
|
230 |
! |
|
231 |
||
584 | 232 |
labelAt:anIndex |
233 |
"gets the label of the menu item at the given index or nil |
|
234 |
" |
|
235 |
|item| |
|
236 |
||
237 |
(item := self menuItemAt:anIndex) notNil ifTrue:[ |
|
801 | 238 |
^ item label |
584 | 239 |
]. |
801 | 240 |
^ nil |
584 | 241 |
|
801 | 242 |
"Modified: / 2.2.1998 / 13:28:32 / cg" |
584 | 243 |
! |
244 |
||
245 |
labelAtValue:aValue |
|
246 |
"gets the label of the menu item assigned to value |
|
247 |
" |
|
248 |
|item| |
|
249 |
||
801 | 250 |
item := self menuAndSubmenusDetectItem:[:anItem | anItem value == aValue ]. |
584 | 251 |
|
252 |
item notNil ifTrue:[ |
|
801 | 253 |
^ item label |
584 | 254 |
]. |
801 | 255 |
^ nil |
584 | 256 |
|
801 | 257 |
"Modified: / 2.2.1998 / 13:28:28 / cg" |
584 | 258 |
! |
259 |
||
451 | 260 |
labels |
261 |
"return a collection of labels from my items" |
|
262 |
||
977
e07277070839
return valid collection in #labels.
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
263 |
items isNil ifTrue:[^ #()]. |
451 | 264 |
^ items collect:[:anItem | anItem label] |
265 |
||
972
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
266 |
"Created: / 25.2.1997 / 19:47:53 / cg" |
977
e07277070839
return valid collection in #labels.
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
267 |
"Modified: / 19.6.1998 / 02:36:22 / cg" |
451 | 268 |
! |
269 |
||
940 | 270 |
lastItem |
271 |
"returns last item |
|
272 |
" |
|
273 |
^ items notNil ifTrue:[items last] ifFalse:[nil] |
|
274 |
! |
|
275 |
||
489 | 276 |
lines |
737 | 277 |
"return the indexes of the menu items that are the last menu item in their group (except the very last)." |
489 | 278 |
|
801 | 279 |
|lines groupSz| |
737 | 280 |
|
801 | 281 |
(groupSz := groupSizes size) <= 1 ifTrue: [^ Array new]. |
282 |
lines := Array new:(groupSz - 1). |
|
283 |
lines at:1 put:groupSizes first. |
|
284 |
2 to:(groupSz-1) do:[:i | |
|
285 |
lines at:i put:(lines at:(i - 1)) + (groupSizes at:i) |
|
286 |
]. |
|
287 |
^ lines |
|
489 | 288 |
|
801 | 289 |
"Modified: / 2.2.1998 / 13:28:19 / cg" |
489 | 290 |
! |
291 |
||
292 |
menuItemAt:index |
|
584 | 293 |
"gets the menu item at the given index. When the index is out of bounds |
294 |
nil is returned |
|
295 |
" |
|
296 |
(index > 0 and:[index <= items size]) ifTrue:[ |
|
740 | 297 |
^ items at:index |
584 | 298 |
]. |
299 |
^ nil |
|
489 | 300 |
! |
301 |
||
724 | 302 |
menuItemLabeled:anItemLabel |
303 |
"return the menuItem for the given nameKey; nil if no such item is in the menu. |
|
304 |
Searches all items (i.e. also submenu items)" |
|
305 |
||
306 |
self allItemsDo:[:anItem| |
|
740 | 307 |
|l| |
724 | 308 |
|
740 | 309 |
((l := anItem label) sameAs: anItemLabel) ifTrue:[ |
310 |
^ anItem |
|
311 |
]. |
|
312 |
(l includes:$&) ifTrue:[ |
|
313 |
((l copyWithout:$&) sameAs: anItemLabel) ifTrue:[ |
|
314 |
^ anItem |
|
315 |
] |
|
316 |
] |
|
317 |
]. |
|
724 | 318 |
^ nil |
319 |
||
320 |
"Created: / 13.9.1997 / 10:25:16 / cg" |
|
321 |
"Modified: / 27.10.1997 / 15:23:33 / cg" |
|
322 |
! |
|
323 |
||
1652 | 324 |
menuItemWithValue:aValue |
325 |
"return the menuItem for the given value; nil if no such item is in the menu. |
|
326 |
Searches all items (i.e. also submenu items)" |
|
327 |
||
328 |
self allItemsDo:[:anItem| |
|
329 |
|l| |
|
330 |
||
331 |
(anItem value == aValue) ifTrue:[ |
|
332 |
^ anItem |
|
333 |
]. |
|
334 |
]. |
|
335 |
^ nil |
|
336 |
||
337 |
"Created: / 13.9.1997 / 10:25:16 / cg" |
|
338 |
"Modified: / 27.10.1997 / 15:23:33 / cg" |
|
339 |
! |
|
340 |
||
489 | 341 |
menuItems |
1327
b0b482a84570
menuItems always returns a collection (never nil)
Claus Gittinger <cg@exept.de>
parents:
1308
diff
changeset
|
342 |
^ items ? #() |
489 | 343 |
! |
344 |
||
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
345 |
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
|
346 |
|n| |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
347 |
|
1620
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
348 |
items := groupSizes := nil. |
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
349 |
|
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
350 |
aCollectionOfMenuItems size == 0 ifTrue:[ ^ self ]. |
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
351 |
|
451 | 352 |
items := aCollectionOfMenuItems. |
1620
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
353 |
|
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
354 |
sizes size > 0 ifTrue:[ |
1620
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
355 |
groupSizes := sizes. |
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
356 |
|
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
357 |
n := sizes inject:0 into:[:sumSoFar :this | sumSoFar + this]. |
1620
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
358 |
|
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
359 |
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
|
360 |
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
|
361 |
] |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
362 |
]. |
451 | 363 |
|
579 | 364 |
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
|
365 |
items with:values do:[:anItem :aValue |anItem value:aValue] |
454 | 366 |
]. |
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
367 |
|
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
368 |
"Modified: / 19.4.1998 / 11:47:34 / cg" |
451 | 369 |
! |
370 |
||
1116 | 371 |
menuPerformer:something |
372 |
"set the receiver of the menu messages" |
|
373 |
||
374 |
receiver := something. |
|
375 |
||
376 |
"Modified: / 2.2.1998 / 13:26:29 / cg" |
|
377 |
! |
|
378 |
||
494 | 379 |
numberOfItems |
801 | 380 |
"return the number of items in this menu" |
381 |
||
494 | 382 |
^ items size |
383 |
||
801 | 384 |
"Created: / 6.3.1997 / 15:15:53 / cg" |
385 |
"Modified: / 2.2.1998 / 13:26:40 / cg" |
|
494 | 386 |
! |
387 |
||
579 | 388 |
receiver |
801 | 389 |
"return the receiver of the menu messages" |
579 | 390 |
|
801 | 391 |
^ receiver |
392 |
||
393 |
"Modified: / 2.2.1998 / 13:26:20 / cg" |
|
394 |
! |
|
579 | 395 |
|
396 |
receiver:something |
|
801 | 397 |
"set the receiver of the menu messages" |
579 | 398 |
|
801 | 399 |
receiver := something. |
400 |
||
401 |
"Modified: / 2.2.1998 / 13:26:29 / cg" |
|
402 |
! |
|
579 | 403 |
|
451 | 404 |
valueAt:index |
405 |
"return a collection of values from my items" |
|
406 |
||
407 |
^ (items at:index) value |
|
408 |
||
409 |
"Created: 25.2.1997 / 19:49:41 / cg" |
|
410 |
! |
|
411 |
||
494 | 412 |
valueAt:anIndex put:aValue |
413 |
"put value an an index" |
|
414 |
||
415 |
(items at:anIndex) value:aValue |
|
416 |
||
417 |
"Created: 6.3.1997 / 15:15:48 / cg" |
|
418 |
! |
|
419 |
||
451 | 420 |
values |
421 |
"return a collection of values from my items" |
|
422 |
||
423 |
^ items collect:[:anItem | anItem value] |
|
424 |
||
425 |
"Created: 25.2.1997 / 19:49:29 / cg" |
|
724 | 426 |
! |
427 |
||
428 |
values:aCollectionOfValues |
|
429 |
"return a collection of values from my items" |
|
430 |
||
431 |
|s| |
|
432 |
||
433 |
s := aCollectionOfValues readStream. |
|
434 |
self itemsDo:[:item | |
|
1111 | 435 |
|val| |
724 | 436 |
|
1111 | 437 |
val := s next. |
438 |
item value:val |
|
724 | 439 |
]. |
1111 | 440 |
s atEnd ifFalse:[ |
441 |
self halt:'not enough elements in value collection' |
|
442 |
] |
|
724 | 443 |
|
444 |
"Created: / 27.10.1997 / 15:15:47 / cg" |
|
445 |
! |
|
446 |
||
447 |
visibleMenuItemGroups |
|
801 | 448 |
|itemGroups visibleItemGroups nextItem| |
724 | 449 |
|
801 | 450 |
itemGroups := OrderedCollection new. |
451 |
nextItem := 1. |
|
452 |
groupSizes do:[:groupSize | |
|
453 |
itemGroups addLast: (items copyFrom:nextItem to:nextItem + groupSize - 1). |
|
454 |
nextItem := nextItem + groupSize |
|
455 |
]. |
|
456 |
self hasHiddenItems ifFalse:[^ itemGroups]. |
|
724 | 457 |
|
801 | 458 |
"Remove the hidden items." |
459 |
visibleItemGroups := OrderedCollection new. |
|
460 |
itemGroups do:[:eachItemGroup | |
|
461 |
|visibleItemGroup| |
|
462 |
||
463 |
visibleItemGroup := eachItemGroup reject:[:eachMenuItem | eachMenuItem hidden]. |
|
464 |
visibleItemGroup isEmpty ifFalse:[ |
|
465 |
visibleItemGroups addLast: visibleItemGroup |
|
466 |
] |
|
467 |
]. |
|
468 |
^ visibleItemGroups |
|
724 | 469 |
|
470 |
"Created: / 27.10.1997 / 15:07:50 / cg" |
|
801 | 471 |
"Modified: / 2.2.1998 / 13:25:52 / cg" |
451 | 472 |
! ! |
473 |
||
1397 | 474 |
!Menu methodsFor:'accessing-resource'! |
582 | 475 |
|
584 | 476 |
findGuiResourcesIn:aResourceContainerOrApplication |
582 | 477 |
"setup a resource owner |
478 |
" |
|
1401
0fda9891ba4a
only ask once for resources (remember locally)
Claus Gittinger <cg@exept.de>
parents:
1397
diff
changeset
|
479 |
^ self |
0fda9891ba4a
only ask once for resources (remember locally)
Claus Gittinger <cg@exept.de>
parents:
1397
diff
changeset
|
480 |
findGuiResourcesIn:aResourceContainerOrApplication |
0fda9891ba4a
only ask once for resources (remember locally)
Claus Gittinger <cg@exept.de>
parents:
1397
diff
changeset
|
481 |
rememberResourcesIn:(ValueHolder new) |
0fda9891ba4a
only ask once for resources (remember locally)
Claus Gittinger <cg@exept.de>
parents:
1397
diff
changeset
|
482 |
! |
0fda9891ba4a
only ask once for resources (remember locally)
Claus Gittinger <cg@exept.de>
parents:
1397
diff
changeset
|
483 |
|
0fda9891ba4a
only ask once for resources (remember locally)
Claus Gittinger <cg@exept.de>
parents:
1397
diff
changeset
|
484 |
findGuiResourcesIn:aResourceContainerOrApplication rememberResourcesIn:aValueHolderOrNil |
0fda9891ba4a
only ask once for resources (remember locally)
Claus Gittinger <cg@exept.de>
parents:
1397
diff
changeset
|
485 |
"setup a resource owner |
0fda9891ba4a
only ask once for resources (remember locally)
Claus Gittinger <cg@exept.de>
parents:
1397
diff
changeset
|
486 |
" |
2059
36e4aa247402
fixed menu-slice resolving (search in masterApplication too)
Claus Gittinger <cg@exept.de>
parents:
2039
diff
changeset
|
487 |
|resolvedItems rcv| |
1986 | 488 |
|
489 |
receiver isNil ifTrue:[ |
|
490 |
receiver := aResourceContainerOrApplication |
|
491 |
]. |
|
492 |
items isEmptyOrNil ifTrue:[^ self]. |
|
493 |
||
494 |
resolvedItems := OrderedCollection new. |
|
495 |
||
496 |
items do:[:anItem | |
|
497 |
anItem isMenuSlice ifTrue:[ |resItems| |
|
2059
36e4aa247402
fixed menu-slice resolving (search in masterApplication too)
Claus Gittinger <cg@exept.de>
parents:
2039
diff
changeset
|
498 |
rcv := aResourceContainerOrApplication. |
36e4aa247402
fixed menu-slice resolving (search in masterApplication too)
Claus Gittinger <cg@exept.de>
parents:
2039
diff
changeset
|
499 |
[rcv notNil and:[resItems isNil]] whileTrue:[ |
36e4aa247402
fixed menu-slice resolving (search in masterApplication too)
Claus Gittinger <cg@exept.de>
parents:
2039
diff
changeset
|
500 |
resItems := anItem resolveSliceMenuItemsIn:rcv |
36e4aa247402
fixed menu-slice resolving (search in masterApplication too)
Claus Gittinger <cg@exept.de>
parents:
2039
diff
changeset
|
501 |
rememberResourcesIn:aValueHolderOrNil. |
36e4aa247402
fixed menu-slice resolving (search in masterApplication too)
Claus Gittinger <cg@exept.de>
parents:
2039
diff
changeset
|
502 |
rcv := rcv perform:#masterApplication ifNotUnderstood:nil. |
36e4aa247402
fixed menu-slice resolving (search in masterApplication too)
Claus Gittinger <cg@exept.de>
parents:
2039
diff
changeset
|
503 |
]. |
1986 | 504 |
|
505 |
resItems notEmptyOrNil ifTrue:[ |
|
506 |
resolvedItems addAll:resItems. |
|
507 |
] |
|
508 |
] ifFalse:[ |
|
509 |
anItem |
|
510 |
findGuiResourcesIn:aResourceContainerOrApplication |
|
511 |
rememberResourcesIn:aValueHolderOrNil. |
|
512 |
||
513 |
resolvedItems add:anItem. |
|
1534
292c277fcf6a
findGuiResources... now sets the receiver, if not yet set
Claus Gittinger <cg@exept.de>
parents:
1532
diff
changeset
|
514 |
]. |
1986 | 515 |
]. |
516 |
items := resolvedItems. |
|
582 | 517 |
! ! |
518 |
||
940 | 519 |
!Menu methodsFor:'adding & removing'! |
520 |
||
521 |
addItem:aMenuItem |
|
1029 | 522 |
"add a menuItem at the end; |
523 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
524 |
||
940 | 525 |
items isNil ifTrue:[ |
1029 | 526 |
items := OrderedCollection new |
527 |
] ifFalse:[ |
|
528 |
items := items asOrderedCollection |
|
940 | 529 |
]. |
530 |
items add:aMenuItem. |
|
1029 | 531 |
|
532 |
"Modified: / 4.8.1998 / 17:31:13 / cg" |
|
940 | 533 |
! |
534 |
||
535 |
addItem:aMenuItem beforeIndex:anIndex |
|
1029 | 536 |
"add a menuItem at some position; |
537 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
538 |
||
940 | 539 |
items isNil ifTrue:[ |
540 |
items := OrderedCollection new |
|
1029 | 541 |
] ifFalse:[ |
542 |
items := items asOrderedCollection |
|
940 | 543 |
]. |
544 |
items add:aMenuItem beforeIndex:anIndex. |
|
1029 | 545 |
|
546 |
"Modified: / 4.8.1998 / 17:31:39 / cg" |
|
940 | 547 |
! |
548 |
||
549 |
addItem:aMenuItem value:aValue |
|
550 |
aMenuItem value:aValue. |
|
551 |
self addItem:aMenuItem. |
|
552 |
! |
|
553 |
||
1758 | 554 |
addItemGroup:aGroup |
1029 | 555 |
"add a group of items at the end; |
556 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
557 |
||
940 | 558 |
groupSizes isNil ifTrue:[ |
1758 | 559 |
groupSizes := OrderedCollection with:items size. |
940 | 560 |
]. |
1758 | 561 |
groupSizes add:aGroup size. |
940 | 562 |
|
1758 | 563 |
aGroup do:[:item | |
1029 | 564 |
self addItem:item |
940 | 565 |
]. |
566 |
||
567 |
"Created: / 27.10.1997 / 15:02:15 / cg" |
|
1029 | 568 |
"Modified: / 4.8.1998 / 17:32:06 / cg" |
940 | 569 |
! |
570 |
||
571 |
addItemGroup:aGroup values:values |
|
1029 | 572 |
"add a group of items at the end; |
573 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
574 |
||
1758 | 575 |
aGroup with:values do:[:item :value | |
576 |
item value:value |
|
940 | 577 |
]. |
1758 | 578 |
self addItemGroup:aGroup |
1029 | 579 |
|
580 |
"Modified: / 4.8.1998 / 17:32:18 / cg" |
|
940 | 581 |
! |
582 |
||
583 |
addItemGroupLabels:labels values:values |
|
1029 | 584 |
"add a group of items at the end; |
585 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
586 |
||
940 | 587 |
|items| |
588 |
||
589 |
items := labels with:values |
|
1029 | 590 |
collect:[:label :value | |
591 |
MenuItem label:label value:value |
|
592 |
]. |
|
940 | 593 |
self addItemGroup:items |
594 |
||
595 |
"Created: / 27.10.1997 / 19:49:27 / cg" |
|
1029 | 596 |
"Modified: / 4.8.1998 / 17:35:22 / cg" |
940 | 597 |
! |
598 |
||
599 |
addItemLabel:label value:value |
|
1029 | 600 |
"add an item at the end; |
601 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
940 | 602 |
|
1029 | 603 |
self addItem:(MenuItem label:label value:value) |
940 | 604 |
|
605 |
"Created: / 27.10.1997 / 19:47:12 / cg" |
|
1029 | 606 |
"Modified: / 4.8.1998 / 17:34:44 / cg" |
940 | 607 |
! |
608 |
||
1500 | 609 |
addSeparator |
610 |
"add a separating line item at the end; |
|
611 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
612 |
||
613 |
self addItem:(MenuItem new label:'-'). |
|
614 |
! |
|
615 |
||
940 | 616 |
removeItem:aMenuItem |
617 |
"remove an item from the menu" |
|
618 |
||
619 |
|idx| |
|
620 |
||
621 |
items notNil ifTrue:[ |
|
622 |
idx := items identityIndexOf:aMenuItem. |
|
623 |
idx ~~ 0 ifTrue:[ |
|
624 |
items removeAtIndex:idx |
|
625 |
] |
|
626 |
]. |
|
627 |
||
628 |
"Created: / 13.9.1997 / 10:27:31 / cg" |
|
629 |
"Modified: / 2.2.1998 / 13:26:49 / cg" |
|
630 |
! |
|
631 |
||
632 |
removeItemAt:anIndex |
|
633 |
"remove item at an index |
|
634 |
" |
|
635 |
anIndex <= items size ifTrue:[ |
|
636 |
^ items removeAtIndex:anIndex |
|
637 |
]. |
|
638 |
^ nil |
|
639 |
! ! |
|
640 |
||
451 | 641 |
!Menu methodsFor:'converting'! |
642 |
||
2081 | 643 |
asOldStylePopUpMenuFor:anApplicationOrNil |
2080 | 644 |
"a temporary kludge - will vanish, when oldStyle MenuView and PopUpMenu are gone" |
645 |
||
2081 | 646 |
|menuView itemsShown| |
647 |
||
648 |
itemsShown := items select:[:each | |
|
649 |
|visibilityInItem| |
|
650 |
||
651 |
visibilityInItem := each isVisible. |
|
652 |
visibilityInItem isNil ifTrue:[ |
|
653 |
true |
|
654 |
] ifFalse:[ |
|
655 |
visibilityInItem isBoolean ifTrue:[ |
|
656 |
visibilityInItem |
|
657 |
] ifFalse:[ |
|
658 |
visibilityInItem isSymbol ifTrue:[ |
|
659 |
(anApplicationOrNil perform:visibilityInItem) value. |
|
660 |
] ifFalse:[ |
|
661 |
visibilityInItem value |
|
662 |
]. |
|
663 |
]. |
|
664 |
]. |
|
665 |
]. |
|
2080 | 666 |
|
667 |
menuView := MenuView |
|
2081 | 668 |
labels:(itemsShown collect:[:each | each label]) |
669 |
selectors:(itemsShown collect:[:each | each value]) |
|
670 |
args:(itemsShown collect:[:each | each argument]) |
|
2080 | 671 |
receiver:receiver. |
672 |
||
2081 | 673 |
itemsShown do:[:each | |
674 |
|enabledInItem enabled| |
|
675 |
||
676 |
enabledInItem := each enabled. |
|
677 |
enabledInItem notNil ifTrue:[ |
|
678 |
enabledInItem isSymbol ifTrue:[ |
|
679 |
enabled := (anApplicationOrNil perform:enabledInItem). |
|
680 |
] ifFalse:[ |
|
681 |
enabledInItem isBoolean ifTrue:[ |
|
682 |
enabled := enabledInItem |
|
683 |
]. |
|
684 |
]. |
|
685 |
enabled value ifFalse:[ |
|
686 |
menuView disable:(each value) |
|
687 |
]. |
|
688 |
]. |
|
689 |
]. |
|
690 |
||
2080 | 691 |
menuView actions:(items collect:[:each | [ receiver perform:each value ]]). |
692 |
||
693 |
^ PopUpMenu forMenu:menuView |
|
694 |
! |
|
695 |
||
451 | 696 |
fromLiteralArrayEncoding:aLiteralEncodedArray |
697 |
"read my contents from a aLiteralEncodedArray" |
|
698 |
||
699 |
|items groups values| |
|
700 |
||
1620
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
701 |
items := aLiteralEncodedArray at:2. |
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
702 |
|
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
703 |
items ifNotNil:[ |
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
704 |
items := items collect:[:item | item decodeAsLiteralArray]. |
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
705 |
]. |
1405
c7775c10e8fd
tolerant literalDecoding (missing 2nd and 3rd elements);
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
706 |
groups := aLiteralEncodedArray at:3 ifAbsent:nil. |
c7775c10e8fd
tolerant literalDecoding (missing 2nd and 3rd elements);
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
707 |
values := aLiteralEncodedArray at:4 ifAbsent:nil. |
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
708 |
self menuItems:items menuItemGroups:groups values:values. |
451 | 709 |
|
710 |
"extract from PD folder.st: |
|
711 |
#(#Menu #( |
|
1245 | 712 |
#(#MenuItem |
713 |
#rawLabel: 'left' |
|
714 |
#value: #left ) |
|
715 |
#(#MenuItem |
|
716 |
#rawLabel: 'center' |
|
717 |
#value: #center ) |
|
718 |
#(#MenuItem |
|
719 |
#rawLabel: 'right' |
|
720 |
#value: #right ) |
|
721 |
) |
|
722 |
#(3 ) |
|
723 |
nil |
|
451 | 724 |
) decodeAsLiteralArray |
725 |
" |
|
452 | 726 |
" |
727 |
#(#Menu #( |
|
1245 | 728 |
#(#MenuItem |
729 |
#label: 'Straighten Up' ) |
|
730 |
#(#MenuItem |
|
731 |
#label: 'Inspect' ) |
|
732 |
#(#MenuItem |
|
733 |
#label: 'Coredump' ) |
|
734 |
) |
|
735 |
#(3 ) |
|
736 |
#(#straightenUp #inspect #halt ) |
|
452 | 737 |
) decodeAsLiteralArray startUp |
738 |
" |
|
457 | 739 |
|
454 | 740 |
"extract from iconicBrowser.st: |
452 | 741 |
#(#Menu #( |
1245 | 742 |
#(#MenuItem |
743 |
#label: 'Straighten Up' ) |
|
744 |
#(#MenuItem |
|
745 |
#label: 'Inspect' ) |
|
746 |
#(#MenuItem |
|
747 |
#label: 'Coredump' ) |
|
748 |
) |
|
749 |
#(3 ) |
|
750 |
#(1 2 3 ) |
|
452 | 751 |
) decodeAsLiteralArray startUp |
752 |
" |
|
451 | 753 |
|
454 | 754 |
"extract from refactory213.st: |
755 |
#(#Menu #( |
|
1245 | 756 |
#(#MenuItem |
757 |
#label: 'File List' |
|
758 |
#accessCharacterPosition: 1 ) |
|
759 |
#(#MenuItem #label: 'File Editor...' |
|
760 |
#accessCharacterPosition: 6 ) |
|
761 |
#(#MenuItem #label: 'Refactoring Tool...' |
|
762 |
#accessCharacterPosition: 1 ) |
|
763 |
#(#MenuItem #label: 'Workspace' |
|
764 |
#accessCharacterPosition: 1 ) |
|
765 |
#(#MenuItem #label: 'New Canvas' |
|
766 |
#accessCharacterPosition: 1 ) |
|
767 |
#(#MenuItem #label: 'Palette' |
|
768 |
#accessCharacterPosition: 1 ) |
|
769 |
#(#MenuItem #label: 'Canvas Tool' |
|
770 |
#accessCharacterPosition: 1 ) |
|
771 |
#(#MenuItem #label: 'Image Editor' |
|
772 |
#accessCharacterPosition: 1 ) |
|
773 |
#(#MenuItem #label: 'Menu Editor' |
|
774 |
#accessCharacterPosition: 1 ) |
|
775 |
#(#MenuItem #label: 'Advanced' |
|
776 |
#accessCharacterPosition: 1 ) |
|
777 |
#(#MenuItem #label: 'DLL and C Connect' |
|
778 |
#accessCharacterPosition: 1 ) |
|
779 |
#(#MenuItem #label: 'System Transcript' |
|
780 |
#accessCharacterPosition: 8 ) |
|
781 |
) |
|
782 |
#(4 5 2 1 ) |
|
783 |
#(#openFileList #openFileEditor #openRefactoringTool #toolsNewWorkspace #toolsNewCanvas #toolsPalette #toolsCanvasTool #toolsMaskEditor #toolsMenuEditor nil #openExternalFinder #toggleSystemTranscript ) |
|
784 |
) decodeAsLiteralArray startUp |
|
454 | 785 |
" |
786 |
||
457 | 787 |
"submenus: |
788 |
#(#Menu #( |
|
1245 | 789 |
#(#MenuItem |
790 |
#label: 'Foo' |
|
791 |
#submenu: #(#Menu #( |
|
792 |
#(#MenuItem #label: 'foo 1') |
|
793 |
#(#MenuItem #label: 'foo 2') |
|
794 |
) |
|
795 |
nil |
|
796 |
#(11 22) |
|
797 |
) |
|
798 |
) |
|
799 |
#(#MenuItem |
|
800 |
#label: 'Inspect' ) |
|
801 |
#(#MenuItem |
|
802 |
#label: 'Coredump' ) |
|
803 |
) |
|
804 |
#(3 ) |
|
805 |
#(1 2 3 ) |
|
457 | 806 |
) decodeAsLiteralArray startUp |
807 |
" |
|
808 |
||
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
809 |
"Modified: 20.6.1997 / 10:45:51 / cg" |
489 | 810 |
! |
811 |
||
812 |
literalArrayEncoding |
|
813 |
"return myself encoded as a literal array" |
|
814 |
||
1245 | 815 |
|coll array size| |
489 | 816 |
|
817 |
coll := OrderedCollection new. |
|
818 |
coll add:#Menu. |
|
1245 | 819 |
|
820 |
(size := items size) == 0 ifTrue:[ |
|
821 |
array := nil |
|
822 |
] ifFalse:[ |
|
823 |
array := Array new:size. |
|
824 |
items keysAndValuesDo:[:anIndex :anItem| |
|
825 |
array at:anIndex put:(anItem literalArrayEncoding) |
|
826 |
] |
|
827 |
]. |
|
828 |
coll add:array. |
|
829 |
||
830 |
(size := groupSizes size) == 0 ifTrue:[ |
|
831 |
array := nil |
|
832 |
] ifFalse:[ |
|
833 |
array := Array new:size. |
|
834 |
groupSizes keysAndValuesDo:[:anIndex :aSize| |
|
835 |
array at:anIndex put:(aSize literalArrayEncoding) |
|
836 |
] |
|
837 |
]. |
|
838 |
coll add:array. |
|
489 | 839 |
coll add:nil. |
579 | 840 |
^ coll asArray |
451 | 841 |
! ! |
842 |
||
584 | 843 |
!Menu methodsFor:'enumerating'! |
844 |
||
665 | 845 |
allItemsDo:aOneArgBlock |
846 |
"evaluate block on each item and submenu items |
|
847 |
" |
|
848 |
self itemsDo:[:anItem| |
|
972
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
849 |
|sub| |
724 | 850 |
|
972
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
851 |
aOneArgBlock value:anItem. |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
852 |
(sub := anItem submenu) notNil ifTrue:[ |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
853 |
sub allItemsDo:aOneArgBlock |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
854 |
] |
665 | 855 |
] |
724 | 856 |
|
972
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
857 |
"Modified: / 19.6.1998 / 00:34:53 / cg" |
665 | 858 |
! |
859 |
||
940 | 860 |
detectItem:aBlock |
861 |
"evaluate the argument, aBlock for each item in the menu until the |
|
862 |
block returns true; in this case return the item which caused the |
|
863 |
true evaluation. |
|
864 |
If none of the evaluations returns true, return the result of the |
|
865 |
evaluation of the exceptionBlock |
|
866 |
" |
|
867 |
^ self detectItem:aBlock ifNone:[self errorNotFound] |
|
868 |
||
869 |
! |
|
870 |
||
871 |
detectItem:aBlock ifNone:exceptionBlock |
|
872 |
"evaluate the argument, aBlock for each item in the menu until the |
|
873 |
block returns true; in this case return the item which caused the |
|
874 |
true evaluation. |
|
875 |
If none of the evaluations returns true, return the result of the |
|
876 |
evaluation of the exceptionBlock |
|
877 |
" |
|
878 |
items notNil ifTrue:[ |
|
879 |
^ items detect:aBlock ifNone:exceptionBlock |
|
880 |
]. |
|
881 |
^ exceptionBlock value |
|
882 |
! |
|
883 |
||
589 | 884 |
itemsDo:aOneArgBlock |
885 |
"evaluate the block for each item in the current menu |
|
886 |
" |
|
887 |
items notNil ifTrue:[items do:aOneArgBlock] |
|
888 |
! |
|
889 |
||
584 | 890 |
menuAndSubmenusDetectItem:aOneArgBlock |
891 |
"evaluate the block for each item in the current menu and all |
|
892 |
submenus. In case that the block returns a non nil argument, |
|
893 |
the item will be returned |
|
894 |
" |
|
724 | 895 |
|item| |
584 | 896 |
|
897 |
items notNil ifTrue:[ |
|
972
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
898 |
items do:[:anItem| |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
899 |
|sub| |
724 | 900 |
|
972
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
901 |
(aOneArgBlock value:anItem) ifTrue:[ |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
902 |
^ anItem |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
903 |
]. |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
904 |
(sub := anItem submenu) notNil ifTrue:[ |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
905 |
item := sub menuAndSubmenusDetectItem:aOneArgBlock. |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
906 |
item notNil ifTrue:[ |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
907 |
^ item |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
908 |
] |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
909 |
] |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
910 |
] |
584 | 911 |
]. |
724 | 912 |
^ nil |
913 |
||
972
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
914 |
"Modified: / 19.6.1998 / 00:35:00 / cg" |
584 | 915 |
! ! |
916 |
||
672
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
917 |
!Menu methodsFor:'kludged fixes'! |
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
918 |
|
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
919 |
destroy |
1599 | 920 |
"dummy to allow a menu to be used where a MenuView used to be" |
672
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
921 |
|
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
922 |
"Created: 28.7.1997 / 10:16:52 / cg" |
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
923 |
! ! |
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
924 |
|
584 | 925 |
!Menu methodsFor:'menu items'! |
926 |
||
740 | 927 |
someMenuItemLabeled:aLabel |
928 |
"get the menu item with that label; in case that the label |
|
929 |
is not found, nil is returned |
|
930 |
" |
|
931 |
^ self someMenuItemLabeled:aLabel ifNone:nil |
|
932 |
||
933 |
"Created: / 14.11.1997 / 20:55:17 / cg" |
|
934 |
! |
|
935 |
||
936 |
someMenuItemLabeled:aLabel ifNone:exceptionBlock |
|
937 |
"get the menu item labeled aLabel; in case that the value |
|
938 |
is not found, the given exceptionBlock is executed and its value returned |
|
939 |
" |
|
940 |
|item| |
|
941 |
||
942 |
item := self menuAndSubmenusDetectItem:[:anItem| anItem label = aLabel]. |
|
943 |
||
944 |
item notNil ifTrue:[ |
|
945 |
^ item |
|
946 |
]. |
|
947 |
^ exceptionBlock value |
|
948 |
||
949 |
"Created: / 14.11.1997 / 20:56:13 / cg" |
|
950 |
! |
|
951 |
||
584 | 952 |
someMenuItemWithValue:aValue |
953 |
"get the menu item assigned with the value; in case that the value |
|
954 |
is not found nil is returned |
|
955 |
" |
|
956 |
^ self someMenuItemWithValue:aValue ifNone:nil |
|
957 |
! |
|
958 |
||
959 |
someMenuItemWithValue:aValue ifNone:exceptionBlock |
|
960 |
"get the menu item assigned with the value; in case that the value |
|
961 |
is not found, the given exceptionBlock is executed and returned |
|
962 |
" |
|
963 |
|item| |
|
964 |
||
965 |
item := self menuAndSubmenusDetectItem:[:anItem| anItem value == aValue]. |
|
966 |
||
967 |
item notNil ifTrue:[ |
|
740 | 968 |
^ item |
584 | 969 |
]. |
970 |
^ exceptionBlock value |
|
971 |
! ! |
|
972 |
||
973 |
!Menu methodsFor:'queries'! |
|
974 |
||
724 | 975 |
hasHiddenItems |
976 |
"test whether any item is hidden" |
|
977 |
||
978 |
self allItemsDo:[:anItem| |
|
740 | 979 |
anItem isHidden ifTrue:[^ true] |
724 | 980 |
]. |
981 |
^ false |
|
982 |
||
983 |
"Modified: / 27.10.1997 / 15:12:44 / cg" |
|
984 |
! |
|
985 |
||
584 | 986 |
hasSubMenuAt:anIndex |
987 |
"test whether the menu item at the given index has a submenu |
|
988 |
" |
|
989 |
^ (self menuItemAt:anIndex) hasSubmenu |
|
990 |
! ! |
|
991 |
||
451 | 992 |
!Menu methodsFor:'startup'! |
993 |
||
729 | 994 |
show |
995 |
"realize the menu at its last position; returns the value associated with the |
|
996 |
selected item, 0 if none was selected" |
|
997 |
||
998 |
^ (MenuPanel menu:self) show ? 0 |
|
999 |
||
1000 |
||
1001 |
! |
|
1002 |
||
1003 |
showAt:aPoint |
|
1004 |
"realize the menu at aPoint; returns the value associated with the |
|
1005 |
selected item, 0 if none was selected" |
|
1006 |
||
1007 |
^ self showAt:aPoint resizing:true |
|
1008 |
||
1009 |
||
1010 |
! |
|
1011 |
||
1012 |
showAt:aPoint resizing:aBoolean |
|
1013 |
"realize the menu at aPoint; returns the value associated with the |
|
451 | 1014 |
selected item, 0 if none was selected" |
1015 |
||
996
1e10d01c90b8
careful: ? is a binary selector.
Claus Gittinger <cg@exept.de>
parents:
977
diff
changeset
|
1016 |
^ ((MenuPanel menu:self) showAt:aPoint resizing:aBoolean) ? 0 |
1e10d01c90b8
careful: ? is a binary selector.
Claus Gittinger <cg@exept.de>
parents:
977
diff
changeset
|
1017 |
|
1e10d01c90b8
careful: ? is a binary selector.
Claus Gittinger <cg@exept.de>
parents:
977
diff
changeset
|
1018 |
"Modified: / 8.7.1998 / 19:57:55 / cg" |
729 | 1019 |
! |
1020 |
||
1021 |
showAtPointer |
|
1022 |
"realize the menu at the current pointer position; returns the value associated with the |
|
1023 |
selected item, 0 if none was selected" |
|
1024 |
||
1025 |
^ self startUp |
|
1026 |
! |
|
457 | 1027 |
|
729 | 1028 |
showCenteredIn:aView |
1029 |
"realize the menu visible at the aView center; returns the value associated with the |
|
1030 |
selected item, 0 if none was selected" |
|
1031 |
||
996
1e10d01c90b8
careful: ? is a binary selector.
Claus Gittinger <cg@exept.de>
parents:
977
diff
changeset
|
1032 |
^ ((MenuPanel menu:self) showCenteredIn:aView) ? 0 |
729 | 1033 |
|
996
1e10d01c90b8
careful: ? is a binary selector.
Claus Gittinger <cg@exept.de>
parents:
977
diff
changeset
|
1034 |
"Modified: / 8.7.1998 / 19:58:05 / cg" |
729 | 1035 |
! |
1036 |
||
1037 |
startUp |
|
1038 |
"display the menu as a popUp; returns the value associated with the |
|
2039 | 1039 |
selected item, nil if none was selected. |
1040 |
(should we return 0 form ST-80 compatibility ?)" |
|
729 | 1041 |
|
1367 | 1042 |
^ (MenuPanel menu:self) startUp "/ ? 0 |
451 | 1043 |
|
579 | 1044 |
" |
1367 | 1045 |
|m| |
579 | 1046 |
|
1367 | 1047 |
m := #(#Menu #( |
1048 |
#(#MenuItem |
|
1049 |
#rawLabel: 'left' |
|
1050 |
#value: #left ) |
|
1051 |
#(#MenuItem |
|
1052 |
#rawLabel: 'center' |
|
1053 |
#value: #center ) |
|
1054 |
#(#MenuItem |
|
1055 |
#rawLabel: 'right' |
|
1056 |
#value: #right ) ) |
|
1057 |
#(2) |
|
1058 |
nil |
|
1059 |
) decodeAsLiteralArray. |
|
451 | 1060 |
|
579 | 1061 |
Transcript showCR:(m startUp) |
1062 |
" |
|
938
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1063 |
! |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1064 |
|
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1065 |
startUpAt:aPoint |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1066 |
"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
|
1067 |
selected item, 0 if none was selected" |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1068 |
|
939 | 1069 |
^ ((MenuPanel menu:self) startUpAt:aPoint) ? 0 |
938
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1070 |
|
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1071 |
" |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1072 |
|m| |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1073 |
|
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1074 |
m := #(#Menu #( |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1075 |
#(#MenuItem |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1076 |
#rawLabel: 'left' |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1077 |
#value: #left ) |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1078 |
#(#MenuItem |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1079 |
#rawLabel: 'center' |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1080 |
#value: #center ) |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1081 |
#(#MenuItem |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1082 |
#rawLabel: 'right' |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1083 |
#value: #right ) ) |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1084 |
#(2) |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1085 |
nil |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1086 |
) decodeAsLiteralArray. |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1087 |
|
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1088 |
Transcript showCR:(m startUpAt:100@100) |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1089 |
" |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1090 |
|
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1091 |
"Created: / 21.5.1998 / 14:15:21 / cg" |
939 | 1092 |
"Modified: / 21.5.1998 / 14:17:46 / cg" |
1367 | 1093 |
! |
1094 |
||
1652 | 1095 |
startUpFor:originatingWidget |
1096 |
"display the menu as a popUp; returns the value associated with the |
|
2039 | 1097 |
selected item, nil if none was selected. |
1098 |
(should we return 0 for ST-80 compatibility ?)" |
|
1652 | 1099 |
|
1100 |
^ (MenuPanel menu:self) startUpFor:originatingWidget "/ ? 0 |
|
1101 |
||
1102 |
" |
|
1103 |
|m| |
|
1104 |
||
1105 |
m := #(#Menu #( |
|
1106 |
#(#MenuItem |
|
1107 |
#rawLabel: 'left' |
|
1108 |
#value: #left ) |
|
1109 |
#(#MenuItem |
|
1110 |
#rawLabel: 'center' |
|
1111 |
#value: #center ) |
|
1112 |
#(#MenuItem |
|
1113 |
#rawLabel: 'right' |
|
1114 |
#value: #right ) ) |
|
1115 |
#(2) |
|
1116 |
nil |
|
1117 |
) decodeAsLiteralArray. |
|
1118 |
||
1119 |
Transcript showCR:(m startUp) |
|
1120 |
" |
|
1121 |
! |
|
1122 |
||
1367 | 1123 |
startUpOrNil |
1124 |
"display the menu as a popUp; returns the value associated with the |
|
1125 |
selected item, nil if none was selected" |
|
1126 |
||
1405
c7775c10e8fd
tolerant literalDecoding (missing 2nd and 3rd elements);
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
1127 |
^ (MenuPanel menu:self) startUpOrNil |
451 | 1128 |
! ! |
1129 |
||
1130 |
!Menu class methodsFor:'documentation'! |
|
1131 |
||
1132 |
version |
|
2081 | 1133 |
^ '$Header: /cvs/stx/stx/libview2/Menu.st,v 1.63 2006-01-11 14:46:27 cg Exp $' |
451 | 1134 |
! ! |