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