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