author | Claus Gittinger <cg@exept.de> |
Wed, 01 Dec 1999 21:25:19 +0100 | |
changeset 1278 | 0fc24ae3a3e3 |
parent 1247 | dee345f571b7 |
child 1308 | c29f450cf3ca |
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 |
|
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
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 |
||
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
35 |
|nLabel valueArray menuItems groupLengths| |
737 | 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 |
|
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
57 |
mi := MenuItem labeled:(arrayOfString at:i) asString. |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
58 |
v := valueArray at:i. |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
59 |
(v isKindOf:Menu) ifTrue:[mi submenu:v]. |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
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 |
|
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
63 |
(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
|
64 |
groupLengths := (menuItems isEmpty) |
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
65 |
ifTrue: [Array new:0] |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
66 |
ifFalse: [Array with:menuItems size] |
737 | 67 |
] ifFalse:[ |
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
68 |
groupLengths := Array new:(linesArray size + 1). |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
69 |
groupLengths at:1 put:linesArray first. |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
70 |
2 to:linesArray size do: [:i | |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
71 |
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
|
72 |
]. |
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
73 |
groupLengths at:groupLengths size put:(menuItems size - linesArray last). |
737 | 74 |
]. |
75 |
||
76 |
^ self new |
|
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
77 |
menuItems:menuItems |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
78 |
menuItemGroups:groupLengths |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
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 |
||
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
84 |
labelArray:arrayOfString values:valueArrayOrNil |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
85 |
"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
|
86 |
The valueArray contains value objects for each menu item |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
87 |
(or is nil if no value objects are specified)." |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
88 |
|
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
89 |
^ self |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
90 |
labelArray:arrayOfString |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
91 |
lines:nil |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
92 |
values: valueArrayOrNil |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
93 |
|
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
94 |
! |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
95 |
|
696 | 96 |
labelList:arrayOfGroupStrings values:valueArrayOrNil |
97 |
|labels lines| |
|
98 |
||
99 |
lines := arrayOfGroupStrings collect:[:each | each size]. |
|
100 |
labels := OrderedCollection new. |
|
101 |
arrayOfGroupStrings do:[:group | labels addAll:group]. |
|
102 |
^ self labelArray:labels lines:lines values:valueArrayOrNil |
|
103 |
||
104 |
"Modified: 20.6.1997 / 10:46:45 / cg" |
|
105 |
"Created: 13.9.1997 / 10:35:46 / cg" |
|
737 | 106 |
! |
107 |
||
738 | 108 |
labels:aString lines:linesArray values:valueArrayOrNil |
737 | 109 |
^ self |
740 | 110 |
labelArray:(aString asCollectionOfLines) |
111 |
lines:linesArray |
|
112 |
values:valueArrayOrNil |
|
737 | 113 |
|
114 |
"Created: / 31.10.1997 / 03:12:20 / cg" |
|
738 | 115 |
"Modified: / 31.10.1997 / 03:23:42 / cg" |
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
116 |
! ! |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
117 |
|
1247 | 118 |
!Menu methodsFor:'Compatibility - ST-80'! |
724 | 119 |
|
120 |
indexOfMenuItem:anItem |
|
121 |
||
122 |
^ items indexOf:anItem |
|
123 |
||
124 |
"Created: / 27.10.1997 / 16:34:19 / cg" |
|
125 |
! |
|
126 |
||
127 |
menuButtons |
|
128 |
"ST-80 seems to use a special menuButton class here. |
|
129 |
Here, kludge a collection of menuItems." |
|
130 |
||
131 |
^ items |
|
132 |
||
133 |
"Created: / 27.10.1997 / 16:33:35 / cg" |
|
134 |
! ! |
|
135 |
||
451 | 136 |
!Menu methodsFor:'accessing'! |
137 |
||
696 | 138 |
atNameKey:aNameKey |
724 | 139 |
"return the menuItem for the given nameKey; nil if no such item is in the menu. |
140 |
Searches in allItems (i.e. also in subMenus)" |
|
696 | 141 |
|
724 | 142 |
self allItemsDo:[:anItem| |
740 | 143 |
anItem nameKey == aNameKey ifTrue:[^ anItem] |
724 | 144 |
]. |
696 | 145 |
^ nil |
146 |
||
724 | 147 |
"Modified: / 27.10.1997 / 15:12:00 / cg" |
696 | 148 |
! |
149 |
||
578 | 150 |
groupSizes |
151 |
"return the value of the instance variable 'groupSizes' (automatically generated)" |
|
152 |
||
153 |
^ groupSizes! |
|
154 |
||
155 |
groupSizes:something |
|
156 |
"set the value of the instance variable 'groupSizes' (automatically generated)" |
|
157 |
||
158 |
groupSizes := something.! |
|
159 |
||
584 | 160 |
labelAt:anIndex |
161 |
"gets the label of the menu item at the given index or nil |
|
162 |
" |
|
163 |
|item| |
|
164 |
||
165 |
(item := self menuItemAt:anIndex) notNil ifTrue:[ |
|
801 | 166 |
^ item label |
584 | 167 |
]. |
801 | 168 |
^ nil |
584 | 169 |
|
801 | 170 |
"Modified: / 2.2.1998 / 13:28:32 / cg" |
584 | 171 |
! |
172 |
||
173 |
labelAtValue:aValue |
|
174 |
"gets the label of the menu item assigned to value |
|
175 |
" |
|
176 |
|item| |
|
177 |
||
801 | 178 |
item := self menuAndSubmenusDetectItem:[:anItem | anItem value == aValue ]. |
584 | 179 |
|
180 |
item notNil ifTrue:[ |
|
801 | 181 |
^ item label |
584 | 182 |
]. |
801 | 183 |
^ nil |
584 | 184 |
|
801 | 185 |
"Modified: / 2.2.1998 / 13:28:28 / cg" |
584 | 186 |
! |
187 |
||
451 | 188 |
labels |
189 |
"return a collection of labels from my items" |
|
190 |
||
977
e07277070839
return valid collection in #labels.
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
191 |
items isNil ifTrue:[^ #()]. |
451 | 192 |
^ items collect:[:anItem | anItem label] |
193 |
||
972
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
194 |
"Created: / 25.2.1997 / 19:47:53 / cg" |
977
e07277070839
return valid collection in #labels.
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
195 |
"Modified: / 19.6.1998 / 02:36:22 / cg" |
451 | 196 |
! |
197 |
||
940 | 198 |
lastItem |
199 |
"returns last item |
|
200 |
" |
|
201 |
^ items notNil ifTrue:[items last] ifFalse:[nil] |
|
202 |
! |
|
203 |
||
489 | 204 |
lines |
737 | 205 |
"return the indexes of the menu items that are the last menu item in their group (except the very last)." |
489 | 206 |
|
801 | 207 |
|lines groupSz| |
737 | 208 |
|
801 | 209 |
(groupSz := groupSizes size) <= 1 ifTrue: [^ Array new]. |
210 |
lines := Array new:(groupSz - 1). |
|
211 |
lines at:1 put:groupSizes first. |
|
212 |
2 to:(groupSz-1) do:[:i | |
|
213 |
lines at:i put:(lines at:(i - 1)) + (groupSizes at:i) |
|
214 |
]. |
|
215 |
^ lines |
|
489 | 216 |
|
801 | 217 |
"Modified: / 2.2.1998 / 13:28:19 / cg" |
489 | 218 |
! |
219 |
||
220 |
menuItemAt:index |
|
584 | 221 |
"gets the menu item at the given index. When the index is out of bounds |
222 |
nil is returned |
|
223 |
" |
|
224 |
(index > 0 and:[index <= items size]) ifTrue:[ |
|
740 | 225 |
^ items at:index |
584 | 226 |
]. |
227 |
^ nil |
|
489 | 228 |
! |
229 |
||
724 | 230 |
menuItemLabeled:anItemLabel |
231 |
"return the menuItem for the given nameKey; nil if no such item is in the menu. |
|
232 |
Searches all items (i.e. also submenu items)" |
|
233 |
||
234 |
self allItemsDo:[:anItem| |
|
740 | 235 |
|l| |
724 | 236 |
|
740 | 237 |
((l := anItem label) sameAs: anItemLabel) ifTrue:[ |
238 |
^ anItem |
|
239 |
]. |
|
240 |
(l includes:$&) ifTrue:[ |
|
241 |
((l copyWithout:$&) sameAs: anItemLabel) ifTrue:[ |
|
242 |
^ anItem |
|
243 |
] |
|
244 |
] |
|
245 |
]. |
|
724 | 246 |
^ nil |
247 |
||
248 |
"Created: / 13.9.1997 / 10:25:16 / cg" |
|
249 |
"Modified: / 27.10.1997 / 15:23:33 / cg" |
|
250 |
! |
|
251 |
||
489 | 252 |
menuItems |
253 |
^ items |
|
254 |
! |
|
255 |
||
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
256 |
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
|
257 |
|n| |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
258 |
|
451 | 259 |
items := aCollectionOfMenuItems. |
579 | 260 |
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
|
261 |
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
|
262 |
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
|
263 |
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
|
264 |
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
|
265 |
] |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
266 |
]. |
451 | 267 |
|
579 | 268 |
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
|
269 |
items with:values do:[:anItem :aValue |anItem value:aValue] |
454 | 270 |
]. |
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
271 |
|
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
272 |
"Modified: / 19.4.1998 / 11:47:34 / cg" |
451 | 273 |
! |
274 |
||
1116 | 275 |
menuPerformer:something |
276 |
"set the receiver of the menu messages" |
|
277 |
||
278 |
receiver := something. |
|
279 |
||
280 |
"Modified: / 2.2.1998 / 13:26:29 / cg" |
|
281 |
! |
|
282 |
||
494 | 283 |
numberOfItems |
801 | 284 |
"return the number of items in this menu" |
285 |
||
494 | 286 |
^ items size |
287 |
||
801 | 288 |
"Created: / 6.3.1997 / 15:15:53 / cg" |
289 |
"Modified: / 2.2.1998 / 13:26:40 / cg" |
|
494 | 290 |
! |
291 |
||
579 | 292 |
receiver |
801 | 293 |
"return the receiver of the menu messages" |
579 | 294 |
|
801 | 295 |
^ receiver |
296 |
||
297 |
"Modified: / 2.2.1998 / 13:26:20 / cg" |
|
298 |
! |
|
579 | 299 |
|
300 |
receiver:something |
|
801 | 301 |
"set the receiver of the menu messages" |
579 | 302 |
|
801 | 303 |
receiver := something. |
304 |
||
305 |
"Modified: / 2.2.1998 / 13:26:29 / cg" |
|
306 |
! |
|
579 | 307 |
|
451 | 308 |
valueAt:index |
309 |
"return a collection of values from my items" |
|
310 |
||
311 |
^ (items at:index) value |
|
312 |
||
313 |
"Created: 25.2.1997 / 19:49:41 / cg" |
|
314 |
! |
|
315 |
||
494 | 316 |
valueAt:anIndex put:aValue |
317 |
"put value an an index" |
|
318 |
||
319 |
(items at:anIndex) value:aValue |
|
320 |
||
321 |
"Created: 6.3.1997 / 15:15:48 / cg" |
|
322 |
! |
|
323 |
||
451 | 324 |
values |
325 |
"return a collection of values from my items" |
|
326 |
||
327 |
^ items collect:[:anItem | anItem value] |
|
328 |
||
329 |
"Created: 25.2.1997 / 19:49:29 / cg" |
|
724 | 330 |
! |
331 |
||
332 |
values:aCollectionOfValues |
|
333 |
"return a collection of values from my items" |
|
334 |
||
335 |
|s| |
|
336 |
||
337 |
s := aCollectionOfValues readStream. |
|
338 |
self itemsDo:[:item | |
|
1111 | 339 |
|val| |
724 | 340 |
|
1111 | 341 |
val := s next. |
342 |
item value:val |
|
724 | 343 |
]. |
1111 | 344 |
s atEnd ifFalse:[ |
345 |
self halt:'not enough elements in value collection' |
|
346 |
] |
|
724 | 347 |
|
348 |
"Created: / 27.10.1997 / 15:15:47 / cg" |
|
349 |
! |
|
350 |
||
351 |
visibleMenuItemGroups |
|
801 | 352 |
|itemGroups visibleItemGroups nextItem| |
724 | 353 |
|
801 | 354 |
itemGroups := OrderedCollection new. |
355 |
nextItem := 1. |
|
356 |
groupSizes do:[:groupSize | |
|
357 |
itemGroups addLast: (items copyFrom:nextItem to:nextItem + groupSize - 1). |
|
358 |
nextItem := nextItem + groupSize |
|
359 |
]. |
|
360 |
self hasHiddenItems ifFalse:[^ itemGroups]. |
|
724 | 361 |
|
801 | 362 |
"Remove the hidden items." |
363 |
visibleItemGroups := OrderedCollection new. |
|
364 |
itemGroups do:[:eachItemGroup | |
|
365 |
|visibleItemGroup| |
|
366 |
||
367 |
visibleItemGroup := eachItemGroup reject:[:eachMenuItem | eachMenuItem hidden]. |
|
368 |
visibleItemGroup isEmpty ifFalse:[ |
|
369 |
visibleItemGroups addLast: visibleItemGroup |
|
370 |
] |
|
371 |
]. |
|
372 |
^ visibleItemGroups |
|
724 | 373 |
|
374 |
"Created: / 27.10.1997 / 15:07:50 / cg" |
|
801 | 375 |
"Modified: / 2.2.1998 / 13:25:52 / cg" |
451 | 376 |
! ! |
377 |
||
582 | 378 |
!Menu methodsFor:'accessing resource'! |
379 |
||
584 | 380 |
findGuiResourcesIn:aResourceContainerOrApplication |
582 | 381 |
"setup a resource owner |
382 |
" |
|
584 | 383 |
aResourceContainerOrApplication notNil ifTrue:[ |
740 | 384 |
items notNil ifTrue:[ |
385 |
items do:[:anItem| anItem findGuiResourcesIn:aResourceContainerOrApplication ] |
|
386 |
] |
|
582 | 387 |
] |
388 |
||
389 |
! ! |
|
390 |
||
940 | 391 |
!Menu methodsFor:'adding & removing'! |
392 |
||
393 |
addItem:aMenuItem |
|
1029 | 394 |
"add a menuItem at the end; |
395 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
396 |
||
940 | 397 |
items isNil ifTrue:[ |
1029 | 398 |
items := OrderedCollection new |
399 |
] ifFalse:[ |
|
400 |
items := items asOrderedCollection |
|
940 | 401 |
]. |
402 |
items add:aMenuItem. |
|
1029 | 403 |
|
404 |
"Modified: / 4.8.1998 / 17:31:13 / cg" |
|
940 | 405 |
! |
406 |
||
407 |
addItem:aMenuItem beforeIndex:anIndex |
|
1029 | 408 |
"add a menuItem at some position; |
409 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
410 |
||
940 | 411 |
items isNil ifTrue:[ |
412 |
items := OrderedCollection new |
|
1029 | 413 |
] ifFalse:[ |
414 |
items := items asOrderedCollection |
|
940 | 415 |
]. |
416 |
items add:aMenuItem beforeIndex:anIndex. |
|
1029 | 417 |
|
418 |
"Modified: / 4.8.1998 / 17:31:39 / cg" |
|
940 | 419 |
! |
420 |
||
421 |
addItem:aMenuItem value:aValue |
|
422 |
aMenuItem value:aValue. |
|
423 |
self addItem:aMenuItem. |
|
424 |
! |
|
425 |
||
426 |
addItemGroup:aCollectionOfItems |
|
1029 | 427 |
"add a group of items at the end; |
428 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
429 |
||
940 | 430 |
groupSizes isNil ifTrue:[ |
1029 | 431 |
groupSizes := OrderedCollection new |
940 | 432 |
]. |
433 |
groupSizes add:aCollectionOfItems size. |
|
434 |
||
435 |
aCollectionOfItems do:[:item | |
|
1029 | 436 |
self addItem:item |
940 | 437 |
]. |
438 |
||
439 |
"Created: / 27.10.1997 / 15:02:15 / cg" |
|
1029 | 440 |
"Modified: / 4.8.1998 / 17:32:06 / cg" |
940 | 441 |
! |
442 |
||
443 |
addItemGroup:aGroup values:values |
|
1029 | 444 |
"add a group of items at the end; |
445 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
446 |
||
940 | 447 |
groupSizes isNil ifTrue:[ |
1029 | 448 |
groupSizes := OrderedCollection new |
940 | 449 |
]. |
450 |
groupSizes add:items size. |
|
451 |
||
452 |
aGroup with:values do:[:item :value | |
|
1029 | 453 |
self addItem:item value:value |
940 | 454 |
]. |
1029 | 455 |
|
456 |
"Modified: / 4.8.1998 / 17:32:18 / cg" |
|
940 | 457 |
! |
458 |
||
459 |
addItemGroupLabels:labels values:values |
|
1029 | 460 |
"add a group of items at the end; |
461 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
462 |
||
940 | 463 |
|items| |
464 |
||
465 |
items := labels with:values |
|
1029 | 466 |
collect:[:label :value | |
467 |
MenuItem label:label value:value |
|
468 |
]. |
|
940 | 469 |
self addItemGroup:items |
470 |
||
471 |
"Created: / 27.10.1997 / 19:49:27 / cg" |
|
1029 | 472 |
"Modified: / 4.8.1998 / 17:35:22 / cg" |
940 | 473 |
! |
474 |
||
475 |
addItemLabel:label value:value |
|
1029 | 476 |
"add an item at the end; |
477 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
940 | 478 |
|
1029 | 479 |
self addItem:(MenuItem label:label value:value) |
940 | 480 |
|
481 |
"Created: / 27.10.1997 / 19:47:12 / cg" |
|
1029 | 482 |
"Modified: / 4.8.1998 / 17:34:44 / cg" |
940 | 483 |
! |
484 |
||
485 |
removeItem:aMenuItem |
|
486 |
"remove an item from the menu" |
|
487 |
||
488 |
|idx| |
|
489 |
||
490 |
items notNil ifTrue:[ |
|
491 |
idx := items identityIndexOf:aMenuItem. |
|
492 |
idx ~~ 0 ifTrue:[ |
|
493 |
items removeAtIndex:idx |
|
494 |
] |
|
495 |
]. |
|
496 |
||
497 |
"Created: / 13.9.1997 / 10:27:31 / cg" |
|
498 |
"Modified: / 2.2.1998 / 13:26:49 / cg" |
|
499 |
! |
|
500 |
||
501 |
removeItemAt:anIndex |
|
502 |
"remove item at an index |
|
503 |
" |
|
504 |
anIndex <= items size ifTrue:[ |
|
505 |
^ items removeAtIndex:anIndex |
|
506 |
]. |
|
507 |
^ nil |
|
508 |
! ! |
|
509 |
||
451 | 510 |
!Menu methodsFor:'converting'! |
511 |
||
512 |
fromLiteralArrayEncoding:aLiteralEncodedArray |
|
513 |
"read my contents from a aLiteralEncodedArray" |
|
514 |
||
515 |
|items groups values| |
|
516 |
||
1245 | 517 |
"/ ((aLiteralEncodedArray at:2) at:1) == #OrderedCollection ifTrue:[ |
518 |
"/ items := (aLiteralEncodedArray at:2) decodeAsLiteralArray |
|
519 |
"/ ] ifFalse:[ |
|
451 | 520 |
items := (aLiteralEncodedArray at:2) collect:[:item | item decodeAsLiteralArray]. |
1245 | 521 |
"/ ]. |
451 | 522 |
groups := aLiteralEncodedArray at:3. |
452 | 523 |
values := aLiteralEncodedArray at:4. |
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
524 |
self menuItems:items menuItemGroups:groups values:values. |
451 | 525 |
|
526 |
"extract from PD folder.st: |
|
527 |
#(#Menu #( |
|
1245 | 528 |
#(#MenuItem |
529 |
#rawLabel: 'left' |
|
530 |
#value: #left ) |
|
531 |
#(#MenuItem |
|
532 |
#rawLabel: 'center' |
|
533 |
#value: #center ) |
|
534 |
#(#MenuItem |
|
535 |
#rawLabel: 'right' |
|
536 |
#value: #right ) |
|
537 |
) |
|
538 |
#(3 ) |
|
539 |
nil |
|
451 | 540 |
) decodeAsLiteralArray |
541 |
" |
|
452 | 542 |
" |
543 |
#(#Menu #( |
|
1245 | 544 |
#(#MenuItem |
545 |
#label: 'Straighten Up' ) |
|
546 |
#(#MenuItem |
|
547 |
#label: 'Inspect' ) |
|
548 |
#(#MenuItem |
|
549 |
#label: 'Coredump' ) |
|
550 |
) |
|
551 |
#(3 ) |
|
552 |
#(#straightenUp #inspect #halt ) |
|
452 | 553 |
) decodeAsLiteralArray startUp |
554 |
" |
|
457 | 555 |
|
454 | 556 |
"extract from iconicBrowser.st: |
452 | 557 |
#(#Menu #( |
1245 | 558 |
#(#MenuItem |
559 |
#label: 'Straighten Up' ) |
|
560 |
#(#MenuItem |
|
561 |
#label: 'Inspect' ) |
|
562 |
#(#MenuItem |
|
563 |
#label: 'Coredump' ) |
|
564 |
) |
|
565 |
#(3 ) |
|
566 |
#(1 2 3 ) |
|
452 | 567 |
) decodeAsLiteralArray startUp |
568 |
" |
|
451 | 569 |
|
454 | 570 |
"extract from refactory213.st: |
571 |
#(#Menu #( |
|
1245 | 572 |
#(#MenuItem |
573 |
#label: 'File List' |
|
574 |
#accessCharacterPosition: 1 ) |
|
575 |
#(#MenuItem #label: 'File Editor...' |
|
576 |
#accessCharacterPosition: 6 ) |
|
577 |
#(#MenuItem #label: 'Refactoring Tool...' |
|
578 |
#accessCharacterPosition: 1 ) |
|
579 |
#(#MenuItem #label: 'Workspace' |
|
580 |
#accessCharacterPosition: 1 ) |
|
581 |
#(#MenuItem #label: 'New Canvas' |
|
582 |
#accessCharacterPosition: 1 ) |
|
583 |
#(#MenuItem #label: 'Palette' |
|
584 |
#accessCharacterPosition: 1 ) |
|
585 |
#(#MenuItem #label: 'Canvas Tool' |
|
586 |
#accessCharacterPosition: 1 ) |
|
587 |
#(#MenuItem #label: 'Image Editor' |
|
588 |
#accessCharacterPosition: 1 ) |
|
589 |
#(#MenuItem #label: 'Menu Editor' |
|
590 |
#accessCharacterPosition: 1 ) |
|
591 |
#(#MenuItem #label: 'Advanced' |
|
592 |
#accessCharacterPosition: 1 ) |
|
593 |
#(#MenuItem #label: 'DLL and C Connect' |
|
594 |
#accessCharacterPosition: 1 ) |
|
595 |
#(#MenuItem #label: 'System Transcript' |
|
596 |
#accessCharacterPosition: 8 ) |
|
597 |
) |
|
598 |
#(4 5 2 1 ) |
|
599 |
#(#openFileList #openFileEditor #openRefactoringTool #toolsNewWorkspace #toolsNewCanvas #toolsPalette #toolsCanvasTool #toolsMaskEditor #toolsMenuEditor nil #openExternalFinder #toggleSystemTranscript ) |
|
600 |
) decodeAsLiteralArray startUp |
|
454 | 601 |
" |
602 |
||
457 | 603 |
"submenus: |
604 |
#(#Menu #( |
|
1245 | 605 |
#(#MenuItem |
606 |
#label: 'Foo' |
|
607 |
#submenu: #(#Menu #( |
|
608 |
#(#MenuItem #label: 'foo 1') |
|
609 |
#(#MenuItem #label: 'foo 2') |
|
610 |
) |
|
611 |
nil |
|
612 |
#(11 22) |
|
613 |
) |
|
614 |
) |
|
615 |
#(#MenuItem |
|
616 |
#label: 'Inspect' ) |
|
617 |
#(#MenuItem |
|
618 |
#label: 'Coredump' ) |
|
619 |
) |
|
620 |
#(3 ) |
|
621 |
#(1 2 3 ) |
|
457 | 622 |
) decodeAsLiteralArray startUp |
623 |
" |
|
624 |
||
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
625 |
"Modified: 20.6.1997 / 10:45:51 / cg" |
489 | 626 |
! |
627 |
||
628 |
literalArrayEncoding |
|
629 |
"return myself encoded as a literal array" |
|
630 |
||
1245 | 631 |
|coll array size| |
489 | 632 |
|
633 |
coll := OrderedCollection new. |
|
634 |
coll add:#Menu. |
|
1245 | 635 |
|
636 |
(size := items size) == 0 ifTrue:[ |
|
637 |
array := nil |
|
638 |
] ifFalse:[ |
|
639 |
array := Array new:size. |
|
640 |
items keysAndValuesDo:[:anIndex :anItem| |
|
641 |
array at:anIndex put:(anItem literalArrayEncoding) |
|
642 |
] |
|
643 |
]. |
|
644 |
coll add:array. |
|
645 |
||
646 |
(size := groupSizes size) == 0 ifTrue:[ |
|
647 |
array := nil |
|
648 |
] ifFalse:[ |
|
649 |
array := Array new:size. |
|
650 |
groupSizes keysAndValuesDo:[:anIndex :aSize| |
|
651 |
array at:anIndex put:(aSize literalArrayEncoding) |
|
652 |
] |
|
653 |
]. |
|
654 |
coll add:array. |
|
489 | 655 |
coll add:nil. |
579 | 656 |
^ coll asArray |
451 | 657 |
! ! |
658 |
||
584 | 659 |
!Menu methodsFor:'enumerating'! |
660 |
||
665 | 661 |
allItemsDo:aOneArgBlock |
662 |
"evaluate block on each item and submenu items |
|
663 |
" |
|
664 |
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
|
665 |
|sub| |
724 | 666 |
|
972
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
667 |
aOneArgBlock value:anItem. |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
668 |
(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
|
669 |
sub allItemsDo:aOneArgBlock |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
670 |
] |
665 | 671 |
] |
724 | 672 |
|
972
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
673 |
"Modified: / 19.6.1998 / 00:34:53 / cg" |
665 | 674 |
! |
675 |
||
940 | 676 |
detectItem:aBlock |
677 |
"evaluate the argument, aBlock for each item in the menu until the |
|
678 |
block returns true; in this case return the item which caused the |
|
679 |
true evaluation. |
|
680 |
If none of the evaluations returns true, return the result of the |
|
681 |
evaluation of the exceptionBlock |
|
682 |
" |
|
683 |
^ self detectItem:aBlock ifNone:[self errorNotFound] |
|
684 |
||
685 |
! |
|
686 |
||
687 |
detectItem:aBlock ifNone:exceptionBlock |
|
688 |
"evaluate the argument, aBlock for each item in the menu until the |
|
689 |
block returns true; in this case return the item which caused the |
|
690 |
true evaluation. |
|
691 |
If none of the evaluations returns true, return the result of the |
|
692 |
evaluation of the exceptionBlock |
|
693 |
" |
|
694 |
items notNil ifTrue:[ |
|
695 |
^ items detect:aBlock ifNone:exceptionBlock |
|
696 |
]. |
|
697 |
^ exceptionBlock value |
|
698 |
! |
|
699 |
||
589 | 700 |
itemsDo:aOneArgBlock |
701 |
"evaluate the block for each item in the current menu |
|
702 |
" |
|
703 |
items notNil ifTrue:[items do:aOneArgBlock] |
|
704 |
! |
|
705 |
||
584 | 706 |
menuAndSubmenusDetectItem:aOneArgBlock |
707 |
"evaluate the block for each item in the current menu and all |
|
708 |
submenus. In case that the block returns a non nil argument, |
|
709 |
the item will be returned |
|
710 |
" |
|
724 | 711 |
|item| |
584 | 712 |
|
713 |
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
|
714 |
items do:[:anItem| |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
715 |
|sub| |
724 | 716 |
|
972
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
717 |
(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
|
718 |
^ anItem |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
719 |
]. |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
720 |
(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
|
721 |
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
|
722 |
item notNil ifTrue:[ |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
723 |
^ item |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
724 |
] |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
725 |
] |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
726 |
] |
584 | 727 |
]. |
724 | 728 |
^ nil |
729 |
||
972
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
730 |
"Modified: / 19.6.1998 / 00:35:00 / cg" |
584 | 731 |
! ! |
732 |
||
672
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
733 |
!Menu methodsFor:'kludged fixes'! |
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
734 |
|
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
735 |
destroy |
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
736 |
|
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
737 |
"Created: 28.7.1997 / 10:16:52 / cg" |
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
738 |
! ! |
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
739 |
|
584 | 740 |
!Menu methodsFor:'menu items'! |
741 |
||
740 | 742 |
someMenuItemLabeled:aLabel |
743 |
"get the menu item with that label; in case that the label |
|
744 |
is not found, nil is returned |
|
745 |
" |
|
746 |
^ self someMenuItemLabeled:aLabel ifNone:nil |
|
747 |
||
748 |
"Created: / 14.11.1997 / 20:55:17 / cg" |
|
749 |
! |
|
750 |
||
751 |
someMenuItemLabeled:aLabel ifNone:exceptionBlock |
|
752 |
"get the menu item labeled aLabel; in case that the value |
|
753 |
is not found, the given exceptionBlock is executed and its value returned |
|
754 |
" |
|
755 |
|item| |
|
756 |
||
757 |
item := self menuAndSubmenusDetectItem:[:anItem| anItem label = aLabel]. |
|
758 |
||
759 |
item notNil ifTrue:[ |
|
760 |
^ item |
|
761 |
]. |
|
762 |
^ exceptionBlock value |
|
763 |
||
764 |
"Created: / 14.11.1997 / 20:56:13 / cg" |
|
765 |
! |
|
766 |
||
584 | 767 |
someMenuItemWithValue:aValue |
768 |
"get the menu item assigned with the value; in case that the value |
|
769 |
is not found nil is returned |
|
770 |
" |
|
771 |
^ self someMenuItemWithValue:aValue ifNone:nil |
|
772 |
! |
|
773 |
||
774 |
someMenuItemWithValue:aValue ifNone:exceptionBlock |
|
775 |
"get the menu item assigned with the value; in case that the value |
|
776 |
is not found, the given exceptionBlock is executed and returned |
|
777 |
" |
|
778 |
|item| |
|
779 |
||
780 |
item := self menuAndSubmenusDetectItem:[:anItem| anItem value == aValue]. |
|
781 |
||
782 |
item notNil ifTrue:[ |
|
740 | 783 |
^ item |
584 | 784 |
]. |
785 |
^ exceptionBlock value |
|
786 |
! ! |
|
787 |
||
788 |
!Menu methodsFor:'queries'! |
|
789 |
||
724 | 790 |
hasHiddenItems |
791 |
"test whether any item is hidden" |
|
792 |
||
793 |
self allItemsDo:[:anItem| |
|
740 | 794 |
anItem isHidden ifTrue:[^ true] |
724 | 795 |
]. |
796 |
^ false |
|
797 |
||
798 |
"Modified: / 27.10.1997 / 15:12:44 / cg" |
|
799 |
! |
|
800 |
||
584 | 801 |
hasSubMenuAt:anIndex |
802 |
"test whether the menu item at the given index has a submenu |
|
803 |
" |
|
804 |
^ (self menuItemAt:anIndex) hasSubmenu |
|
805 |
! ! |
|
806 |
||
451 | 807 |
!Menu methodsFor:'startup'! |
808 |
||
729 | 809 |
show |
810 |
"realize the menu at its last position; returns the value associated with the |
|
811 |
selected item, 0 if none was selected" |
|
812 |
||
813 |
^ (MenuPanel menu:self) show ? 0 |
|
814 |
||
815 |
||
816 |
! |
|
817 |
||
818 |
showAt:aPoint |
|
819 |
"realize the menu at aPoint; returns the value associated with the |
|
820 |
selected item, 0 if none was selected" |
|
821 |
||
822 |
^ self showAt:aPoint resizing:true |
|
823 |
||
824 |
||
825 |
! |
|
826 |
||
827 |
showAt:aPoint resizing:aBoolean |
|
828 |
"realize the menu at aPoint; returns the value associated with the |
|
451 | 829 |
selected item, 0 if none was selected" |
830 |
||
996
1e10d01c90b8
careful: ? is a binary selector.
Claus Gittinger <cg@exept.de>
parents:
977
diff
changeset
|
831 |
^ ((MenuPanel menu:self) showAt:aPoint resizing:aBoolean) ? 0 |
1e10d01c90b8
careful: ? is a binary selector.
Claus Gittinger <cg@exept.de>
parents:
977
diff
changeset
|
832 |
|
1e10d01c90b8
careful: ? is a binary selector.
Claus Gittinger <cg@exept.de>
parents:
977
diff
changeset
|
833 |
"Modified: / 8.7.1998 / 19:57:55 / cg" |
729 | 834 |
! |
835 |
||
836 |
showAtPointer |
|
837 |
"realize the menu at the current pointer position; returns the value associated with the |
|
838 |
selected item, 0 if none was selected" |
|
839 |
||
840 |
^ self startUp |
|
841 |
! |
|
457 | 842 |
|
729 | 843 |
showCenteredIn:aView |
844 |
"realize the menu visible at the aView center; returns the value associated with the |
|
845 |
selected item, 0 if none was selected" |
|
846 |
||
996
1e10d01c90b8
careful: ? is a binary selector.
Claus Gittinger <cg@exept.de>
parents:
977
diff
changeset
|
847 |
^ ((MenuPanel menu:self) showCenteredIn:aView) ? 0 |
729 | 848 |
|
996
1e10d01c90b8
careful: ? is a binary selector.
Claus Gittinger <cg@exept.de>
parents:
977
diff
changeset
|
849 |
"Modified: / 8.7.1998 / 19:58:05 / cg" |
729 | 850 |
! |
851 |
||
852 |
startUp |
|
853 |
"display the menu as a popUp; returns the value associated with the |
|
854 |
selected item, 0 if none was selected" |
|
855 |
||
856 |
^ (MenuPanel menu:self) startUp ? 0 |
|
451 | 857 |
|
579 | 858 |
" |
740 | 859 |
|m| |
579 | 860 |
|
740 | 861 |
m := #(#Menu #( |
862 |
#(#MenuItem |
|
863 |
#rawLabel: 'left' |
|
864 |
#value: #left ) |
|
865 |
#(#MenuItem |
|
866 |
#rawLabel: 'center' |
|
867 |
#value: #center ) |
|
868 |
#(#MenuItem |
|
869 |
#rawLabel: 'right' |
|
870 |
#value: #right ) ) |
|
871 |
#(2) |
|
872 |
nil |
|
873 |
) decodeAsLiteralArray. |
|
451 | 874 |
|
579 | 875 |
Transcript showCR:(m startUp) |
876 |
" |
|
938
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
877 |
! |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
878 |
|
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
879 |
startUpAt:aPoint |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
880 |
"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
|
881 |
selected item, 0 if none was selected" |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
882 |
|
939 | 883 |
^ ((MenuPanel menu:self) startUpAt:aPoint) ? 0 |
938
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
884 |
|
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
885 |
" |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
886 |
|m| |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
887 |
|
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
888 |
m := #(#Menu #( |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
889 |
#(#MenuItem |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
890 |
#rawLabel: 'left' |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
891 |
#value: #left ) |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
892 |
#(#MenuItem |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
893 |
#rawLabel: 'center' |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
894 |
#value: #center ) |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
895 |
#(#MenuItem |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
896 |
#rawLabel: 'right' |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
897 |
#value: #right ) ) |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
898 |
#(2) |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
899 |
nil |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
900 |
) decodeAsLiteralArray. |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
901 |
|
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
902 |
Transcript showCR:(m startUpAt:100@100) |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
903 |
" |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
904 |
|
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
905 |
"Created: / 21.5.1998 / 14:15:21 / cg" |
939 | 906 |
"Modified: / 21.5.1998 / 14:17:46 / cg" |
451 | 907 |
! ! |
908 |
||
909 |
!Menu class methodsFor:'documentation'! |
|
910 |
||
911 |
version |
|
1247 | 912 |
^ '$Header: /cvs/stx/stx/libview2/Menu.st,v 1.40 1999-10-04 10:45:59 cg Exp $' |
451 | 913 |
! ! |