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