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