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