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