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