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