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