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