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