author | Claus Gittinger <cg@exept.de> |
Fri, 11 Jan 2013 16:13:27 +0100 | |
changeset 3053 | 2c1b6c1e317f |
parent 3028 | 29a0a22942fe |
child 3117 | 3c7f6b69b2c5 |
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 |
" |
|
1367 | 12 |
"{ Package: 'stx:libview2' }" |
13 |
||
2854
d37c539b59ad
inherit from model, for cheap dependents.
Claus Gittinger <cg@exept.de>
parents:
2814
diff
changeset
|
14 |
Model subclass:#Menu |
579 | 15 |
instanceVariableNames:'items groupSizes receiver' |
451 | 16 |
classVariableNames:'' |
17 |
poolDictionaries:'' |
|
18 |
category:'Views-Support' |
|
19 |
! |
|
20 |
||
21 |
!Menu class methodsFor:'documentation'! |
|
22 |
||
1354 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
||
36 |
||
37 |
! |
|
38 |
||
451 | 39 |
documentation |
40 |
" |
|
41 |
not yet finished Menu class - this will eventually replace |
|
42 |
most of the MenuView and PopUpMenu stuff. |
|
43 |
(and hopefully be ST-80 compatible ...) |
|
44 |
||
45 |
For now, only a subset of the full protocol is implemented. |
|
46 |
||
47 |
[author:] |
|
740 | 48 |
Claus Gittinger |
451 | 49 |
|
50 |
[see also:] |
|
740 | 51 |
MenuItem |
52 |
PopUpMenu |
|
451 | 53 |
" |
54 |
! ! |
|
55 |
||
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
56 |
!Menu class methodsFor:'instance creation'! |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
57 |
|
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
58 |
labelArray:arrayOfString lines:linesArray values:valueArrayOrNil |
737 | 59 |
"return a menu with menu items built with labels from arrayOfString (not Symbols). |
60 |
The linesArray describes which menu items are the last menu item in their group. |
|
61 |
The valueArray contains value objects for each menu item |
|
62 |
(or is nil if no value objects are specified)." |
|
63 |
||
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
64 |
|nLabel valueArray menuItems groupLengths| |
737 | 65 |
|
66 |
nLabel := arrayOfString size. |
|
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
67 |
|
737 | 68 |
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
|
69 |
(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
|
70 |
valueArray := #() |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
71 |
] ifFalse:[ |
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 := (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
|
73 |
] |
737 | 74 |
] 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
|
75 |
valueArray := valueArrayOrNil |
737 | 76 |
]. |
77 |
||
78 |
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
|
79 |
^ self error: 'illegal menu combination' |
737 | 80 |
]. |
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
81 |
|
737 | 82 |
menuItems := Array new:nLabel. |
83 |
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
|
84 |
|mi v| |
737 | 85 |
|
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
86 |
mi := MenuItem labeled:(arrayOfString at:i) asString. |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
87 |
v := valueArray at:i. |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
88 |
(v isKindOf:Menu) ifTrue:[mi submenu:v]. |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
89 |
menuItems at:i put:mi |
737 | 90 |
]. |
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
91 |
|
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
92 |
(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
|
93 |
groupLengths := (menuItems isEmpty) |
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
94 |
ifTrue: [Array new:0] |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
95 |
ifFalse: [Array with:menuItems size] |
737 | 96 |
] ifFalse:[ |
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
97 |
groupLengths := Array new:(linesArray size + 1). |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
98 |
groupLengths at:1 put:linesArray first. |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
99 |
2 to:linesArray size do: [:i | |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
100 |
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
|
101 |
]. |
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
102 |
groupLengths at:groupLengths size put:(menuItems size - linesArray last). |
737 | 103 |
]. |
104 |
||
105 |
^ self new |
|
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
106 |
menuItems:menuItems |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
107 |
menuItemGroups:groupLengths |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
108 |
values:valueArray |
737 | 109 |
|
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
110 |
"Modified: / 19.4.1998 / 11:30:18 / cg" |
696 | 111 |
! |
112 |
||
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
113 |
labelArray:arrayOfString values:valueArrayOrNil |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
114 |
"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
|
115 |
The valueArray contains value objects for each menu item |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
116 |
(or is nil if no value objects are specified)." |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
117 |
|
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
118 |
^ self |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
119 |
labelArray:arrayOfString |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
120 |
lines:nil |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
121 |
values: valueArrayOrNil |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
122 |
|
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
123 |
! |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
124 |
|
696 | 125 |
labelList:arrayOfGroupStrings values:valueArrayOrNil |
126 |
|labels lines| |
|
127 |
||
128 |
lines := arrayOfGroupStrings collect:[:each | each size]. |
|
2017 | 129 |
labels := arrayOfGroupStrings collectAll:[:eachGroup | eachGroup]. |
696 | 130 |
^ self labelArray:labels lines:lines values:valueArrayOrNil |
131 |
||
132 |
"Modified: 20.6.1997 / 10:46:45 / cg" |
|
133 |
"Created: 13.9.1997 / 10:35:46 / cg" |
|
737 | 134 |
! |
135 |
||
738 | 136 |
labels:aString lines:linesArray values:valueArrayOrNil |
737 | 137 |
^ self |
740 | 138 |
labelArray:(aString asCollectionOfLines) |
139 |
lines:linesArray |
|
140 |
values:valueArrayOrNil |
|
737 | 141 |
|
142 |
"Created: / 31.10.1997 / 03:12:20 / cg" |
|
738 | 143 |
"Modified: / 31.10.1997 / 03:23:42 / cg" |
1525 | 144 |
! |
145 |
||
146 |
labels:aString values:valueArrayOrNil |
|
147 |
^ self |
|
148 |
labelArray:(aString asCollectionOfLines) |
|
149 |
lines:#() |
|
150 |
values:valueArrayOrNil |
|
151 |
||
152 |
"Modified: / 31.10.1997 / 03:23:42 / cg" |
|
153 |
"Created: / 12.11.2001 / 16:06:36 / cg" |
|
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
154 |
! ! |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
155 |
|
1764 | 156 |
!Menu methodsFor:'Compatibility-ST80'! |
724 | 157 |
|
2126 | 158 |
addLine |
159 |
self addSeparator |
|
160 |
! |
|
161 |
||
724 | 162 |
indexOfMenuItem:anItem |
2433 | 163 |
^ items indexOf:anItem |
724 | 164 |
|
2433 | 165 |
"Created: / 27.10.1997 / 16:34:19 / cg" |
166 |
! |
|
167 |
||
168 |
indexOfMenuItemForWhich:aBlock |
|
169 |
^ items findFirst:aBlock |
|
724 | 170 |
|
171 |
"Created: / 27.10.1997 / 16:34:19 / cg" |
|
172 |
! |
|
173 |
||
174 |
menuButtons |
|
175 |
"ST-80 seems to use a special menuButton class here. |
|
176 |
Here, kludge a collection of menuItems." |
|
177 |
||
178 |
^ items |
|
179 |
||
180 |
"Created: / 27.10.1997 / 16:33:35 / cg" |
|
181 |
! ! |
|
182 |
||
1782 | 183 |
!Menu methodsFor:'Compatibility-Squeak'! |
184 |
||
2764 | 185 |
add:label target:target selector:selector |
186 |
self addItem:(MenuItem label:label value:[target perform:selector]). |
|
187 |
! |
|
188 |
||
189 |
balloonTextForLastItem:aString |
|
190 |
items last helpText:aString |
|
191 |
! |
|
192 |
||
1782 | 193 |
labels:labels lines:lines selections:selections |
194 |
|labelArray| |
|
195 |
||
196 |
labels isString ifTrue:[ |
|
197 |
labelArray := labels asCollectionOfLines. |
|
198 |
] ifFalse:[ |
|
199 |
labelArray := labels. |
|
200 |
]. |
|
201 |
||
202 |
1 to:labelArray size do:[:idx | |
|
203 |
|item| |
|
204 |
||
205 |
item := MenuItem new. |
|
206 |
item label:(labelArray at:idx). |
|
3022 | 207 |
item itemValue:(selections at:idx). |
1782 | 208 |
self addItem:item. |
209 |
||
210 |
(lines includes:idx) ifTrue:[ |
|
211 |
self addSeparator. |
|
212 |
]. |
|
213 |
]. |
|
3022 | 214 |
|
215 |
"Modified: / 09-09-2012 / 13:08:55 / cg" |
|
1782 | 216 |
! ! |
217 |
||
451 | 218 |
!Menu methodsFor:'accessing'! |
219 |
||
2916
ff96b6187a5f
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
220 |
atMenuItemLabeled:aString putSubmenu:aMenu visible:visible |
ff96b6187a5f
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
221 |
(self menuItemLabeled:aString) |
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
222 |
submenu:aMenu; |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
223 |
isVisible:visible |
2916
ff96b6187a5f
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
224 |
|
ff96b6187a5f
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
225 |
"Created: / 30-06-2011 / 10:30:22 / cg" |
ff96b6187a5f
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
226 |
! |
ff96b6187a5f
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
227 |
|
696 | 228 |
atNameKey:aNameKey |
724 | 229 |
"return the menuItem for the given nameKey; nil if no such item is in the menu. |
230 |
Searches in allItems (i.e. also in subMenus)" |
|
696 | 231 |
|
724 | 232 |
self allItemsDo:[:anItem| |
740 | 233 |
anItem nameKey == aNameKey ifTrue:[^ anItem] |
724 | 234 |
]. |
696 | 235 |
^ nil |
236 |
||
724 | 237 |
"Modified: / 27.10.1997 / 15:12:00 / cg" |
696 | 238 |
! |
239 |
||
578 | 240 |
groupSizes |
1500 | 241 |
^ groupSizes |
242 |
! |
|
578 | 243 |
|
244 |
groupSizes:something |
|
1500 | 245 |
groupSizes := something. |
246 |
! |
|
578 | 247 |
|
1986 | 248 |
items |
249 |
^ items |
|
250 |
! |
|
251 |
||
584 | 252 |
labelAt:anIndex |
253 |
"gets the label of the menu item at the given index or nil |
|
254 |
" |
|
255 |
|item| |
|
256 |
||
257 |
(item := self menuItemAt:anIndex) notNil ifTrue:[ |
|
801 | 258 |
^ item label |
584 | 259 |
]. |
801 | 260 |
^ nil |
584 | 261 |
|
801 | 262 |
"Modified: / 2.2.1998 / 13:28:32 / cg" |
584 | 263 |
! |
264 |
||
265 |
labelAtValue:aValue |
|
266 |
"gets the label of the menu item assigned to value |
|
267 |
" |
|
268 |
|item| |
|
269 |
||
801 | 270 |
item := self menuAndSubmenusDetectItem:[:anItem | anItem value == aValue ]. |
584 | 271 |
|
272 |
item notNil ifTrue:[ |
|
801 | 273 |
^ item label |
584 | 274 |
]. |
801 | 275 |
^ nil |
584 | 276 |
|
801 | 277 |
"Modified: / 2.2.1998 / 13:28:28 / cg" |
584 | 278 |
! |
279 |
||
451 | 280 |
labels |
281 |
"return a collection of labels from my items" |
|
282 |
||
977
e07277070839
return valid collection in #labels.
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
283 |
items isNil ifTrue:[^ #()]. |
451 | 284 |
^ items collect:[:anItem | anItem label] |
285 |
||
972
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
286 |
"Created: / 25.2.1997 / 19:47:53 / cg" |
977
e07277070839
return valid collection in #labels.
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
287 |
"Modified: / 19.6.1998 / 02:36:22 / cg" |
451 | 288 |
! |
289 |
||
940 | 290 |
lastItem |
2584 | 291 |
"returns the last item or nil, if there are none" |
292 |
||
293 |
^ items isEmptyOrNil |
|
294 |
ifTrue:[nil] |
|
295 |
ifFalse:[items last] |
|
940 | 296 |
! |
297 |
||
489 | 298 |
lines |
737 | 299 |
"return the indexes of the menu items that are the last menu item in their group (except the very last)." |
489 | 300 |
|
801 | 301 |
|lines groupSz| |
737 | 302 |
|
801 | 303 |
(groupSz := groupSizes size) <= 1 ifTrue: [^ Array new]. |
304 |
lines := Array new:(groupSz - 1). |
|
305 |
lines at:1 put:groupSizes first. |
|
306 |
2 to:(groupSz-1) do:[:i | |
|
307 |
lines at:i put:(lines at:(i - 1)) + (groupSizes at:i) |
|
308 |
]. |
|
309 |
^ lines |
|
489 | 310 |
|
801 | 311 |
"Modified: / 2.2.1998 / 13:28:19 / cg" |
489 | 312 |
! |
313 |
||
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
314 |
menuItemAt:index |
584 | 315 |
"gets the menu item at the given index. When the index is out of bounds |
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
316 |
nil is returned" |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
317 |
|
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
318 |
(index > 0 and:[ index <= items size ]) ifTrue:[ |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
319 |
^ items at:index |
584 | 320 |
]. |
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
321 |
^ nil |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
322 |
|
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
323 |
"Modified: / 30-06-2011 / 10:51:39 / cg" |
489 | 324 |
! |
325 |
||
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
326 |
menuItemLabeled:anItemLabel |
724 | 327 |
"return the menuItem for the given nameKey; nil if no such item is in the menu. |
328 |
Searches all items (i.e. also submenu items)" |
|
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
329 |
|
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
330 |
self |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
331 |
allItemsDo:[:anItem | |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
332 |
|l| |
724 | 333 |
|
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
334 |
((l := anItem label) sameAs:anItemLabel) ifTrue:[ |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
335 |
^ anItem |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
336 |
]. |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
337 |
(l includes:$&) ifTrue:[ |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
338 |
((l copyWithout:$&) sameAs:anItemLabel) ifTrue:[ |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
339 |
^ anItem |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
340 |
] |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
341 |
] |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
342 |
]. |
724 | 343 |
^ nil |
344 |
||
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
345 |
"Created: / 13-09-1997 / 10:25:16 / cg" |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
346 |
"Modified: / 30-06-2011 / 10:51:44 / cg" |
724 | 347 |
! |
348 |
||
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
349 |
menuItemWithArgument:aValue |
2908
e21010b76553
added: #menuItemWithArgument:
Claus Gittinger <cg@exept.de>
parents:
2867
diff
changeset
|
350 |
"return the menuItem for the given value; nil if no such item is in the menu. |
e21010b76553
added: #menuItemWithArgument:
Claus Gittinger <cg@exept.de>
parents:
2867
diff
changeset
|
351 |
Searches all items (i.e. also submenu items)" |
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
352 |
|
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
353 |
self |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
354 |
allItemsDo:[:anItem | |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
355 |
|l| |
2908
e21010b76553
added: #menuItemWithArgument:
Claus Gittinger <cg@exept.de>
parents:
2867
diff
changeset
|
356 |
|
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
357 |
(anItem argument = aValue) ifTrue:[ |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
358 |
^ anItem |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
359 |
]. |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
360 |
]. |
2908
e21010b76553
added: #menuItemWithArgument:
Claus Gittinger <cg@exept.de>
parents:
2867
diff
changeset
|
361 |
^ nil |
e21010b76553
added: #menuItemWithArgument:
Claus Gittinger <cg@exept.de>
parents:
2867
diff
changeset
|
362 |
|
e21010b76553
added: #menuItemWithArgument:
Claus Gittinger <cg@exept.de>
parents:
2867
diff
changeset
|
363 |
"Created: / 19-04-2011 / 14:42:18 / cg" |
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
364 |
"Modified: / 30-06-2011 / 10:51:50 / cg" |
2908
e21010b76553
added: #menuItemWithArgument:
Claus Gittinger <cg@exept.de>
parents:
2867
diff
changeset
|
365 |
! |
e21010b76553
added: #menuItemWithArgument:
Claus Gittinger <cg@exept.de>
parents:
2867
diff
changeset
|
366 |
|
2952
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
367 |
menuItemWithKey:aValue |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
368 |
"return the menuItem for the given key; nil if no such item is in the menu. |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
369 |
Searches all items (i.e. also submenu items)" |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
370 |
|
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
371 |
self |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
372 |
allItemsDo:[:anItem | |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
373 |
|
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
374 |
(anItem nameKey = aValue) ifTrue:[ |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
375 |
^ anItem |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
376 |
]. |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
377 |
]. |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
378 |
^ nil |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
379 |
|
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
380 |
"Created: / 19-04-2011 / 14:42:18 / cg" |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
381 |
"Modified: / 30-06-2011 / 10:51:50 / cg" |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
382 |
"Created: / 07-10-2011 / 15:04:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
383 |
! |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
384 |
|
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
385 |
menuItemWithValue:aValue |
1652 | 386 |
"return the menuItem for the given value; nil if no such item is in the menu. |
387 |
Searches all items (i.e. also submenu items)" |
|
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
388 |
|
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
389 |
self |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
390 |
allItemsDo:[:anItem | |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
391 |
|l| |
1652 | 392 |
|
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
393 |
(anItem value == aValue) ifTrue:[ |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
394 |
^ anItem |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
395 |
]. |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
396 |
]. |
1652 | 397 |
^ nil |
398 |
||
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
399 |
"Created: / 13-09-1997 / 10:25:16 / cg" |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
400 |
"Modified: / 30-06-2011 / 10:51:56 / cg" |
1652 | 401 |
! |
402 |
||
489 | 403 |
menuItems |
1327
b0b482a84570
menuItems always returns a collection (never nil)
Claus Gittinger <cg@exept.de>
parents:
1308
diff
changeset
|
404 |
^ items ? #() |
489 | 405 |
! |
406 |
||
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
407 |
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
|
408 |
|n| |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
409 |
|
1620
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
410 |
items := groupSizes := nil. |
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
411 |
|
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
412 |
aCollectionOfMenuItems size == 0 ifTrue:[ ^ self ]. |
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
413 |
|
451 | 414 |
items := aCollectionOfMenuItems. |
1620
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
415 |
|
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
416 |
sizes size > 0 ifTrue:[ |
1620
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
417 |
groupSizes := sizes. |
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
418 |
|
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
419 |
n := sizes inject:0 into:[:sumSoFar :this | sumSoFar + this]. |
1620
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
420 |
|
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
421 |
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
|
422 |
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
|
423 |
] |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
424 |
]. |
451 | 425 |
|
579 | 426 |
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
|
427 |
items with:values do:[:anItem :aValue |anItem value:aValue] |
454 | 428 |
]. |
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
429 |
|
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
430 |
"Modified: / 19.4.1998 / 11:47:34 / cg" |
451 | 431 |
! |
432 |
||
1116 | 433 |
menuPerformer:something |
434 |
"set the receiver of the menu messages" |
|
435 |
||
436 |
receiver := something. |
|
437 |
||
438 |
"Modified: / 2.2.1998 / 13:26:29 / cg" |
|
439 |
! |
|
440 |
||
494 | 441 |
numberOfItems |
801 | 442 |
"return the number of items in this menu" |
443 |
||
494 | 444 |
^ items size |
445 |
||
801 | 446 |
"Created: / 6.3.1997 / 15:15:53 / cg" |
447 |
"Modified: / 2.2.1998 / 13:26:40 / cg" |
|
494 | 448 |
! |
449 |
||
579 | 450 |
receiver |
801 | 451 |
"return the receiver of the menu messages" |
579 | 452 |
|
801 | 453 |
^ receiver |
454 |
||
455 |
"Modified: / 2.2.1998 / 13:26:20 / cg" |
|
456 |
! |
|
579 | 457 |
|
458 |
receiver:something |
|
801 | 459 |
"set the receiver of the menu messages" |
579 | 460 |
|
801 | 461 |
receiver := something. |
462 |
||
463 |
"Modified: / 2.2.1998 / 13:26:29 / cg" |
|
464 |
! |
|
579 | 465 |
|
451 | 466 |
valueAt:index |
467 |
"return a collection of values from my items" |
|
468 |
||
469 |
^ (items at:index) value |
|
470 |
||
471 |
"Created: 25.2.1997 / 19:49:41 / cg" |
|
472 |
! |
|
473 |
||
494 | 474 |
valueAt:anIndex put:aValue |
475 |
"put value an an index" |
|
476 |
||
477 |
(items at:anIndex) value:aValue |
|
478 |
||
479 |
"Created: 6.3.1997 / 15:15:48 / cg" |
|
480 |
! |
|
481 |
||
451 | 482 |
values |
483 |
"return a collection of values from my items" |
|
484 |
||
485 |
^ items collect:[:anItem | anItem value] |
|
486 |
||
487 |
"Created: 25.2.1997 / 19:49:29 / cg" |
|
724 | 488 |
! |
489 |
||
490 |
values:aCollectionOfValues |
|
491 |
"return a collection of values from my items" |
|
492 |
||
493 |
|s| |
|
494 |
||
495 |
s := aCollectionOfValues readStream. |
|
496 |
self itemsDo:[:item | |
|
1111 | 497 |
|val| |
724 | 498 |
|
1111 | 499 |
val := s next. |
500 |
item value:val |
|
724 | 501 |
]. |
1111 | 502 |
s atEnd ifFalse:[ |
2092 | 503 |
self error:'not enough elements in the value collection' mayProceed:true |
1111 | 504 |
] |
724 | 505 |
|
506 |
"Created: / 27.10.1997 / 15:15:47 / cg" |
|
507 |
! |
|
508 |
||
509 |
visibleMenuItemGroups |
|
801 | 510 |
|itemGroups visibleItemGroups nextItem| |
724 | 511 |
|
801 | 512 |
itemGroups := OrderedCollection new. |
513 |
nextItem := 1. |
|
514 |
groupSizes do:[:groupSize | |
|
515 |
itemGroups addLast: (items copyFrom:nextItem to:nextItem + groupSize - 1). |
|
516 |
nextItem := nextItem + groupSize |
|
517 |
]. |
|
518 |
self hasHiddenItems ifFalse:[^ itemGroups]. |
|
724 | 519 |
|
801 | 520 |
"Remove the hidden items." |
521 |
visibleItemGroups := OrderedCollection new. |
|
522 |
itemGroups do:[:eachItemGroup | |
|
523 |
|visibleItemGroup| |
|
524 |
||
525 |
visibleItemGroup := eachItemGroup reject:[:eachMenuItem | eachMenuItem hidden]. |
|
2129 | 526 |
visibleItemGroup notEmpty ifTrue:[ |
801 | 527 |
visibleItemGroups addLast: visibleItemGroup |
528 |
] |
|
529 |
]. |
|
530 |
^ visibleItemGroups |
|
724 | 531 |
|
532 |
"Created: / 27.10.1997 / 15:07:50 / cg" |
|
801 | 533 |
"Modified: / 2.2.1998 / 13:25:52 / cg" |
451 | 534 |
! ! |
535 |
||
1397 | 536 |
!Menu methodsFor:'accessing-resource'! |
582 | 537 |
|
584 | 538 |
findGuiResourcesIn:aResourceContainerOrApplication |
2269
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
539 |
"setup a resource owner" |
1986 | 540 |
|
541 |
receiver isNil ifTrue:[ |
|
542 |
receiver := aResourceContainerOrApplication |
|
543 |
]. |
|
2269
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
544 |
^ self |
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
545 |
findGuiResourcesIn:aResourceContainerOrApplication |
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
546 |
rememberResourcesIn:(ValueHolder new) |
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
547 |
|
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
548 |
"Modified: / 26-10-2006 / 16:37:57 / cg" |
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
549 |
! |
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
550 |
|
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
551 |
findGuiResourcesIn:aResourceContainerOrApplication rememberResourcesIn:aValueHolderOrNil |
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
552 |
"setup a resource owner" |
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
553 |
|
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
554 |
|resolvedItems rcv| |
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
555 |
|
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
556 |
"/ cg: do not recursively change the receiver - it could be set for the top |
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
557 |
"/ menu via #receiver: by the application. |
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
558 |
"/ if the submenu's receiver is nil, the parentmenus receiver will be used, which is ok. |
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
559 |
"/ But if it was changed below, we would need a recursive setting in #receiver: as well. |
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
560 |
|
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
561 |
"/ receiver isNil ifTrue:[ |
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
562 |
"/ receiver := aResourceContainerOrApplication |
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
563 |
"/ ]. |
1986 | 564 |
items isEmptyOrNil ifTrue:[^ self]. |
565 |
||
566 |
resolvedItems := OrderedCollection new. |
|
567 |
||
568 |
items do:[:anItem | |
|
2867 | 569 |
anItem isMenuSlice ifTrue:[ |
570 |
|resItems| |
|
571 |
||
2059
36e4aa247402
fixed menu-slice resolving (search in masterApplication too)
Claus Gittinger <cg@exept.de>
parents:
2039
diff
changeset
|
572 |
rcv := aResourceContainerOrApplication. |
36e4aa247402
fixed menu-slice resolving (search in masterApplication too)
Claus Gittinger <cg@exept.de>
parents:
2039
diff
changeset
|
573 |
[rcv notNil and:[resItems isNil]] whileTrue:[ |
36e4aa247402
fixed menu-slice resolving (search in masterApplication too)
Claus Gittinger <cg@exept.de>
parents:
2039
diff
changeset
|
574 |
resItems := anItem resolveSliceMenuItemsIn:rcv |
36e4aa247402
fixed menu-slice resolving (search in masterApplication too)
Claus Gittinger <cg@exept.de>
parents:
2039
diff
changeset
|
575 |
rememberResourcesIn:aValueHolderOrNil. |
36e4aa247402
fixed menu-slice resolving (search in masterApplication too)
Claus Gittinger <cg@exept.de>
parents:
2039
diff
changeset
|
576 |
rcv := rcv perform:#masterApplication ifNotUnderstood:nil. |
36e4aa247402
fixed menu-slice resolving (search in masterApplication too)
Claus Gittinger <cg@exept.de>
parents:
2039
diff
changeset
|
577 |
]. |
1986 | 578 |
|
579 |
resItems notEmptyOrNil ifTrue:[ |
|
580 |
resolvedItems addAll:resItems. |
|
581 |
] |
|
582 |
] ifFalse:[ |
|
583 |
anItem |
|
584 |
findGuiResourcesIn:aResourceContainerOrApplication |
|
585 |
rememberResourcesIn:aValueHolderOrNil. |
|
586 |
||
587 |
resolvedItems add:anItem. |
|
1534
292c277fcf6a
findGuiResources... now sets the receiver, if not yet set
Claus Gittinger <cg@exept.de>
parents:
1532
diff
changeset
|
588 |
]. |
1986 | 589 |
]. |
590 |
items := resolvedItems. |
|
2269
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
591 |
|
2867 | 592 |
"Modified: / 22-09-2010 / 13:34:38 / cg" |
582 | 593 |
! ! |
594 |
||
940 | 595 |
!Menu methodsFor:'adding & removing'! |
596 |
||
597 |
addItem:aMenuItem |
|
1029 | 598 |
"add a menuItem at the end; |
599 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
600 |
||
940 | 601 |
items isNil ifTrue:[ |
1029 | 602 |
items := OrderedCollection new |
603 |
] ifFalse:[ |
|
604 |
items := items asOrderedCollection |
|
940 | 605 |
]. |
606 |
items add:aMenuItem. |
|
1029 | 607 |
|
608 |
"Modified: / 4.8.1998 / 17:31:13 / cg" |
|
940 | 609 |
! |
610 |
||
611 |
addItem:aMenuItem beforeIndex:anIndex |
|
1029 | 612 |
"add a menuItem at some position; |
613 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
614 |
||
940 | 615 |
items isNil ifTrue:[ |
616 |
items := OrderedCollection new |
|
1029 | 617 |
] ifFalse:[ |
618 |
items := items asOrderedCollection |
|
940 | 619 |
]. |
620 |
items add:aMenuItem beforeIndex:anIndex. |
|
1029 | 621 |
|
622 |
"Modified: / 4.8.1998 / 17:31:39 / cg" |
|
940 | 623 |
! |
624 |
||
625 |
addItem:aMenuItem value:aValue |
|
3022 | 626 |
aMenuItem itemValue:aValue. |
940 | 627 |
self addItem:aMenuItem. |
3022 | 628 |
|
629 |
"Modified: / 09-09-2012 / 13:08:50 / cg" |
|
940 | 630 |
! |
631 |
||
1758 | 632 |
addItemGroup:aGroup |
1029 | 633 |
"add a group of items at the end; |
634 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
635 |
||
940 | 636 |
groupSizes isNil ifTrue:[ |
1758 | 637 |
groupSizes := OrderedCollection with:items size. |
940 | 638 |
]. |
1758 | 639 |
groupSizes add:aGroup size. |
940 | 640 |
|
1758 | 641 |
aGroup do:[:item | |
1029 | 642 |
self addItem:item |
940 | 643 |
]. |
644 |
||
645 |
"Created: / 27.10.1997 / 15:02:15 / cg" |
|
1029 | 646 |
"Modified: / 4.8.1998 / 17:32:06 / cg" |
940 | 647 |
! |
648 |
||
649 |
addItemGroup:aGroup values:values |
|
1029 | 650 |
"add a group of items at the end; |
651 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
652 |
||
1758 | 653 |
aGroup with:values do:[:item :value | |
654 |
item value:value |
|
940 | 655 |
]. |
1758 | 656 |
self addItemGroup:aGroup |
1029 | 657 |
|
658 |
"Modified: / 4.8.1998 / 17:32:18 / cg" |
|
940 | 659 |
! |
660 |
||
661 |
addItemGroupLabels:labels values:values |
|
1029 | 662 |
"add a group of items at the end; |
663 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
664 |
||
940 | 665 |
|items| |
666 |
||
667 |
items := labels with:values |
|
1029 | 668 |
collect:[:label :value | |
669 |
MenuItem label:label value:value |
|
670 |
]. |
|
940 | 671 |
self addItemGroup:items |
672 |
||
673 |
"Created: / 27.10.1997 / 19:49:27 / cg" |
|
1029 | 674 |
"Modified: / 4.8.1998 / 17:35:22 / cg" |
940 | 675 |
! |
676 |
||
677 |
addItemLabel:label value:value |
|
1029 | 678 |
"add an item at the end; |
679 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
940 | 680 |
|
1029 | 681 |
self addItem:(MenuItem label:label value:value) |
940 | 682 |
|
683 |
"Created: / 27.10.1997 / 19:47:12 / cg" |
|
1029 | 684 |
"Modified: / 4.8.1998 / 17:34:44 / cg" |
940 | 685 |
! |
686 |
||
1500 | 687 |
addSeparator |
688 |
"add a separating line item at the end; |
|
689 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
690 |
||
2814 | 691 |
self addItem:(MenuItem separator). |
1500 | 692 |
! |
693 |
||
940 | 694 |
removeItem:aMenuItem |
695 |
"remove an item from the menu" |
|
696 |
||
697 |
|idx| |
|
698 |
||
699 |
items notNil ifTrue:[ |
|
700 |
idx := items identityIndexOf:aMenuItem. |
|
701 |
idx ~~ 0 ifTrue:[ |
|
702 |
items removeAtIndex:idx |
|
703 |
] |
|
704 |
]. |
|
705 |
||
706 |
"Created: / 13.9.1997 / 10:27:31 / cg" |
|
707 |
"Modified: / 2.2.1998 / 13:26:49 / cg" |
|
708 |
! |
|
709 |
||
710 |
removeItemAt:anIndex |
|
711 |
"remove item at an index |
|
712 |
" |
|
713 |
anIndex <= items size ifTrue:[ |
|
714 |
^ items removeAtIndex:anIndex |
|
715 |
]. |
|
716 |
^ nil |
|
717 |
! ! |
|
718 |
||
451 | 719 |
!Menu methodsFor:'converting'! |
720 |
||
2081 | 721 |
asOldStylePopUpMenuFor:anApplicationOrNil |
2080 | 722 |
"a temporary kludge - will vanish, when oldStyle MenuView and PopUpMenu are gone" |
723 |
||
2081 | 724 |
|menuView itemsShown| |
725 |
||
2867 | 726 |
itemsShown := items |
727 |
select:[:each | |
|
2081 | 728 |
|visibilityInItem| |
729 |
||
730 |
visibilityInItem := each isVisible. |
|
731 |
visibilityInItem isNil ifTrue:[ |
|
732 |
true |
|
733 |
] ifFalse:[ |
|
734 |
visibilityInItem isBoolean ifTrue:[ |
|
735 |
visibilityInItem |
|
736 |
] ifFalse:[ |
|
737 |
visibilityInItem isSymbol ifTrue:[ |
|
2917
2ba0fee85a7f
changed: #asOldStylePopUpMenuFor:
Claus Gittinger <cg@exept.de>
parents:
2916
diff
changeset
|
738 |
anApplicationOrNil isNil |
2ba0fee85a7f
changed: #asOldStylePopUpMenuFor:
Claus Gittinger <cg@exept.de>
parents:
2916
diff
changeset
|
739 |
or:[ (anApplicationOrNil perform:visibilityInItem) value ]. |
2081 | 740 |
] ifFalse:[ |
741 |
visibilityInItem value |
|
742 |
]. |
|
743 |
]. |
|
744 |
]. |
|
745 |
]. |
|
2080 | 746 |
|
747 |
menuView := MenuView |
|
2081 | 748 |
labels:(itemsShown collect:[:each | each label]) |
749 |
selectors:(itemsShown collect:[:each | each value]) |
|
2751
d0729d604864
changed: #asOldStylePopUpMenuFor:
Claus Gittinger <cg@exept.de>
parents:
2584
diff
changeset
|
750 |
accelerators:(itemsShown collect:[:each | each shortcutKey]) |
2081 | 751 |
args:(itemsShown collect:[:each | each argument]) |
2080 | 752 |
receiver:receiver. |
753 |
||
2092 | 754 |
itemsShown doWithIndex:[:each :idx | |
2081 | 755 |
|enabledInItem enabled| |
756 |
||
757 |
enabledInItem := each enabled. |
|
758 |
enabledInItem notNil ifTrue:[ |
|
759 |
enabledInItem isSymbol ifTrue:[ |
|
2917
2ba0fee85a7f
changed: #asOldStylePopUpMenuFor:
Claus Gittinger <cg@exept.de>
parents:
2916
diff
changeset
|
760 |
enabled := anApplicationOrNil isNil or:[ (anApplicationOrNil perform:enabledInItem) ]. |
2081 | 761 |
] ifFalse:[ |
3028
29a0a22942fe
changed: #asOldStylePopUpMenuFor:
Claus Gittinger <cg@exept.de>
parents:
3022
diff
changeset
|
762 |
enabled := enabledInItem |
2081 | 763 |
]. |
764 |
enabled value ifFalse:[ |
|
2092 | 765 |
menuView disable:idx |
2081 | 766 |
]. |
767 |
]. |
|
768 |
]. |
|
769 |
||
2092 | 770 |
menuView actions:(itemsShown collect:[:each | [ receiver perform:each value ]]). |
2080 | 771 |
|
772 |
^ PopUpMenu forMenu:menuView |
|
2867 | 773 |
|
2917
2ba0fee85a7f
changed: #asOldStylePopUpMenuFor:
Claus Gittinger <cg@exept.de>
parents:
2916
diff
changeset
|
774 |
"Modified: / 30-06-2011 / 10:35:57 / cg" |
2080 | 775 |
! |
776 |
||
451 | 777 |
fromLiteralArrayEncoding:aLiteralEncodedArray |
778 |
"read my contents from a aLiteralEncodedArray" |
|
779 |
||
780 |
|items groups values| |
|
781 |
||
1620
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
782 |
items := aLiteralEncodedArray at:2. |
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
783 |
|
2864
f90017f2da66
changed: #fromLiteralArrayEncoding:
Claus Gittinger <cg@exept.de>
parents:
2854
diff
changeset
|
784 |
items notNil ifTrue:[ |
1620
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
785 |
items := items collect:[:item | item decodeAsLiteralArray]. |
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
786 |
]. |
1405
c7775c10e8fd
tolerant literalDecoding (missing 2nd and 3rd elements);
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
787 |
groups := aLiteralEncodedArray at:3 ifAbsent:nil. |
c7775c10e8fd
tolerant literalDecoding (missing 2nd and 3rd elements);
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
788 |
values := aLiteralEncodedArray at:4 ifAbsent:nil. |
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
789 |
self menuItems:items menuItemGroups:groups values:values. |
451 | 790 |
|
791 |
"extract from PD folder.st: |
|
792 |
#(#Menu #( |
|
1245 | 793 |
#(#MenuItem |
794 |
#rawLabel: 'left' |
|
795 |
#value: #left ) |
|
796 |
#(#MenuItem |
|
797 |
#rawLabel: 'center' |
|
798 |
#value: #center ) |
|
799 |
#(#MenuItem |
|
800 |
#rawLabel: 'right' |
|
801 |
#value: #right ) |
|
802 |
) |
|
803 |
#(3 ) |
|
804 |
nil |
|
451 | 805 |
) decodeAsLiteralArray |
806 |
" |
|
452 | 807 |
" |
808 |
#(#Menu #( |
|
1245 | 809 |
#(#MenuItem |
810 |
#label: 'Straighten Up' ) |
|
811 |
#(#MenuItem |
|
812 |
#label: 'Inspect' ) |
|
813 |
#(#MenuItem |
|
814 |
#label: 'Coredump' ) |
|
815 |
) |
|
816 |
#(3 ) |
|
817 |
#(#straightenUp #inspect #halt ) |
|
452 | 818 |
) decodeAsLiteralArray startUp |
819 |
" |
|
457 | 820 |
|
454 | 821 |
"extract from iconicBrowser.st: |
452 | 822 |
#(#Menu #( |
1245 | 823 |
#(#MenuItem |
824 |
#label: 'Straighten Up' ) |
|
825 |
#(#MenuItem |
|
826 |
#label: 'Inspect' ) |
|
827 |
#(#MenuItem |
|
828 |
#label: 'Coredump' ) |
|
829 |
) |
|
830 |
#(3 ) |
|
831 |
#(1 2 3 ) |
|
452 | 832 |
) decodeAsLiteralArray startUp |
833 |
" |
|
451 | 834 |
|
454 | 835 |
"extract from refactory213.st: |
836 |
#(#Menu #( |
|
1245 | 837 |
#(#MenuItem |
838 |
#label: 'File List' |
|
839 |
#accessCharacterPosition: 1 ) |
|
840 |
#(#MenuItem #label: 'File Editor...' |
|
841 |
#accessCharacterPosition: 6 ) |
|
842 |
#(#MenuItem #label: 'Refactoring Tool...' |
|
843 |
#accessCharacterPosition: 1 ) |
|
844 |
#(#MenuItem #label: 'Workspace' |
|
845 |
#accessCharacterPosition: 1 ) |
|
846 |
#(#MenuItem #label: 'New Canvas' |
|
847 |
#accessCharacterPosition: 1 ) |
|
848 |
#(#MenuItem #label: 'Palette' |
|
849 |
#accessCharacterPosition: 1 ) |
|
850 |
#(#MenuItem #label: 'Canvas Tool' |
|
851 |
#accessCharacterPosition: 1 ) |
|
852 |
#(#MenuItem #label: 'Image Editor' |
|
853 |
#accessCharacterPosition: 1 ) |
|
854 |
#(#MenuItem #label: 'Menu Editor' |
|
855 |
#accessCharacterPosition: 1 ) |
|
856 |
#(#MenuItem #label: 'Advanced' |
|
857 |
#accessCharacterPosition: 1 ) |
|
858 |
#(#MenuItem #label: 'DLL and C Connect' |
|
859 |
#accessCharacterPosition: 1 ) |
|
860 |
#(#MenuItem #label: 'System Transcript' |
|
861 |
#accessCharacterPosition: 8 ) |
|
862 |
) |
|
863 |
#(4 5 2 1 ) |
|
864 |
#(#openFileList #openFileEditor #openRefactoringTool #toolsNewWorkspace #toolsNewCanvas #toolsPalette #toolsCanvasTool #toolsMaskEditor #toolsMenuEditor nil #openExternalFinder #toggleSystemTranscript ) |
|
865 |
) decodeAsLiteralArray startUp |
|
454 | 866 |
" |
867 |
||
457 | 868 |
"submenus: |
869 |
#(#Menu #( |
|
1245 | 870 |
#(#MenuItem |
871 |
#label: 'Foo' |
|
872 |
#submenu: #(#Menu #( |
|
873 |
#(#MenuItem #label: 'foo 1') |
|
874 |
#(#MenuItem #label: 'foo 2') |
|
875 |
) |
|
876 |
nil |
|
877 |
#(11 22) |
|
878 |
) |
|
879 |
) |
|
880 |
#(#MenuItem |
|
881 |
#label: 'Inspect' ) |
|
882 |
#(#MenuItem |
|
883 |
#label: 'Coredump' ) |
|
884 |
) |
|
885 |
#(3 ) |
|
886 |
#(1 2 3 ) |
|
457 | 887 |
) decodeAsLiteralArray startUp |
888 |
" |
|
889 |
||
2864
f90017f2da66
changed: #fromLiteralArrayEncoding:
Claus Gittinger <cg@exept.de>
parents:
2854
diff
changeset
|
890 |
"Modified: / 08-08-2010 / 14:43:03 / cg" |
489 | 891 |
! |
892 |
||
893 |
literalArrayEncoding |
|
894 |
"return myself encoded as a literal array" |
|
895 |
||
1245 | 896 |
|coll array size| |
489 | 897 |
|
898 |
coll := OrderedCollection new. |
|
899 |
coll add:#Menu. |
|
1245 | 900 |
|
901 |
(size := items size) == 0 ifTrue:[ |
|
902 |
array := nil |
|
903 |
] ifFalse:[ |
|
904 |
array := Array new:size. |
|
905 |
items keysAndValuesDo:[:anIndex :anItem| |
|
906 |
array at:anIndex put:(anItem literalArrayEncoding) |
|
907 |
] |
|
908 |
]. |
|
909 |
coll add:array. |
|
910 |
||
911 |
(size := groupSizes size) == 0 ifTrue:[ |
|
912 |
array := nil |
|
913 |
] ifFalse:[ |
|
914 |
array := Array new:size. |
|
915 |
groupSizes keysAndValuesDo:[:anIndex :aSize| |
|
916 |
array at:anIndex put:(aSize literalArrayEncoding) |
|
917 |
] |
|
918 |
]. |
|
919 |
coll add:array. |
|
489 | 920 |
coll add:nil. |
579 | 921 |
^ coll asArray |
451 | 922 |
! ! |
923 |
||
584 | 924 |
!Menu methodsFor:'enumerating'! |
925 |
||
2494
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
926 |
allItemsDetect:aOneArgBlock ifNone:exceptionalValue |
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
927 |
"find an element amongst each item and submenu items" |
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
928 |
|
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
929 |
self itemsDo:[:anItem| |
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
930 |
|sub subItem| |
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
931 |
|
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
932 |
(aOneArgBlock value:anItem) ifTrue:[^ anItem]. |
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
933 |
(sub := anItem submenu) notNil ifTrue:[ |
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
934 |
subItem := sub allItemsDetect:aOneArgBlock ifNone:nil. |
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
935 |
subItem notNil ifTrue:[^ subItem]. |
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
936 |
] |
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
937 |
]. |
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
938 |
^ exceptionalValue value |
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
939 |
! |
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
940 |
|
665 | 941 |
allItemsDo:aOneArgBlock |
942 |
"evaluate block on each item and submenu items |
|
943 |
" |
|
944 |
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
|
945 |
|sub| |
724 | 946 |
|
972
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
947 |
aOneArgBlock value:anItem. |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
948 |
(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
|
949 |
sub allItemsDo:aOneArgBlock |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
950 |
] |
665 | 951 |
] |
724 | 952 |
|
972
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
953 |
"Modified: / 19.6.1998 / 00:34:53 / cg" |
665 | 954 |
! |
955 |
||
940 | 956 |
detectItem:aBlock |
957 |
"evaluate the argument, aBlock for each item in the menu until the |
|
958 |
block returns true; in this case return the item which caused the |
|
959 |
true evaluation. |
|
960 |
If none of the evaluations returns true, return the result of the |
|
961 |
evaluation of the exceptionBlock |
|
962 |
" |
|
963 |
^ self detectItem:aBlock ifNone:[self errorNotFound] |
|
964 |
||
965 |
! |
|
966 |
||
967 |
detectItem:aBlock ifNone:exceptionBlock |
|
968 |
"evaluate the argument, aBlock for each item in the menu until the |
|
969 |
block returns true; in this case return the item which caused the |
|
970 |
true evaluation. |
|
971 |
If none of the evaluations returns true, return the result of the |
|
972 |
evaluation of the exceptionBlock |
|
973 |
" |
|
974 |
items notNil ifTrue:[ |
|
975 |
^ items detect:aBlock ifNone:exceptionBlock |
|
976 |
]. |
|
977 |
^ exceptionBlock value |
|
978 |
! |
|
979 |
||
589 | 980 |
itemsDo:aOneArgBlock |
981 |
"evaluate the block for each item in the current menu |
|
982 |
" |
|
983 |
items notNil ifTrue:[items do:aOneArgBlock] |
|
984 |
! |
|
985 |
||
584 | 986 |
menuAndSubmenusDetectItem:aOneArgBlock |
987 |
"evaluate the block for each item in the current menu and all |
|
988 |
submenus. In case that the block returns a non nil argument, |
|
989 |
the item will be returned |
|
990 |
" |
|
724 | 991 |
|item| |
584 | 992 |
|
993 |
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
|
994 |
items do:[:anItem| |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
995 |
|sub| |
724 | 996 |
|
972
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
997 |
(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
|
998 |
^ anItem |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
999 |
]. |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
1000 |
(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
|
1001 |
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
|
1002 |
item notNil ifTrue:[ |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
1003 |
^ item |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
1004 |
] |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
1005 |
] |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
1006 |
] |
584 | 1007 |
]. |
724 | 1008 |
^ nil |
1009 |
||
972
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
1010 |
"Modified: / 19.6.1998 / 00:35:00 / cg" |
584 | 1011 |
! ! |
1012 |
||
672
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1013 |
!Menu methodsFor:'kludged fixes'! |
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1014 |
|
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1015 |
destroy |
1599 | 1016 |
"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
|
1017 |
|
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1018 |
"Created: 28.7.1997 / 10:16:52 / cg" |
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1019 |
! ! |
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1020 |
|
584 | 1021 |
!Menu methodsFor:'menu items'! |
1022 |
||
2404 | 1023 |
removeAllAccelerators |
1024 |
self allItemsDo:[:eachItem | |
|
1025 |
eachItem shortcutKey:nil. |
|
1026 |
]. |
|
1027 |
! |
|
1028 |
||
740 | 1029 |
someMenuItemLabeled:aLabel |
1030 |
"get the menu item with that label; in case that the label |
|
1031 |
is not found, nil is returned |
|
1032 |
" |
|
1033 |
^ self someMenuItemLabeled:aLabel ifNone:nil |
|
1034 |
||
1035 |
"Created: / 14.11.1997 / 20:55:17 / cg" |
|
1036 |
! |
|
1037 |
||
1038 |
someMenuItemLabeled:aLabel ifNone:exceptionBlock |
|
1039 |
"get the menu item labeled aLabel; in case that the value |
|
1040 |
is not found, the given exceptionBlock is executed and its value returned |
|
1041 |
" |
|
1042 |
|item| |
|
1043 |
||
1044 |
item := self menuAndSubmenusDetectItem:[:anItem| anItem label = aLabel]. |
|
1045 |
||
1046 |
item notNil ifTrue:[ |
|
1047 |
^ item |
|
1048 |
]. |
|
1049 |
^ exceptionBlock value |
|
1050 |
||
1051 |
"Created: / 14.11.1997 / 20:56:13 / cg" |
|
1052 |
! |
|
1053 |
||
584 | 1054 |
someMenuItemWithValue:aValue |
1055 |
"get the menu item assigned with the value; in case that the value |
|
1056 |
is not found nil is returned |
|
1057 |
" |
|
1058 |
^ self someMenuItemWithValue:aValue ifNone:nil |
|
1059 |
! |
|
1060 |
||
1061 |
someMenuItemWithValue:aValue ifNone:exceptionBlock |
|
1062 |
"get the menu item assigned with the value; in case that the value |
|
1063 |
is not found, the given exceptionBlock is executed and returned |
|
1064 |
" |
|
1065 |
|item| |
|
1066 |
||
1067 |
item := self menuAndSubmenusDetectItem:[:anItem| anItem value == aValue]. |
|
1068 |
||
1069 |
item notNil ifTrue:[ |
|
740 | 1070 |
^ item |
584 | 1071 |
]. |
1072 |
^ exceptionBlock value |
|
1073 |
! ! |
|
1074 |
||
1075 |
!Menu methodsFor:'queries'! |
|
1076 |
||
724 | 1077 |
hasHiddenItems |
1078 |
"test whether any item is hidden" |
|
1079 |
||
1080 |
self allItemsDo:[:anItem| |
|
740 | 1081 |
anItem isHidden ifTrue:[^ true] |
724 | 1082 |
]. |
1083 |
^ false |
|
1084 |
||
1085 |
"Modified: / 27.10.1997 / 15:12:44 / cg" |
|
1086 |
! |
|
1087 |
||
2584 | 1088 |
hasItems |
1089 |
"test whether there are any menu-items" |
|
1090 |
||
1091 |
^ items notEmptyOrNil |
|
1092 |
! |
|
1093 |
||
584 | 1094 |
hasSubMenuAt:anIndex |
1095 |
"test whether the menu item at the given index has a submenu |
|
1096 |
" |
|
1097 |
^ (self menuItemAt:anIndex) hasSubmenu |
|
1098 |
! ! |
|
1099 |
||
451 | 1100 |
!Menu methodsFor:'startup'! |
1101 |
||
729 | 1102 |
show |
1103 |
"realize the menu at its last position; returns the value associated with the |
|
1104 |
selected item, 0 if none was selected" |
|
1105 |
||
1106 |
^ (MenuPanel menu:self) show ? 0 |
|
1107 |
||
1108 |
||
1109 |
! |
|
1110 |
||
1111 |
showAt:aPoint |
|
1112 |
"realize the menu at aPoint; returns the value associated with the |
|
1113 |
selected item, 0 if none was selected" |
|
1114 |
||
1115 |
^ self showAt:aPoint resizing:true |
|
1116 |
||
1117 |
||
1118 |
! |
|
1119 |
||
1120 |
showAt:aPoint resizing:aBoolean |
|
1121 |
"realize the menu at aPoint; returns the value associated with the |
|
451 | 1122 |
selected item, 0 if none was selected" |
1123 |
||
996
1e10d01c90b8
careful: ? is a binary selector.
Claus Gittinger <cg@exept.de>
parents:
977
diff
changeset
|
1124 |
^ ((MenuPanel menu:self) showAt:aPoint resizing:aBoolean) ? 0 |
1e10d01c90b8
careful: ? is a binary selector.
Claus Gittinger <cg@exept.de>
parents:
977
diff
changeset
|
1125 |
|
1e10d01c90b8
careful: ? is a binary selector.
Claus Gittinger <cg@exept.de>
parents:
977
diff
changeset
|
1126 |
"Modified: / 8.7.1998 / 19:57:55 / cg" |
729 | 1127 |
! |
1128 |
||
1129 |
showAtPointer |
|
1130 |
"realize the menu at the current pointer position; returns the value associated with the |
|
1131 |
selected item, 0 if none was selected" |
|
1132 |
||
1133 |
^ self startUp |
|
1134 |
! |
|
457 | 1135 |
|
729 | 1136 |
showCenteredIn:aView |
1137 |
"realize the menu visible at the aView center; returns the value associated with the |
|
1138 |
selected item, 0 if none was selected" |
|
1139 |
||
996
1e10d01c90b8
careful: ? is a binary selector.
Claus Gittinger <cg@exept.de>
parents:
977
diff
changeset
|
1140 |
^ ((MenuPanel menu:self) showCenteredIn:aView) ? 0 |
729 | 1141 |
|
996
1e10d01c90b8
careful: ? is a binary selector.
Claus Gittinger <cg@exept.de>
parents:
977
diff
changeset
|
1142 |
"Modified: / 8.7.1998 / 19:58:05 / cg" |
729 | 1143 |
! |
1144 |
||
1145 |
startUp |
|
1146 |
"display the menu as a popUp; returns the value associated with the |
|
2039 | 1147 |
selected item, nil if none was selected. |
1148 |
(should we return 0 form ST-80 compatibility ?)" |
|
729 | 1149 |
|
1367 | 1150 |
^ (MenuPanel menu:self) startUp "/ ? 0 |
451 | 1151 |
|
579 | 1152 |
" |
1367 | 1153 |
|m| |
579 | 1154 |
|
1367 | 1155 |
m := #(#Menu #( |
1156 |
#(#MenuItem |
|
1157 |
#rawLabel: 'left' |
|
1158 |
#value: #left ) |
|
1159 |
#(#MenuItem |
|
1160 |
#rawLabel: 'center' |
|
1161 |
#value: #center ) |
|
1162 |
#(#MenuItem |
|
1163 |
#rawLabel: 'right' |
|
1164 |
#value: #right ) ) |
|
1165 |
#(2) |
|
1166 |
nil |
|
1167 |
) decodeAsLiteralArray. |
|
451 | 1168 |
|
579 | 1169 |
Transcript showCR:(m startUp) |
1170 |
" |
|
938
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1171 |
! |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1172 |
|
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1173 |
startUpAt:aPoint |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1174 |
"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
|
1175 |
selected item, 0 if none was selected" |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1176 |
|
939 | 1177 |
^ ((MenuPanel menu:self) startUpAt:aPoint) ? 0 |
938
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1178 |
|
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1179 |
" |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1180 |
|m| |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1181 |
|
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1182 |
m := #(#Menu #( |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1183 |
#(#MenuItem |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1184 |
#rawLabel: 'left' |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1185 |
#value: #left ) |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1186 |
#(#MenuItem |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1187 |
#rawLabel: 'center' |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1188 |
#value: #center ) |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1189 |
#(#MenuItem |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1190 |
#rawLabel: 'right' |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1191 |
#value: #right ) ) |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1192 |
#(2) |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1193 |
nil |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1194 |
) decodeAsLiteralArray. |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1195 |
|
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1196 |
Transcript showCR:(m startUpAt:100@100) |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1197 |
" |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1198 |
|
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1199 |
"Created: / 21.5.1998 / 14:15:21 / cg" |
939 | 1200 |
"Modified: / 21.5.1998 / 14:17:46 / cg" |
1367 | 1201 |
! |
1202 |
||
1652 | 1203 |
startUpFor:originatingWidget |
1204 |
"display the menu as a popUp; returns the value associated with the |
|
2039 | 1205 |
selected item, nil if none was selected. |
1206 |
(should we return 0 for ST-80 compatibility ?)" |
|
1652 | 1207 |
|
1208 |
^ (MenuPanel menu:self) startUpFor:originatingWidget "/ ? 0 |
|
1209 |
||
1210 |
" |
|
1211 |
|m| |
|
1212 |
||
1213 |
m := #(#Menu #( |
|
1214 |
#(#MenuItem |
|
1215 |
#rawLabel: 'left' |
|
1216 |
#value: #left ) |
|
1217 |
#(#MenuItem |
|
1218 |
#rawLabel: 'center' |
|
1219 |
#value: #center ) |
|
1220 |
#(#MenuItem |
|
1221 |
#rawLabel: 'right' |
|
1222 |
#value: #right ) ) |
|
1223 |
#(2) |
|
1224 |
nil |
|
1225 |
) decodeAsLiteralArray. |
|
1226 |
||
1227 |
Transcript showCR:(m startUp) |
|
1228 |
" |
|
1229 |
! |
|
1230 |
||
1367 | 1231 |
startUpOrNil |
1232 |
"display the menu as a popUp; returns the value associated with the |
|
1233 |
selected item, nil if none was selected" |
|
1234 |
||
1405
c7775c10e8fd
tolerant literalDecoding (missing 2nd and 3rd elements);
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
1235 |
^ (MenuPanel menu:self) startUpOrNil |
451 | 1236 |
! ! |
1237 |
||
2967
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1238 |
!Menu methodsFor:'utilities'! |
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1239 |
|
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1240 |
replaceArgument: oldValue with: newValue |
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1241 |
|
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1242 |
"Recusively Replace argument in menu items where |
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1243 |
current argument is equal to oldValue by newValue" |
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1244 |
|
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1245 |
self itemsDo:[:item| |
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1246 |
item replaceArgument: oldValue with: newValue |
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1247 |
] |
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1248 |
|
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1249 |
"Created: / 12-10-2011 / 20:11:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1250 |
! ! |
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1251 |
|
451 | 1252 |
!Menu class methodsFor:'documentation'! |
1253 |
||
2764 | 1254 |
version_CVS |
3028
29a0a22942fe
changed: #asOldStylePopUpMenuFor:
Claus Gittinger <cg@exept.de>
parents:
3022
diff
changeset
|
1255 |
^ '$Header: /cvs/stx/stx/libview2/Menu.st,v 1.85 2012-10-17 09:04:40 cg Exp $' |
451 | 1256 |
! ! |