author | Claus Gittinger <cg@exept.de> |
Fri, 22 Nov 2019 15:57:31 +0100 | |
changeset 4397 | 7dff9bb71888 |
parent 4383 | 95689e660a4b |
child 4442 | 510751dc36f5 |
permissions | -rw-r--r-- |
4036 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1354 | 3 |
" |
4 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
5 |
All Rights Reserved |
|
6 |
||
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
1367 | 14 |
"{ Package: 'stx:libview2' }" |
15 |
||
3449 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
2854
d37c539b59ad
inherit from model, for cheap dependents.
Claus Gittinger <cg@exept.de>
parents:
2814
diff
changeset
|
18 |
Model subclass:#Menu |
579 | 19 |
instanceVariableNames:'items groupSizes receiver' |
451 | 20 |
classVariableNames:'' |
21 |
poolDictionaries:'' |
|
22 |
category:'Views-Support' |
|
23 |
! |
|
24 |
||
3778 | 25 |
Query subclass:#NeedResourcesQuery |
26 |
instanceVariableNames:'' |
|
27 |
classVariableNames:'' |
|
28 |
poolDictionaries:'' |
|
29 |
privateIn:Menu |
|
30 |
! |
|
31 |
||
451 | 32 |
!Menu class methodsFor:'documentation'! |
33 |
||
1354 | 34 |
copyright |
35 |
" |
|
36 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
37 |
All Rights Reserved |
|
38 |
||
39 |
This software is furnished under a license and may be used |
|
40 |
only in accordance with the terms of that license and with the |
|
41 |
inclusion of the above copyright notice. This software may not |
|
42 |
be provided or otherwise made available to, or used by, any |
|
43 |
other person. No title to or ownership of the software is |
|
44 |
hereby transferred. |
|
45 |
" |
|
46 |
||
47 |
||
48 |
! |
|
49 |
||
451 | 50 |
documentation |
51 |
" |
|
4095 | 52 |
Menu (aka MenuSpec, that's what it is!!). |
53 |
||
54 |
similar to UISpecifications, this describes the look, feel and behavior of |
|
55 |
popUpMenus, toolbarMenus and window menus. |
|
451 | 56 |
|
4095 | 57 |
Instances of me are usually created from menuSpec methods, which return a literal |
58 |
array description of me. |
|
59 |
Instances of me are processed by MenuBuilders, which create a real MenuView/MenuPanel |
|
60 |
from that into a window. |
|
451 | 61 |
|
4095 | 62 |
Should be relatively VisualWorks compatible (clean room development, by emulating the |
63 |
protocol needed by some public domain VW applications) |
|
64 |
||
451 | 65 |
[author:] |
4095 | 66 |
Claus Gittinger |
451 | 67 |
|
68 |
[see also:] |
|
4095 | 69 |
MenuItem |
70 |
PopUpMenu |
|
451 | 71 |
" |
72 |
! ! |
|
73 |
||
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
74 |
!Menu class methodsFor:'instance creation'! |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
75 |
|
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
76 |
labelArray:arrayOfString lines:linesArray values:valueArrayOrNil |
737 | 77 |
"return a menu with menu items built with labels from arrayOfString (not Symbols). |
78 |
The linesArray describes which menu items are the last menu item in their group. |
|
79 |
The valueArray contains value objects for each menu item |
|
80 |
(or is nil if no value objects are specified)." |
|
81 |
||
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
82 |
|nLabel valueArray menuItems groupLengths| |
737 | 83 |
|
84 |
nLabel := arrayOfString size. |
|
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
85 |
|
737 | 86 |
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
|
87 |
(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
|
88 |
valueArray := #() |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
89 |
] ifFalse:[ |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
90 |
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
|
91 |
] |
737 | 92 |
] 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
|
93 |
valueArray := valueArrayOrNil |
737 | 94 |
]. |
95 |
||
96 |
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
|
97 |
^ self error: 'illegal menu combination' |
737 | 98 |
]. |
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
99 |
|
737 | 100 |
menuItems := Array new:nLabel. |
101 |
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
|
102 |
|mi v| |
737 | 103 |
|
3222 | 104 |
mi := MenuItem label:(arrayOfString at:i) asString. |
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
105 |
v := valueArray at:i. |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
106 |
(v isKindOf:Menu) ifTrue:[mi submenu:v]. |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
107 |
menuItems at:i put:mi |
737 | 108 |
]. |
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
109 |
|
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
110 |
(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
|
111 |
groupLengths := (menuItems isEmpty) |
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
112 |
ifTrue: [Array new:0] |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
113 |
ifFalse: [Array with:menuItems size] |
737 | 114 |
] ifFalse:[ |
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
115 |
groupLengths := Array new:(linesArray size + 1). |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
116 |
groupLengths at:1 put:linesArray first. |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
117 |
2 to:linesArray size do: [:i | |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
118 |
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
|
119 |
]. |
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
120 |
groupLengths at:groupLengths size put:(menuItems size - linesArray last). |
737 | 121 |
]. |
122 |
||
123 |
^ self new |
|
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
124 |
menuItems:menuItems |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
125 |
menuItemGroups:groupLengths |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
126 |
values:valueArray |
737 | 127 |
|
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
128 |
"Modified: / 19.4.1998 / 11:30:18 / cg" |
696 | 129 |
! |
130 |
||
1174
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
131 |
labelArray:arrayOfString values:valueArrayOrNil |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
132 |
"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
|
133 |
The valueArray contains value objects for each menu item |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
134 |
(or is nil if no value objects are specified)." |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
135 |
|
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
136 |
^ self |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
137 |
labelArray:arrayOfString |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
138 |
lines:nil |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
139 |
values: valueArrayOrNil |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
140 |
|
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
141 |
! |
f58d5c8cee82
added #labelArray:values: (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
1116
diff
changeset
|
142 |
|
696 | 143 |
labelList:arrayOfGroupStrings values:valueArrayOrNil |
144 |
|labels lines| |
|
145 |
||
146 |
lines := arrayOfGroupStrings collect:[:each | each size]. |
|
2017 | 147 |
labels := arrayOfGroupStrings collectAll:[:eachGroup | eachGroup]. |
696 | 148 |
^ self labelArray:labels lines:lines values:valueArrayOrNil |
149 |
||
150 |
"Modified: 20.6.1997 / 10:46:45 / cg" |
|
151 |
"Created: 13.9.1997 / 10:35:46 / cg" |
|
737 | 152 |
! |
153 |
||
738 | 154 |
labels:aString lines:linesArray values:valueArrayOrNil |
737 | 155 |
^ self |
740 | 156 |
labelArray:(aString asCollectionOfLines) |
157 |
lines:linesArray |
|
158 |
values:valueArrayOrNil |
|
737 | 159 |
|
160 |
"Created: / 31.10.1997 / 03:12:20 / cg" |
|
738 | 161 |
"Modified: / 31.10.1997 / 03:23:42 / cg" |
1525 | 162 |
! |
163 |
||
164 |
labels:aString values:valueArrayOrNil |
|
165 |
^ self |
|
166 |
labelArray:(aString asCollectionOfLines) |
|
167 |
lines:#() |
|
168 |
values:valueArrayOrNil |
|
169 |
||
170 |
"Modified: / 31.10.1997 / 03:23:42 / cg" |
|
171 |
"Created: / 12.11.2001 / 16:06:36 / cg" |
|
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
172 |
! ! |
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
173 |
|
1764 | 174 |
!Menu methodsFor:'Compatibility-ST80'! |
724 | 175 |
|
2126 | 176 |
addLine |
177 |
self addSeparator |
|
178 |
! |
|
179 |
||
724 | 180 |
indexOfMenuItem:anItem |
2433 | 181 |
^ items indexOf:anItem |
724 | 182 |
|
2433 | 183 |
"Created: / 27.10.1997 / 16:34:19 / cg" |
184 |
! |
|
185 |
||
186 |
indexOfMenuItemForWhich:aBlock |
|
187 |
^ items findFirst:aBlock |
|
724 | 188 |
|
189 |
"Created: / 27.10.1997 / 16:34:19 / cg" |
|
190 |
! |
|
191 |
||
192 |
menuButtons |
|
193 |
"ST-80 seems to use a special menuButton class here. |
|
194 |
Here, kludge a collection of menuItems." |
|
195 |
||
196 |
^ items |
|
197 |
||
198 |
"Created: / 27.10.1997 / 16:33:35 / cg" |
|
199 |
! ! |
|
200 |
||
1782 | 201 |
!Menu methodsFor:'Compatibility-Squeak'! |
202 |
||
2764 | 203 |
add:label target:target selector:selector |
3185 | 204 |
self addItem:(MenuItem label:label itemValue:[target perform:selector]). |
2764 | 205 |
! |
206 |
||
207 |
balloonTextForLastItem:aString |
|
208 |
items last helpText:aString |
|
209 |
! |
|
210 |
||
1782 | 211 |
labels:labels lines:lines selections:selections |
212 |
|labelArray| |
|
213 |
||
214 |
labels isString ifTrue:[ |
|
215 |
labelArray := labels asCollectionOfLines. |
|
216 |
] ifFalse:[ |
|
217 |
labelArray := labels. |
|
218 |
]. |
|
219 |
||
220 |
1 to:labelArray size do:[:idx | |
|
3355 | 221 |
self addItem:(MenuItem |
222 |
label:(labelArray at:idx) |
|
223 |
itemValue:(selections at:idx)). |
|
1782 | 224 |
|
225 |
(lines includes:idx) ifTrue:[ |
|
226 |
self addSeparator. |
|
227 |
]. |
|
228 |
]. |
|
3022 | 229 |
|
230 |
"Modified: / 09-09-2012 / 13:08:55 / cg" |
|
1782 | 231 |
! ! |
232 |
||
451 | 233 |
!Menu methodsFor:'accessing'! |
234 |
||
2916
ff96b6187a5f
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
235 |
atMenuItemLabeled:aString putSubmenu:aMenu visible:visible |
ff96b6187a5f
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
236 |
(self menuItemLabeled:aString) |
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
237 |
submenu:aMenu; |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
238 |
isVisible:visible |
2916
ff96b6187a5f
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
239 |
|
ff96b6187a5f
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
240 |
"Created: / 30-06-2011 / 10:30:22 / cg" |
ff96b6187a5f
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
241 |
! |
ff96b6187a5f
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
2908
diff
changeset
|
242 |
|
696 | 243 |
atNameKey:aNameKey |
724 | 244 |
"return the menuItem for the given nameKey; nil if no such item is in the menu. |
245 |
Searches in allItems (i.e. also in subMenus)" |
|
696 | 246 |
|
724 | 247 |
self allItemsDo:[:anItem| |
740 | 248 |
anItem nameKey == aNameKey ifTrue:[^ anItem] |
724 | 249 |
]. |
696 | 250 |
^ nil |
251 |
||
724 | 252 |
"Modified: / 27.10.1997 / 15:12:00 / cg" |
696 | 253 |
! |
254 |
||
3340 | 255 |
atNameKey:aNameKey ifPresentDo:aBlock |
3951 | 256 |
"look for a menuItem with the given nameKey. If one is found, aBlock is evaluated for it. |
3340 | 257 |
If not, nothing is done. |
258 |
Searches in allItems (i.e. also in subMenus). |
|
259 |
Returns the item or nil." |
|
260 |
||
261 |
|item| |
|
262 |
||
263 |
(item := self atNameKey:aNameKey) notNil ifTrue:[ |
|
264 |
aBlock value:item. |
|
265 |
]. |
|
266 |
^ item |
|
3951 | 267 |
|
268 |
"Modified (comment): / 16-05-2017 / 10:55:03 / mawalch" |
|
3340 | 269 |
! |
270 |
||
578 | 271 |
groupSizes |
1500 | 272 |
^ groupSizes |
273 |
! |
|
578 | 274 |
|
275 |
groupSizes:something |
|
1500 | 276 |
groupSizes := something. |
277 |
! |
|
578 | 278 |
|
3942 | 279 |
itemAtValue:aValue |
4095 | 280 |
"gets the item which has aValue assigned as value" |
281 |
||
3942 | 282 |
^ self menuAndSubmenusDetectItem:[:anItem | anItem value == aValue ]. |
283 |
||
284 |
"Created: / 14-03-2017 / 16:12:37 / cg" |
|
4095 | 285 |
"Modified (comment): / 24-05-2018 / 16:11:15 / Claus Gittinger" |
3942 | 286 |
! |
287 |
||
1986 | 288 |
items |
289 |
^ items |
|
290 |
! |
|
291 |
||
3833 | 292 |
items:aCollectionOfMenuItems |
293 |
items := aCollectionOfMenuItems |
|
294 |
! |
|
295 |
||
584 | 296 |
labelAt:anIndex |
4095 | 297 |
"gets the label of the menu item at the given index or nil" |
298 |
||
584 | 299 |
|item| |
300 |
||
301 |
(item := self menuItemAt:anIndex) notNil ifTrue:[ |
|
801 | 302 |
^ item label |
584 | 303 |
]. |
801 | 304 |
^ nil |
584 | 305 |
|
4095 | 306 |
"Modified: / 02-02-1998 / 13:28:32 / cg" |
307 |
"Modified (comment): / 24-05-2018 / 16:11:26 / Claus Gittinger" |
|
584 | 308 |
! |
309 |
||
310 |
labelAtValue:aValue |
|
4095 | 311 |
"gets the label of the menu item assigned to value" |
312 |
||
584 | 313 |
|item| |
314 |
||
801 | 315 |
item := self menuAndSubmenusDetectItem:[:anItem | anItem value == aValue ]. |
584 | 316 |
|
317 |
item notNil ifTrue:[ |
|
801 | 318 |
^ item label |
584 | 319 |
]. |
801 | 320 |
^ nil |
584 | 321 |
|
4095 | 322 |
"Modified: / 02-02-1998 / 13:28:28 / cg" |
323 |
"Modified (comment): / 24-05-2018 / 16:11:30 / Claus Gittinger" |
|
584 | 324 |
! |
325 |
||
451 | 326 |
labels |
327 |
"return a collection of labels from my items" |
|
328 |
||
977
e07277070839
return valid collection in #labels.
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
329 |
items isNil ifTrue:[^ #()]. |
451 | 330 |
^ items collect:[:anItem | anItem label] |
331 |
||
972
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
332 |
"Created: / 25.2.1997 / 19:47:53 / cg" |
977
e07277070839
return valid collection in #labels.
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
333 |
"Modified: / 19.6.1998 / 02:36:22 / cg" |
451 | 334 |
! |
335 |
||
940 | 336 |
lastItem |
2584 | 337 |
"returns the last item or nil, if there are none" |
338 |
||
339 |
^ items isEmptyOrNil |
|
340 |
ifTrue:[nil] |
|
341 |
ifFalse:[items last] |
|
940 | 342 |
! |
343 |
||
489 | 344 |
lines |
737 | 345 |
"return the indexes of the menu items that are the last menu item in their group (except the very last)." |
489 | 346 |
|
801 | 347 |
|lines groupSz| |
737 | 348 |
|
3752 | 349 |
(groupSz := groupSizes size) <= 1 ifTrue: [^ #()]. |
801 | 350 |
lines := Array new:(groupSz - 1). |
351 |
lines at:1 put:groupSizes first. |
|
352 |
2 to:(groupSz-1) do:[:i | |
|
353 |
lines at:i put:(lines at:(i - 1)) + (groupSizes at:i) |
|
354 |
]. |
|
355 |
^ lines |
|
489 | 356 |
|
801 | 357 |
"Modified: / 2.2.1998 / 13:28:19 / cg" |
489 | 358 |
! |
359 |
||
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
360 |
menuItemAt:index |
3942 | 361 |
"gets the menu item at the given index. |
362 |
When the index is out of bounds, nil is returned" |
|
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
363 |
|
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
364 |
(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
|
365 |
^ items at:index |
584 | 366 |
]. |
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
367 |
^ nil |
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 |
"Modified: / 30-06-2011 / 10:51:39 / cg" |
3942 | 370 |
"Modified (comment): / 14-03-2017 / 16:11:31 / cg" |
489 | 371 |
! |
372 |
||
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
373 |
menuItemLabeled:anItemLabel |
724 | 374 |
"return the menuItem for the given nameKey; nil if no such item is in the menu. |
375 |
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
|
376 |
|
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
377 |
self |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
378 |
allItemsDo:[:anItem | |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
379 |
|l| |
724 | 380 |
|
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
381 |
((l := anItem label) sameAs:anItemLabel) ifTrue:[ |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
382 |
^ anItem |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
383 |
]. |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
384 |
(l includes:$&) ifTrue:[ |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
385 |
((l copyWithout:$&) sameAs:anItemLabel) ifTrue:[ |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
386 |
^ anItem |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
387 |
] |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
388 |
] |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
389 |
]. |
724 | 390 |
^ nil |
391 |
||
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
392 |
"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
|
393 |
"Modified: / 30-06-2011 / 10:51:44 / cg" |
724 | 394 |
! |
395 |
||
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
396 |
menuItemWithArgument:aValue |
2908
e21010b76553
added: #menuItemWithArgument:
Claus Gittinger <cg@exept.de>
parents:
2867
diff
changeset
|
397 |
"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
|
398 |
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
|
399 |
|
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
400 |
self |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
401 |
allItemsDo:[:anItem | |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
402 |
|l| |
2908
e21010b76553
added: #menuItemWithArgument:
Claus Gittinger <cg@exept.de>
parents:
2867
diff
changeset
|
403 |
|
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
404 |
(anItem argument = aValue) ifTrue:[ |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
405 |
^ anItem |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
406 |
]. |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
407 |
]. |
2908
e21010b76553
added: #menuItemWithArgument:
Claus Gittinger <cg@exept.de>
parents:
2867
diff
changeset
|
408 |
^ nil |
e21010b76553
added: #menuItemWithArgument:
Claus Gittinger <cg@exept.de>
parents:
2867
diff
changeset
|
409 |
|
e21010b76553
added: #menuItemWithArgument:
Claus Gittinger <cg@exept.de>
parents:
2867
diff
changeset
|
410 |
"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
|
411 |
"Modified: / 30-06-2011 / 10:51:50 / cg" |
2908
e21010b76553
added: #menuItemWithArgument:
Claus Gittinger <cg@exept.de>
parents:
2867
diff
changeset
|
412 |
! |
e21010b76553
added: #menuItemWithArgument:
Claus Gittinger <cg@exept.de>
parents:
2867
diff
changeset
|
413 |
|
2952
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
414 |
menuItemWithKey:aValue |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
415 |
"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
|
416 |
Searches all items (i.e. also submenu items)" |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
417 |
|
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
418 |
self |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
419 |
allItemsDo:[:anItem | |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
420 |
|
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
421 |
(anItem nameKey = aValue) ifTrue:[ |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
422 |
^ anItem |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
423 |
]. |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
424 |
]. |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
425 |
^ nil |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
426 |
|
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
427 |
"Created: / 19-04-2011 / 14:42:18 / cg" |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
428 |
"Modified: / 30-06-2011 / 10:51:50 / cg" |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
429 |
"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
|
430 |
! |
1cedbbc95433
added: #menuItemWithKey:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2918
diff
changeset
|
431 |
|
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
432 |
menuItemWithValue:aValue |
1652 | 433 |
"return the menuItem for the given value; nil if no such item is in the menu. |
434 |
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
|
435 |
|
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
436 |
self |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
437 |
allItemsDo:[:anItem | |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
438 |
|l| |
1652 | 439 |
|
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
440 |
(anItem value == aValue) ifTrue:[ |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
441 |
^ anItem |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
442 |
]. |
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
443 |
]. |
1652 | 444 |
^ nil |
445 |
||
2918
44a68f3ffba5
fixes for Jan's menu rewriting in NewSystemBrowser
Claus Gittinger <cg@exept.de>
parents:
2917
diff
changeset
|
446 |
"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
|
447 |
"Modified: / 30-06-2011 / 10:51:56 / cg" |
1652 | 448 |
! |
449 |
||
489 | 450 |
menuItems |
1327
b0b482a84570
menuItems always returns a collection (never nil)
Claus Gittinger <cg@exept.de>
parents:
1308
diff
changeset
|
451 |
^ items ? #() |
489 | 452 |
! |
453 |
||
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
454 |
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
|
455 |
|n| |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
456 |
|
1620
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
457 |
items := groupSizes := nil. |
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
458 |
|
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
459 |
aCollectionOfMenuItems size == 0 ifTrue:[ ^ self ]. |
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
460 |
|
451 | 461 |
items := aCollectionOfMenuItems. |
1620
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
462 |
|
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
463 |
sizes size > 0 ifTrue:[ |
1620
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
464 |
groupSizes := sizes. |
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
465 |
|
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
466 |
n := sizes inject:0 into:[:sumSoFar :this | sumSoFar + this]. |
1620
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
467 |
|
900
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
468 |
n = items size ifTrue:[ |
3117
3c7f6b69b2c5
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
3028
diff
changeset
|
469 |
groupSizes := sizes copyButLast: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
|
470 |
] |
aa93395cdb55
care for empty group at the end (avoid line at end of menu)
Claus Gittinger <cg@exept.de>
parents:
801
diff
changeset
|
471 |
]. |
451 | 472 |
|
579 | 473 |
values notNil ifTrue:[ |
4095 | 474 |
items with:values do:[:anItem :eachValue |anItem value:eachValue] |
454 | 475 |
]. |
610
72dbf392e888
ST80 compatible inst creation method..
Claus Gittinger <cg@exept.de>
parents:
589
diff
changeset
|
476 |
|
4095 | 477 |
"Modified: / 19-04-1998 / 11:47:34 / cg" |
478 |
"Modified (format): / 24-05-2018 / 15:18:25 / Claus Gittinger" |
|
451 | 479 |
! |
480 |
||
1116 | 481 |
menuPerformer:something |
482 |
"set the receiver of the menu messages" |
|
483 |
||
484 |
receiver := something. |
|
485 |
||
486 |
"Modified: / 2.2.1998 / 13:26:29 / cg" |
|
487 |
! |
|
488 |
||
494 | 489 |
numberOfItems |
801 | 490 |
"return the number of items in this menu" |
491 |
||
494 | 492 |
^ items size |
493 |
||
801 | 494 |
"Created: / 6.3.1997 / 15:15:53 / cg" |
495 |
"Modified: / 2.2.1998 / 13:26:40 / cg" |
|
494 | 496 |
! |
497 |
||
579 | 498 |
receiver |
801 | 499 |
"return the receiver of the menu messages" |
579 | 500 |
|
801 | 501 |
^ receiver |
502 |
||
503 |
"Modified: / 2.2.1998 / 13:26:20 / cg" |
|
504 |
! |
|
579 | 505 |
|
506 |
receiver:something |
|
801 | 507 |
"set the receiver of the menu messages" |
579 | 508 |
|
801 | 509 |
receiver := something. |
510 |
||
511 |
"Modified: / 2.2.1998 / 13:26:29 / cg" |
|
512 |
! |
|
579 | 513 |
|
451 | 514 |
valueAt:index |
3942 | 515 |
"return the value of an item" |
451 | 516 |
|
517 |
^ (items at:index) value |
|
518 |
||
3942 | 519 |
"Created: / 25-02-1997 / 19:49:41 / cg" |
520 |
"Modified (comment): / 14-03-2017 / 16:10:23 / cg" |
|
451 | 521 |
! |
522 |
||
494 | 523 |
valueAt:anIndex put:aValue |
3942 | 524 |
"put value at an index" |
494 | 525 |
|
526 |
(items at:anIndex) value:aValue |
|
527 |
||
3942 | 528 |
"Created: / 06-03-1997 / 15:15:48 / cg" |
529 |
"Modified (comment): / 14-03-2017 / 16:10:29 / cg" |
|
494 | 530 |
! |
531 |
||
451 | 532 |
values |
533 |
"return a collection of values from my items" |
|
534 |
||
535 |
^ items collect:[:anItem | anItem value] |
|
536 |
||
537 |
"Created: 25.2.1997 / 19:49:29 / cg" |
|
724 | 538 |
! |
539 |
||
540 |
values:aCollectionOfValues |
|
3942 | 541 |
"set the collection of values in my items" |
724 | 542 |
|
543 |
|s| |
|
544 |
||
545 |
s := aCollectionOfValues readStream. |
|
546 |
self itemsDo:[:item | |
|
1111 | 547 |
|val| |
724 | 548 |
|
1111 | 549 |
val := s next. |
550 |
item value:val |
|
724 | 551 |
]. |
1111 | 552 |
s atEnd ifFalse:[ |
2092 | 553 |
self error:'not enough elements in the value collection' mayProceed:true |
1111 | 554 |
] |
724 | 555 |
|
3942 | 556 |
"Created: / 27-10-1997 / 15:15:47 / cg" |
557 |
"Modified (comment): / 14-03-2017 / 16:10:41 / cg" |
|
724 | 558 |
! |
559 |
||
560 |
visibleMenuItemGroups |
|
801 | 561 |
|itemGroups visibleItemGroups nextItem| |
724 | 562 |
|
801 | 563 |
itemGroups := OrderedCollection new. |
564 |
nextItem := 1. |
|
565 |
groupSizes do:[:groupSize | |
|
566 |
itemGroups addLast: (items copyFrom:nextItem to:nextItem + groupSize - 1). |
|
567 |
nextItem := nextItem + groupSize |
|
568 |
]. |
|
569 |
self hasHiddenItems ifFalse:[^ itemGroups]. |
|
724 | 570 |
|
801 | 571 |
"Remove the hidden items." |
572 |
visibleItemGroups := OrderedCollection new. |
|
573 |
itemGroups do:[:eachItemGroup | |
|
574 |
|visibleItemGroup| |
|
575 |
||
576 |
visibleItemGroup := eachItemGroup reject:[:eachMenuItem | eachMenuItem hidden]. |
|
2129 | 577 |
visibleItemGroup notEmpty ifTrue:[ |
801 | 578 |
visibleItemGroups addLast: visibleItemGroup |
579 |
] |
|
580 |
]. |
|
581 |
^ visibleItemGroups |
|
724 | 582 |
|
583 |
"Created: / 27.10.1997 / 15:07:50 / cg" |
|
801 | 584 |
"Modified: / 2.2.1998 / 13:25:52 / cg" |
451 | 585 |
! ! |
586 |
||
1397 | 587 |
!Menu methodsFor:'accessing-resource'! |
582 | 588 |
|
584 | 589 |
findGuiResourcesIn:aResourceContainerOrApplication |
4036 | 590 |
"resolve national language translations from aResourceContainerOrApplication. |
591 |
Unless already set, remember aResourceContainerOrApplication as menu receiver" |
|
1986 | 592 |
|
4083 | 593 |
^ self findGuiResourcesIn:aResourceContainerOrApplication for:nil |
594 |
||
595 |
"Modified: / 26-10-2006 / 16:37:57 / cg" |
|
596 |
! |
|
597 |
||
598 |
findGuiResourcesIn:aResourceContainerOrApplication for:aViewOrNil |
|
599 |
"resolve national language translations from aResourceContainerOrApplication. |
|
600 |
Unless already set, remember aResourceContainerOrApplication as menu receiver" |
|
601 |
||
1986 | 602 |
receiver isNil ifTrue:[ |
603 |
receiver := aResourceContainerOrApplication |
|
604 |
]. |
|
3778 | 605 |
self |
4083 | 606 |
findGuiResourcesIn:aResourceContainerOrApplication |
607 |
for:aViewOrNil |
|
2269
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
608 |
rememberResourcesIn:(ValueHolder new) |
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
609 |
|
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
610 |
"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
|
611 |
! |
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
612 |
|
4083 | 613 |
findGuiResourcesIn:aResourceContainerOrApplication for:aViewOrNil rememberResourcesIn:aValueHolderOrNil |
3845 | 614 |
"resolve national language translations from aResourceContainerOrApplication" |
2269
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
615 |
|
3967 | 616 |
|need resolvedItems rcv| |
2269
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
617 |
|
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
618 |
"/ 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
|
619 |
"/ menu via #receiver: by the application. |
4036 | 620 |
"/ if the submenu's receiver is nil, the parentmenu's receiver will be used, |
621 |
"/ which is ok. |
|
2269
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
622 |
"/ But if it was changed below, we would need a recursive setting in #receiver: as well. |
4036 | 623 |
"/ receiver isNil ifTrue:[ |
624 |
"/ receiver := aResourceContainerOrApplication |
|
625 |
"/ ]. |
|
2269
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
626 |
|
1986 | 627 |
items isEmptyOrNil ifTrue:[^ self]. |
3965 | 628 |
"/ someone might catch queries and return some non-boolean |
629 |
"/ this is a bad side effect of Query being a subclass of Notification!! |
|
3967 | 630 |
(need := NeedResourcesQuery query) == true ifFalse:[ |
631 |
need isBoolean ifFalse:[ |
|
3968 | 632 |
"/ Transcript showCR:NeedResourcesQuery findHandler senderContext(GuiBrowser::ExpeccoGuiBrowser >> update:with:from: [70]). |
633 |
"/ self halt. |
|
634 |
"/ NeedResourcesQuery query. |
|
3967 | 635 |
thisContext fullPrintAllOn:Transcript |
636 |
]. |
|
637 |
^self |
|
638 |
]. |
|
1986 | 639 |
|
640 |
resolvedItems := OrderedCollection new. |
|
641 |
||
642 |
items do:[:anItem | |
|
2867 | 643 |
anItem isMenuSlice ifTrue:[ |
644 |
|resItems| |
|
645 |
||
2059
36e4aa247402
fixed menu-slice resolving (search in masterApplication too)
Claus Gittinger <cg@exept.de>
parents:
2039
diff
changeset
|
646 |
rcv := aResourceContainerOrApplication. |
36e4aa247402
fixed menu-slice resolving (search in masterApplication too)
Claus Gittinger <cg@exept.de>
parents:
2039
diff
changeset
|
647 |
[rcv notNil and:[resItems isNil]] whileTrue:[ |
3965 | 648 |
"/ pass down the original app while walking the master chain, |
4083 | 649 |
"/ so that subclices can be redefined by the master |
650 |
"/ (is that what we want???) |
|
3965 | 651 |
resItems := anItem resolveSliceMenuItemsIn:rcv for:aResourceContainerOrApplication rememberResourcesIn:aValueHolderOrNil. |
2059
36e4aa247402
fixed menu-slice resolving (search in masterApplication too)
Claus Gittinger <cg@exept.de>
parents:
2039
diff
changeset
|
652 |
rcv := rcv perform:#masterApplication ifNotUnderstood:nil. |
36e4aa247402
fixed menu-slice resolving (search in masterApplication too)
Claus Gittinger <cg@exept.de>
parents:
2039
diff
changeset
|
653 |
]. |
4083 | 654 |
"/ if there is no mastApp, or it did not provide the slice, |
655 |
"/ ask the view itself. |
|
656 |
resItems isNil ifTrue:[ |
|
657 |
aViewOrNil notNil ifTrue:[ |
|
658 |
resItems := anItem resolveSliceMenuItemsIn:aViewOrNil for:aResourceContainerOrApplication rememberResourcesIn:aValueHolderOrNil. |
|
659 |
]. |
|
660 |
]. |
|
1986 | 661 |
|
662 |
resItems notEmptyOrNil ifTrue:[ |
|
663 |
resolvedItems addAll:resItems. |
|
664 |
] |
|
665 |
] ifFalse:[ |
|
3449 | 666 |
anItem findGuiResourcesIn:aResourceContainerOrApplication rememberResourcesIn:aValueHolderOrNil. |
1986 | 667 |
resolvedItems add:anItem. |
1534
292c277fcf6a
findGuiResources... now sets the receiver, if not yet set
Claus Gittinger <cg@exept.de>
parents:
1532
diff
changeset
|
668 |
]. |
1986 | 669 |
]. |
670 |
items := resolvedItems. |
|
2269
7fae2df3ba48
resolveGUIResources no longer sets the receiver recursively
Claus Gittinger <cg@exept.de>
parents:
2129
diff
changeset
|
671 |
|
3968 | 672 |
"Modified: / 23-07-2017 / 12:17:58 / cg" |
4083 | 673 |
! |
674 |
||
675 |
findGuiResourcesIn:aResourceContainerOrApplication rememberResourcesIn:aValueHolderOrNil |
|
676 |
"resolve national language translations from aResourceContainerOrApplication" |
|
677 |
||
678 |
^ self |
|
679 |
findGuiResourcesIn:aResourceContainerOrApplication |
|
680 |
for:nil |
|
681 |
rememberResourcesIn:aValueHolderOrNil |
|
582 | 682 |
! ! |
683 |
||
940 | 684 |
!Menu methodsFor:'adding & removing'! |
685 |
||
686 |
addItem:aMenuItem |
|
1029 | 687 |
"add a menuItem at the end; |
688 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
689 |
||
940 | 690 |
items isNil ifTrue:[ |
1029 | 691 |
items := OrderedCollection new |
692 |
] ifFalse:[ |
|
693 |
items := items asOrderedCollection |
|
940 | 694 |
]. |
695 |
items add:aMenuItem. |
|
1029 | 696 |
|
697 |
"Modified: / 4.8.1998 / 17:31:13 / cg" |
|
940 | 698 |
! |
699 |
||
700 |
addItem:aMenuItem beforeIndex:anIndex |
|
1029 | 701 |
"add a menuItem at some position; |
702 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
703 |
||
940 | 704 |
items isNil ifTrue:[ |
705 |
items := OrderedCollection new |
|
1029 | 706 |
] ifFalse:[ |
707 |
items := items asOrderedCollection |
|
940 | 708 |
]. |
709 |
items add:aMenuItem beforeIndex:anIndex. |
|
1029 | 710 |
|
711 |
"Modified: / 4.8.1998 / 17:31:39 / cg" |
|
940 | 712 |
! |
713 |
||
714 |
addItem:aMenuItem value:aValue |
|
3022 | 715 |
aMenuItem itemValue:aValue. |
940 | 716 |
self addItem:aMenuItem. |
3022 | 717 |
|
718 |
"Modified: / 09-09-2012 / 13:08:50 / cg" |
|
940 | 719 |
! |
720 |
||
1758 | 721 |
addItemGroup:aGroup |
1029 | 722 |
"add a group of items at the end; |
723 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
724 |
||
940 | 725 |
groupSizes isNil ifTrue:[ |
1758 | 726 |
groupSizes := OrderedCollection with:items size. |
940 | 727 |
]. |
1758 | 728 |
groupSizes add:aGroup size. |
940 | 729 |
|
1758 | 730 |
aGroup do:[:item | |
1029 | 731 |
self addItem:item |
940 | 732 |
]. |
733 |
||
734 |
"Created: / 27.10.1997 / 15:02:15 / cg" |
|
1029 | 735 |
"Modified: / 4.8.1998 / 17:32:06 / cg" |
940 | 736 |
! |
737 |
||
738 |
addItemGroup:aGroup values:values |
|
1029 | 739 |
"add a group of items at the end; |
740 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
741 |
||
1758 | 742 |
aGroup with:values do:[:item :value | |
743 |
item value:value |
|
940 | 744 |
]. |
1758 | 745 |
self addItemGroup:aGroup |
1029 | 746 |
|
747 |
"Modified: / 4.8.1998 / 17:32:18 / cg" |
|
940 | 748 |
! |
749 |
||
750 |
addItemGroupLabels:labels values:values |
|
1029 | 751 |
"add a group of items at the end; |
752 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
753 |
||
940 | 754 |
|items| |
755 |
||
756 |
items := labels with:values |
|
1029 | 757 |
collect:[:label :value | |
3185 | 758 |
MenuItem label:label itemValue:value |
1029 | 759 |
]. |
940 | 760 |
self addItemGroup:items |
761 |
||
762 |
"Created: / 27.10.1997 / 19:49:27 / cg" |
|
1029 | 763 |
"Modified: / 4.8.1998 / 17:35:22 / cg" |
940 | 764 |
! |
765 |
||
766 |
addItemLabel:label value:value |
|
1029 | 767 |
"add an item at the end; |
768 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
940 | 769 |
|
3185 | 770 |
self addItem:(MenuItem label:label itemValue:value) |
940 | 771 |
|
772 |
"Created: / 27.10.1997 / 19:47:12 / cg" |
|
1029 | 773 |
"Modified: / 4.8.1998 / 17:34:44 / cg" |
940 | 774 |
! |
775 |
||
3226 | 776 |
addItems: collection |
777 |
"Add all items in given collection. |
|
778 |
Useful to build a menu programmatically (or, to add more items dynamically)" |
|
779 |
||
780 |
items isNil ifTrue:[ |
|
781 |
items := OrderedCollection new |
|
782 |
] ifFalse:[ |
|
783 |
items := items asOrderedCollection |
|
784 |
]. |
|
785 |
items addAll: collection |
|
786 |
||
787 |
"Created: / 01-09-2013 / 16:43:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
788 |
! |
|
789 |
||
790 |
addItemsFrom: anotherMenu |
|
791 |
"Add all items from another menu. |
|
792 |
Useful to build a menu programmatically (or, to add more items dynamically)" |
|
793 |
||
3254 | 794 |
self addItems: anotherMenu items ? #() |
3226 | 795 |
|
796 |
"Created: / 01-09-2013 / 16:44:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
3254 | 797 |
"Modified: / 04-10-2013 / 19:28:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
3226 | 798 |
! |
799 |
||
4086 | 800 |
addLabel:aLabel selector:aSelector action:aBlock |
801 |
self addItem:(MenuItem label:aLabel itemValue:aBlock). |
|
802 |
! |
|
803 |
||
1500 | 804 |
addSeparator |
805 |
"add a separating line item at the end; |
|
806 |
useful to build a menu programmatically (or, to add more items dynamically)" |
|
807 |
||
2814 | 808 |
self addItem:(MenuItem separator). |
1500 | 809 |
! |
810 |
||
940 | 811 |
removeItem:aMenuItem |
812 |
"remove an item from the menu" |
|
813 |
||
814 |
|idx| |
|
815 |
||
816 |
items notNil ifTrue:[ |
|
817 |
idx := items identityIndexOf:aMenuItem. |
|
818 |
idx ~~ 0 ifTrue:[ |
|
819 |
items removeAtIndex:idx |
|
820 |
] |
|
821 |
]. |
|
822 |
||
823 |
"Created: / 13.9.1997 / 10:27:31 / cg" |
|
824 |
"Modified: / 2.2.1998 / 13:26:49 / cg" |
|
825 |
! |
|
826 |
||
827 |
removeItemAt:anIndex |
|
828 |
"remove item at an index |
|
829 |
" |
|
830 |
anIndex <= items size ifTrue:[ |
|
831 |
^ items removeAtIndex:anIndex |
|
832 |
]. |
|
833 |
^ nil |
|
834 |
! ! |
|
835 |
||
451 | 836 |
!Menu methodsFor:'converting'! |
837 |
||
2081 | 838 |
asOldStylePopUpMenuFor:anApplicationOrNil |
2080 | 839 |
"a temporary kludge - will vanish, when oldStyle MenuView and PopUpMenu are gone" |
840 |
||
2081 | 841 |
|menuView itemsShown| |
842 |
||
2867 | 843 |
itemsShown := items |
844 |
select:[:each | |
|
2081 | 845 |
|visibilityInItem| |
846 |
||
847 |
visibilityInItem := each isVisible. |
|
848 |
visibilityInItem isNil ifTrue:[ |
|
849 |
true |
|
850 |
] ifFalse:[ |
|
851 |
visibilityInItem isBoolean ifTrue:[ |
|
852 |
visibilityInItem |
|
853 |
] ifFalse:[ |
|
854 |
visibilityInItem isSymbol ifTrue:[ |
|
2917
2ba0fee85a7f
changed: #asOldStylePopUpMenuFor:
Claus Gittinger <cg@exept.de>
parents:
2916
diff
changeset
|
855 |
anApplicationOrNil isNil |
2ba0fee85a7f
changed: #asOldStylePopUpMenuFor:
Claus Gittinger <cg@exept.de>
parents:
2916
diff
changeset
|
856 |
or:[ (anApplicationOrNil perform:visibilityInItem) value ]. |
2081 | 857 |
] ifFalse:[ |
858 |
visibilityInItem value |
|
859 |
]. |
|
860 |
]. |
|
861 |
]. |
|
862 |
]. |
|
2080 | 863 |
|
864 |
menuView := MenuView |
|
2081 | 865 |
labels:(itemsShown collect:[:each | each label]) |
866 |
selectors:(itemsShown collect:[:each | each value]) |
|
2751
d0729d604864
changed: #asOldStylePopUpMenuFor:
Claus Gittinger <cg@exept.de>
parents:
2584
diff
changeset
|
867 |
accelerators:(itemsShown collect:[:each | each shortcutKey]) |
2081 | 868 |
args:(itemsShown collect:[:each | each argument]) |
2080 | 869 |
receiver:receiver. |
870 |
||
2092 | 871 |
itemsShown doWithIndex:[:each :idx | |
2081 | 872 |
|enabledInItem enabled| |
873 |
||
874 |
enabledInItem := each enabled. |
|
875 |
enabledInItem notNil ifTrue:[ |
|
876 |
enabledInItem isSymbol ifTrue:[ |
|
4095 | 877 |
anApplicationOrNil isNil ifTrue:[ |
878 |
Smalltalk isSmalltalkDevelopmentSystem ifTrue:[ |
|
879 |
self halt:('no application to ask %1 (enabled)' bindWith:enabledInItem) |
|
880 |
]. |
|
881 |
]. |
|
2917
2ba0fee85a7f
changed: #asOldStylePopUpMenuFor:
Claus Gittinger <cg@exept.de>
parents:
2916
diff
changeset
|
882 |
enabled := anApplicationOrNil isNil or:[ (anApplicationOrNil perform:enabledInItem) ]. |
2081 | 883 |
] ifFalse:[ |
3028
29a0a22942fe
changed: #asOldStylePopUpMenuFor:
Claus Gittinger <cg@exept.de>
parents:
3022
diff
changeset
|
884 |
enabled := enabledInItem |
2081 | 885 |
]. |
886 |
enabled value ifFalse:[ |
|
2092 | 887 |
menuView disable:idx |
2081 | 888 |
]. |
889 |
]. |
|
890 |
]. |
|
891 |
||
3245 | 892 |
menuView actions:(itemsShown |
893 |
collect:[:each | |
|
894 |
[ |
|
895 |
|actionOrSymbol| |
|
896 |
||
897 |
actionOrSymbol := each itemValue. |
|
898 |
actionOrSymbol isBlock ifTrue:[ |
|
899 |
actionOrSymbol value |
|
900 |
] ifFalse:[ |
|
901 |
receiver perform:actionOrSymbol |
|
902 |
] |
|
903 |
] |
|
904 |
] |
|
905 |
). |
|
2080 | 906 |
|
907 |
^ PopUpMenu forMenu:menuView |
|
2867 | 908 |
|
2917
2ba0fee85a7f
changed: #asOldStylePopUpMenuFor:
Claus Gittinger <cg@exept.de>
parents:
2916
diff
changeset
|
909 |
"Modified: / 30-06-2011 / 10:35:57 / cg" |
4095 | 910 |
"Modified: / 24-05-2018 / 15:26:17 / Claus Gittinger" |
2080 | 911 |
! |
912 |
||
451 | 913 |
fromLiteralArrayEncoding:aLiteralEncodedArray |
914 |
"read my contents from a aLiteralEncodedArray" |
|
915 |
||
4330 | 916 |
"/ original (VW) format encodes as: |
917 |
"/ #( Menu |
|
918 |
"/ items-array |
|
919 |
"/ groups-array (usually nil) |
|
920 |
"/ values-array (usually nil) |
|
921 |
"/ ) |
|
922 |
"/ groups-array and values-array can be left empty (see fromLiteralArrayEncoding) |
|
923 |
"/ |
|
924 |
"/ new condensed format (menu items array elements are sliced in directly): |
|
925 |
"/ #( Menu |
|
926 |
"/ (MenuItem ...) |
|
927 |
"/ (MenuItem ...) |
|
928 |
"/ ... |
|
929 |
"/ ) |
|
930 |
||
931 |
|itemArrayOrFirstItem itemArray groupArrayOrNil valuesArrayOrNil numSlots| |
|
1620
bf72298c42bc
bug fixes; handle unspecified items in literalArrayEncoding
ca
parents:
1599
diff
changeset
|
932 |
|
4311 | 933 |
numSlots := aLiteralEncodedArray size. |
934 |
numSlots > 1 ifTrue:[ |
|
4330 | 935 |
itemArrayOrFirstItem := aLiteralEncodedArray at:2. |
936 |
"/ new or old format? |
|
937 |
(itemArrayOrFirstItem notNil |
|
938 |
and:[itemArrayOrFirstItem isArray |
|
939 |
and:[itemArrayOrFirstItem size > 1 |
|
940 |
and:[itemArrayOrFirstItem first isSymbol |
|
941 |
]]] ) ifTrue:[ |
|
942 |
"/ new condensed format |
|
943 |
itemArray := aLiteralEncodedArray from:2 collect:[:item | item decodeAsLiteralArray]. |
|
944 |
] ifFalse:[ |
|
945 |
itemArray := itemArrayOrFirstItem. |
|
946 |
itemArray notNil ifTrue:[ |
|
947 |
itemArray := itemArray collect:[:item | item decodeAsLiteralArray]. |
|
948 |
]. |
|
949 |
numSlots > 2 ifTrue:[ |
|
950 |
groupArrayOrNil := aLiteralEncodedArray at:3. |
|
951 |
numSlots > 3 ifTrue:[ |
|
952 |
valuesArrayOrNil := aLiteralEncodedArray at:4. |
|
953 |
]. |
|
4311 | 954 |
]. |
4310 | 955 |
]. |
956 |
]. |
|
957 |
||
958 |
self menuItems:itemArray menuItemGroups:groupArrayOrNil values:valuesArrayOrNil. |
|
451 | 959 |
|
4330 | 960 |
"extracted from PD folder.st: |
451 | 961 |
#(#Menu #( |
1245 | 962 |
#(#MenuItem |
963 |
#rawLabel: 'left' |
|
964 |
#value: #left ) |
|
965 |
#(#MenuItem |
|
966 |
#rawLabel: 'center' |
|
967 |
#value: #center ) |
|
968 |
#(#MenuItem |
|
969 |
#rawLabel: 'right' |
|
970 |
#value: #right ) |
|
971 |
) |
|
972 |
#(3 ) |
|
973 |
nil |
|
451 | 974 |
) decodeAsLiteralArray |
975 |
" |
|
452 | 976 |
" |
977 |
#(#Menu #( |
|
1245 | 978 |
#(#MenuItem |
979 |
#label: 'Straighten Up' ) |
|
980 |
#(#MenuItem |
|
981 |
#label: 'Inspect' ) |
|
982 |
#(#MenuItem |
|
983 |
#label: 'Coredump' ) |
|
984 |
) |
|
985 |
#(3 ) |
|
986 |
#(#straightenUp #inspect #halt ) |
|
452 | 987 |
) decodeAsLiteralArray startUp |
988 |
" |
|
457 | 989 |
|
4330 | 990 |
"extracted from iconicBrowser.st: |
452 | 991 |
#(#Menu #( |
1245 | 992 |
#(#MenuItem |
993 |
#label: 'Straighten Up' ) |
|
994 |
#(#MenuItem |
|
995 |
#label: 'Inspect' ) |
|
996 |
#(#MenuItem |
|
997 |
#label: 'Coredump' ) |
|
998 |
) |
|
999 |
#(3 ) |
|
1000 |
#(1 2 3 ) |
|
452 | 1001 |
) decodeAsLiteralArray startUp |
1002 |
" |
|
451 | 1003 |
|
4330 | 1004 |
"extracted from refactory213.st: |
454 | 1005 |
#(#Menu #( |
1245 | 1006 |
#(#MenuItem |
1007 |
#label: 'File List' |
|
1008 |
#accessCharacterPosition: 1 ) |
|
1009 |
#(#MenuItem #label: 'File Editor...' |
|
1010 |
#accessCharacterPosition: 6 ) |
|
1011 |
#(#MenuItem #label: 'Refactoring Tool...' |
|
1012 |
#accessCharacterPosition: 1 ) |
|
1013 |
#(#MenuItem #label: 'Workspace' |
|
1014 |
#accessCharacterPosition: 1 ) |
|
1015 |
#(#MenuItem #label: 'New Canvas' |
|
1016 |
#accessCharacterPosition: 1 ) |
|
1017 |
#(#MenuItem #label: 'Palette' |
|
1018 |
#accessCharacterPosition: 1 ) |
|
1019 |
#(#MenuItem #label: 'Canvas Tool' |
|
1020 |
#accessCharacterPosition: 1 ) |
|
1021 |
#(#MenuItem #label: 'Image Editor' |
|
1022 |
#accessCharacterPosition: 1 ) |
|
1023 |
#(#MenuItem #label: 'Menu Editor' |
|
1024 |
#accessCharacterPosition: 1 ) |
|
1025 |
#(#MenuItem #label: 'Advanced' |
|
1026 |
#accessCharacterPosition: 1 ) |
|
1027 |
#(#MenuItem #label: 'DLL and C Connect' |
|
1028 |
#accessCharacterPosition: 1 ) |
|
1029 |
#(#MenuItem #label: 'System Transcript' |
|
1030 |
#accessCharacterPosition: 8 ) |
|
1031 |
) |
|
1032 |
#(4 5 2 1 ) |
|
1033 |
#(#openFileList #openFileEditor #openRefactoringTool #toolsNewWorkspace #toolsNewCanvas #toolsPalette #toolsCanvasTool #toolsMaskEditor #toolsMenuEditor nil #openExternalFinder #toggleSystemTranscript ) |
|
1034 |
) decodeAsLiteralArray startUp |
|
454 | 1035 |
" |
1036 |
||
457 | 1037 |
"submenus: |
1038 |
#(#Menu #( |
|
1245 | 1039 |
#(#MenuItem |
1040 |
#label: 'Foo' |
|
1041 |
#submenu: #(#Menu #( |
|
1042 |
#(#MenuItem #label: 'foo 1') |
|
1043 |
#(#MenuItem #label: 'foo 2') |
|
1044 |
) |
|
1045 |
nil |
|
1046 |
#(11 22) |
|
1047 |
) |
|
1048 |
) |
|
1049 |
#(#MenuItem |
|
1050 |
#label: 'Inspect' ) |
|
1051 |
#(#MenuItem |
|
1052 |
#label: 'Coredump' ) |
|
1053 |
) |
|
1054 |
#(3 ) |
|
1055 |
#(1 2 3 ) |
|
457 | 1056 |
) decodeAsLiteralArray startUp |
1057 |
" |
|
1058 |
||
4330 | 1059 |
"old format: |
1060 |
#(#Menu |
|
1061 |
( |
|
1062 |
#(#MenuItem #label: 'Foo' ) |
|
1063 |
#(#MenuItem #label: 'Inspect' ) |
|
1064 |
#(#MenuItem #label: 'Coredump' ) |
|
1065 |
) |
|
1066 |
nil |
|
1067 |
nil |
|
1068 |
) decodeAsLiteralArray startUp |
|
1069 |
||
1070 |
#(#Menu |
|
1071 |
( |
|
1072 |
#(#MenuItem #label: 'Foo' ) |
|
1073 |
#(#MenuItem #label: 'Inspect' ) |
|
1074 |
#(#MenuItem #label: 'Coredump' ) |
|
1075 |
) |
|
1076 |
nil |
|
1077 |
nil |
|
1078 |
) decodeAsLiteralArray literalArrayEncoding |
|
1079 |
" |
|
1080 |
||
1081 |
"condensed format (new): |
|
1082 |
#(#Menu |
|
1083 |
#(#MenuItem #label: 'Foo' ) |
|
1084 |
#(#MenuItem #label: 'Inspect' ) |
|
1085 |
#(#MenuItem #label: 'Coredump' ) |
|
1086 |
) decodeAsLiteralArray startUp |
|
1087 |
||
1088 |
#(#Menu |
|
1089 |
#(#MenuItem #label: 'Foo' ) |
|
1090 |
#(#MenuItem #label: 'Inspect' ) |
|
1091 |
#(#MenuItem #label: 'Coredump' ) |
|
1092 |
) decodeAsLiteralArray literalArrayEncoding |
|
1093 |
" |
|
1094 |
||
2864
f90017f2da66
changed: #fromLiteralArrayEncoding:
Claus Gittinger <cg@exept.de>
parents:
2854
diff
changeset
|
1095 |
"Modified: / 08-08-2010 / 14:43:03 / cg" |
4311 | 1096 |
"Modified: / 19-07-2019 / 18:29:20 / Claus Gittinger" |
489 | 1097 |
! |
1098 |
||
1099 |
literalArrayEncoding |
|
1100 |
"return myself encoded as a literal array" |
|
1101 |
||
4330 | 1102 |
|useNewFormat coll itemArray groupsArray valuesArray size| |
1103 |
||
1104 |
useNewFormat := true. |
|
489 | 1105 |
|
4330 | 1106 |
"/ ST/X does not use or support a value array |
1107 |
"/ (valuesa are in the items, not in the menu) |
|
4310 | 1108 |
valuesArray := nil. |
4330 | 1109 |
"/ however, the code below would deal correctly with a non-nil valuesArray... |
1110 |
"/ (who knows if we'll need it some time) |
|
1111 |
||
4310 | 1112 |
"/ encodes as: |
1113 |
"/ #( Menu |
|
1114 |
"/ items-array |
|
1115 |
"/ groups-array (usually nil) |
|
1116 |
"/ values-array (usually nil) |
|
1117 |
"/ ) |
|
1118 |
"/ groups-array and values-array can be left empty (see fromLiteralArrayEncoding) |
|
4330 | 1119 |
"/ |
1120 |
"/ new condensed format (menu items array elements are sliced in directly): |
|
1121 |
"/ #( Menu |
|
1122 |
"/ (MenuItem ...) |
|
1123 |
"/ (MenuItem ...) |
|
1124 |
"/ ... |
|
1125 |
"/ ) |
|
4310 | 1126 |
|
489 | 1127 |
coll := OrderedCollection new. |
1128 |
coll add:#Menu. |
|
1245 | 1129 |
|
1130 |
(size := items size) == 0 ifTrue:[ |
|
4310 | 1131 |
itemArray := nil |
1245 | 1132 |
] ifFalse:[ |
4310 | 1133 |
itemArray := Array new:size. |
1245 | 1134 |
items keysAndValuesDo:[:anIndex :anItem| |
4310 | 1135 |
itemArray at:anIndex put:(anItem literalArrayEncoding) |
1245 | 1136 |
] |
1137 |
]. |
|
4330 | 1138 |
useNewFormat ifTrue:[ |
1139 |
(groupSizes isEmptyOrNil and:[valuesArray isEmptyOrNil]) ifTrue:[ |
|
1140 |
"/ generate new condensed format |
|
1141 |
itemArray notEmptyOrNil ifTrue:[ coll addAll:itemArray ]. |
|
1142 |
^ coll asArray. |
|
1143 |
]. |
|
1144 |
]. |
|
1145 |
||
4310 | 1146 |
coll add:itemArray. |
1245 | 1147 |
|
1148 |
(size := groupSizes size) == 0 ifTrue:[ |
|
4310 | 1149 |
groupsArray := nil |
1245 | 1150 |
] ifFalse:[ |
4310 | 1151 |
groupsArray := Array new:size. |
1245 | 1152 |
groupSizes keysAndValuesDo:[:anIndex :aSize| |
4310 | 1153 |
groupsArray at:anIndex put:(aSize literalArrayEncoding) |
1245 | 1154 |
] |
1155 |
]. |
|
4311 | 1156 |
|
4310 | 1157 |
(groupsArray notNil or:[valuesArray notNil]) ifTrue:[ |
1158 |
coll add:groupsArray. |
|
1159 |
valuesArray notNil ifTrue:[ |
|
1160 |
coll add:valuesArray. "/ always nil, currently |
|
1161 |
]. |
|
4330 | 1162 |
]. |
1163 |
||
4310 | 1164 |
^ coll asArray |
1165 |
||
4311 | 1166 |
"Modified (format): / 19-07-2019 / 18:30:20 / Claus Gittinger" |
451 | 1167 |
! ! |
1168 |
||
584 | 1169 |
!Menu methodsFor:'enumerating'! |
1170 |
||
2494
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
1171 |
allItemsDetect:aOneArgBlock ifNone:exceptionalValue |
4095 | 1172 |
"recursively find an element amongst each item and submenu items" |
2494
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
1173 |
|
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
1174 |
self itemsDo:[:anItem| |
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
1175 |
|sub subItem| |
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
1176 |
|
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
1177 |
(aOneArgBlock value:anItem) ifTrue:[^ anItem]. |
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
1178 |
(sub := anItem submenu) notNil ifTrue:[ |
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
1179 |
subItem := sub allItemsDetect:aOneArgBlock ifNone:nil. |
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
1180 |
subItem notNil ifTrue:[^ subItem]. |
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
1181 |
] |
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
1182 |
]. |
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
1183 |
^ exceptionalValue value |
4095 | 1184 |
|
1185 |
"Modified (comment): / 24-05-2018 / 16:10:36 / Claus Gittinger" |
|
2494
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
1186 |
! |
994b030ae562
new enumerator: allItemsDetect:ifNone:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
1187 |
|
665 | 1188 |
allItemsDo:aOneArgBlock |
4095 | 1189 |
"recursively evaluate block on each item and submenu items" |
1190 |
||
665 | 1191 |
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
|
1192 |
|sub| |
724 | 1193 |
|
972
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
1194 |
aOneArgBlock value:anItem. |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
1195 |
(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
|
1196 |
sub allItemsDo:aOneArgBlock |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
1197 |
] |
665 | 1198 |
] |
724 | 1199 |
|
4095 | 1200 |
"Modified: / 19-06-1998 / 00:34:53 / cg" |
1201 |
"Modified (comment): / 24-05-2018 / 16:10:41 / Claus Gittinger" |
|
665 | 1202 |
! |
1203 |
||
940 | 1204 |
detectItem:aBlock |
1205 |
"evaluate the argument, aBlock for each item in the menu until the |
|
1206 |
block returns true; in this case return the item which caused the |
|
1207 |
true evaluation. |
|
1208 |
If none of the evaluations returns true, return the result of the |
|
4095 | 1209 |
evaluation of the exceptionBlock" |
1210 |
||
940 | 1211 |
^ self detectItem:aBlock ifNone:[self errorNotFound] |
1212 |
||
4095 | 1213 |
"Modified (comment): / 24-05-2018 / 16:10:46 / Claus Gittinger" |
940 | 1214 |
! |
1215 |
||
3942 | 1216 |
detectItem:aBlock ifNone:exceptionValue |
940 | 1217 |
"evaluate the argument, aBlock for each item in the menu until the |
1218 |
block returns true; in this case return the item which caused the |
|
1219 |
true evaluation. |
|
4095 | 1220 |
If none of the evaluations returns true, return the value from exceptionValue" |
1221 |
||
940 | 1222 |
items notNil ifTrue:[ |
3942 | 1223 |
^ items detect:aBlock ifNone:exceptionValue |
940 | 1224 |
]. |
3942 | 1225 |
^ exceptionValue value |
1226 |
||
1227 |
"Modified (comment): / 14-03-2017 / 16:09:51 / cg" |
|
4095 | 1228 |
"Modified (comment): / 24-05-2018 / 16:10:51 / Claus Gittinger" |
1229 |
! |
|
1230 |
||
1231 |
do:aOneArgBlock |
|
1232 |
"recursively evaluate block on each item and submenu items" |
|
1233 |
||
1234 |
self allItemsDo:aOneArgBlock |
|
1235 |
||
1236 |
"Created: / 24-05-2018 / 16:10:25 / Claus Gittinger" |
|
940 | 1237 |
! |
1238 |
||
589 | 1239 |
itemsDo:aOneArgBlock |
4095 | 1240 |
"evaluate the block for each item in the current menu" |
1241 |
||
589 | 1242 |
items notNil ifTrue:[items do:aOneArgBlock] |
4095 | 1243 |
|
1244 |
"Modified (comment): / 24-05-2018 / 16:10:55 / Claus Gittinger" |
|
589 | 1245 |
! |
1246 |
||
584 | 1247 |
menuAndSubmenusDetectItem:aOneArgBlock |
1248 |
"evaluate the block for each item in the current menu and all |
|
1249 |
submenus. In case that the block returns a non nil argument, |
|
4095 | 1250 |
the item will be returned" |
1251 |
||
724 | 1252 |
|item| |
584 | 1253 |
|
1254 |
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
|
1255 |
items do:[:anItem| |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
1256 |
|sub| |
724 | 1257 |
|
972
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
1258 |
(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
|
1259 |
^ anItem |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
1260 |
]. |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
1261 |
(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
|
1262 |
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
|
1263 |
item notNil ifTrue:[ |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
1264 |
^ item |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
1265 |
] |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
1266 |
] |
09bc0765dbc1
no need to send submenu value - the item does it now.
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
1267 |
] |
584 | 1268 |
]. |
724 | 1269 |
^ nil |
1270 |
||
4095 | 1271 |
"Modified: / 19-06-1998 / 00:35:00 / cg" |
1272 |
"Modified (comment): / 24-05-2018 / 16:10:59 / Claus Gittinger" |
|
584 | 1273 |
! ! |
1274 |
||
672
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1275 |
!Menu methodsFor:'kludged fixes'! |
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1276 |
|
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1277 |
destroy |
1599 | 1278 |
"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
|
1279 |
|
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1280 |
"Created: 28.7.1997 / 10:16:52 / cg" |
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1281 |
! ! |
2db4bb41aa93
added dummy #destroy (q&d hack)
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1282 |
|
584 | 1283 |
!Menu methodsFor:'menu items'! |
1284 |
||
2404 | 1285 |
removeAllAccelerators |
1286 |
self allItemsDo:[:eachItem | |
|
1287 |
eachItem shortcutKey:nil. |
|
1288 |
]. |
|
1289 |
! |
|
1290 |
||
740 | 1291 |
someMenuItemLabeled:aLabel |
1292 |
"get the menu item with that label; in case that the label |
|
1293 |
is not found, nil is returned |
|
1294 |
" |
|
1295 |
^ self someMenuItemLabeled:aLabel ifNone:nil |
|
1296 |
||
1297 |
"Created: / 14.11.1997 / 20:55:17 / cg" |
|
1298 |
! |
|
1299 |
||
1300 |
someMenuItemLabeled:aLabel ifNone:exceptionBlock |
|
1301 |
"get the menu item labeled aLabel; in case that the value |
|
1302 |
is not found, the given exceptionBlock is executed and its value returned |
|
1303 |
" |
|
1304 |
|item| |
|
1305 |
||
1306 |
item := self menuAndSubmenusDetectItem:[:anItem| anItem label = aLabel]. |
|
1307 |
||
1308 |
item notNil ifTrue:[ |
|
1309 |
^ item |
|
1310 |
]. |
|
1311 |
^ exceptionBlock value |
|
1312 |
||
1313 |
"Created: / 14.11.1997 / 20:56:13 / cg" |
|
1314 |
! |
|
1315 |
||
584 | 1316 |
someMenuItemWithValue:aValue |
1317 |
"get the menu item assigned with the value; in case that the value |
|
1318 |
is not found nil is returned |
|
1319 |
" |
|
1320 |
^ self someMenuItemWithValue:aValue ifNone:nil |
|
1321 |
! |
|
1322 |
||
1323 |
someMenuItemWithValue:aValue ifNone:exceptionBlock |
|
1324 |
"get the menu item assigned with the value; in case that the value |
|
1325 |
is not found, the given exceptionBlock is executed and returned |
|
1326 |
" |
|
1327 |
|item| |
|
1328 |
||
1329 |
item := self menuAndSubmenusDetectItem:[:anItem| anItem value == aValue]. |
|
1330 |
||
1331 |
item notNil ifTrue:[ |
|
740 | 1332 |
^ item |
584 | 1333 |
]. |
1334 |
^ exceptionBlock value |
|
1335 |
! ! |
|
1336 |
||
1337 |
!Menu methodsFor:'queries'! |
|
1338 |
||
724 | 1339 |
hasHiddenItems |
1340 |
"test whether any item is hidden" |
|
1341 |
||
1342 |
self allItemsDo:[:anItem| |
|
740 | 1343 |
anItem isHidden ifTrue:[^ true] |
724 | 1344 |
]. |
1345 |
^ false |
|
1346 |
||
1347 |
"Modified: / 27.10.1997 / 15:12:44 / cg" |
|
1348 |
! |
|
1349 |
||
2584 | 1350 |
hasItems |
1351 |
"test whether there are any menu-items" |
|
1352 |
||
1353 |
^ items notEmptyOrNil |
|
1354 |
! |
|
1355 |
||
584 | 1356 |
hasSubMenuAt:anIndex |
1357 |
"test whether the menu item at the given index has a submenu |
|
1358 |
" |
|
1359 |
^ (self menuItemAt:anIndex) hasSubmenu |
|
1360 |
! ! |
|
1361 |
||
451 | 1362 |
!Menu methodsFor:'startup'! |
1363 |
||
729 | 1364 |
show |
1365 |
"realize the menu at its last position; returns the value associated with the |
|
1366 |
selected item, 0 if none was selected" |
|
1367 |
||
1368 |
^ (MenuPanel menu:self) show ? 0 |
|
1369 |
||
1370 |
||
1371 |
! |
|
1372 |
||
1373 |
showAt:aPoint |
|
1374 |
"realize the menu at aPoint; returns the value associated with the |
|
1375 |
selected item, 0 if none was selected" |
|
1376 |
||
1377 |
^ self showAt:aPoint resizing:true |
|
1378 |
||
1379 |
||
1380 |
! |
|
1381 |
||
1382 |
showAt:aPoint resizing:aBoolean |
|
1383 |
"realize the menu at aPoint; returns the value associated with the |
|
451 | 1384 |
selected item, 0 if none was selected" |
1385 |
||
996
1e10d01c90b8
careful: ? is a binary selector.
Claus Gittinger <cg@exept.de>
parents:
977
diff
changeset
|
1386 |
^ ((MenuPanel menu:self) showAt:aPoint resizing:aBoolean) ? 0 |
1e10d01c90b8
careful: ? is a binary selector.
Claus Gittinger <cg@exept.de>
parents:
977
diff
changeset
|
1387 |
|
1e10d01c90b8
careful: ? is a binary selector.
Claus Gittinger <cg@exept.de>
parents:
977
diff
changeset
|
1388 |
"Modified: / 8.7.1998 / 19:57:55 / cg" |
729 | 1389 |
! |
1390 |
||
1391 |
showAtPointer |
|
4383 | 1392 |
"realize the menu at the current pointer position; |
1393 |
returns the value associated with the selected item, 0 if none was selected" |
|
729 | 1394 |
|
1395 |
^ self startUp |
|
1396 |
! |
|
457 | 1397 |
|
729 | 1398 |
showCenteredIn:aView |
1399 |
"realize the menu visible at the aView center; returns the value associated with the |
|
1400 |
selected item, 0 if none was selected" |
|
1401 |
||
996
1e10d01c90b8
careful: ? is a binary selector.
Claus Gittinger <cg@exept.de>
parents:
977
diff
changeset
|
1402 |
^ ((MenuPanel menu:self) showCenteredIn:aView) ? 0 |
729 | 1403 |
|
996
1e10d01c90b8
careful: ? is a binary selector.
Claus Gittinger <cg@exept.de>
parents:
977
diff
changeset
|
1404 |
"Modified: / 8.7.1998 / 19:58:05 / cg" |
729 | 1405 |
! |
1406 |
||
1407 |
startUp |
|
1408 |
"display the menu as a popUp; returns the value associated with the |
|
2039 | 1409 |
selected item, nil if none was selected. |
1410 |
(should we return 0 form ST-80 compatibility ?)" |
|
729 | 1411 |
|
1367 | 1412 |
^ (MenuPanel menu:self) startUp "/ ? 0 |
451 | 1413 |
|
579 | 1414 |
" |
1367 | 1415 |
|m| |
579 | 1416 |
|
1367 | 1417 |
m := #(#Menu #( |
1418 |
#(#MenuItem |
|
1419 |
#rawLabel: 'left' |
|
1420 |
#value: #left ) |
|
1421 |
#(#MenuItem |
|
1422 |
#rawLabel: 'center' |
|
1423 |
#value: #center ) |
|
1424 |
#(#MenuItem |
|
1425 |
#rawLabel: 'right' |
|
1426 |
#value: #right ) ) |
|
1427 |
#(2) |
|
1428 |
nil |
|
1429 |
) decodeAsLiteralArray. |
|
451 | 1430 |
|
579 | 1431 |
Transcript showCR:(m startUp) |
1432 |
" |
|
938
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1433 |
! |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1434 |
|
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1435 |
startUpAt:aPoint |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1436 |
"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
|
1437 |
selected item, 0 if none was selected" |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1438 |
|
939 | 1439 |
^ ((MenuPanel menu:self) startUpAt:aPoint) ? 0 |
938
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1440 |
|
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1441 |
" |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1442 |
|m| |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1443 |
|
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1444 |
m := #(#Menu #( |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1445 |
#(#MenuItem |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1446 |
#rawLabel: 'left' |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1447 |
#value: #left ) |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1448 |
#(#MenuItem |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1449 |
#rawLabel: 'center' |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1450 |
#value: #center ) |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1451 |
#(#MenuItem |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1452 |
#rawLabel: 'right' |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1453 |
#value: #right ) ) |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1454 |
#(2) |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1455 |
nil |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1456 |
) decodeAsLiteralArray. |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1457 |
|
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1458 |
Transcript showCR:(m startUpAt:100@100) |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1459 |
" |
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1460 |
|
dfa1b1666cfa
added #startUpAt: (MenuView compatibility)
Claus Gittinger <cg@exept.de>
parents:
900
diff
changeset
|
1461 |
"Created: / 21.5.1998 / 14:15:21 / cg" |
939 | 1462 |
"Modified: / 21.5.1998 / 14:17:46 / cg" |
1367 | 1463 |
! |
1464 |
||
1652 | 1465 |
startUpFor:originatingWidget |
1466 |
"display the menu as a popUp; returns the value associated with the |
|
2039 | 1467 |
selected item, nil if none was selected. |
1468 |
(should we return 0 for ST-80 compatibility ?)" |
|
1652 | 1469 |
|
1470 |
^ (MenuPanel menu:self) startUpFor:originatingWidget "/ ? 0 |
|
1471 |
||
1472 |
" |
|
1473 |
|m| |
|
1474 |
||
1475 |
m := #(#Menu #( |
|
1476 |
#(#MenuItem |
|
1477 |
#rawLabel: 'left' |
|
1478 |
#value: #left ) |
|
1479 |
#(#MenuItem |
|
1480 |
#rawLabel: 'center' |
|
1481 |
#value: #center ) |
|
1482 |
#(#MenuItem |
|
1483 |
#rawLabel: 'right' |
|
1484 |
#value: #right ) ) |
|
1485 |
#(2) |
|
1486 |
nil |
|
1487 |
) decodeAsLiteralArray. |
|
1488 |
||
1489 |
Transcript showCR:(m startUp) |
|
1490 |
" |
|
1491 |
! |
|
1492 |
||
1367 | 1493 |
startUpOrNil |
1494 |
"display the menu as a popUp; returns the value associated with the |
|
1495 |
selected item, nil if none was selected" |
|
1496 |
||
1405
c7775c10e8fd
tolerant literalDecoding (missing 2nd and 3rd elements);
Claus Gittinger <cg@exept.de>
parents:
1401
diff
changeset
|
1497 |
^ (MenuPanel menu:self) startUpOrNil |
451 | 1498 |
! ! |
1499 |
||
2967
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1500 |
!Menu methodsFor:'utilities'! |
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1501 |
|
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1502 |
replaceArgument: oldValue with: newValue |
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1503 |
|
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1504 |
"Recusively Replace argument in menu items where |
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1505 |
current argument is equal to oldValue by newValue" |
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1506 |
|
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1507 |
self itemsDo:[:item| |
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1508 |
item replaceArgument: oldValue with: newValue |
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1509 |
] |
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1510 |
|
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1511 |
"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
|
1512 |
! ! |
c50ab5fa6cf0
Added #replaceArgument:with:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2952
diff
changeset
|
1513 |
|
3778 | 1514 |
!Menu::NeedResourcesQuery class methodsFor:'defaults'! |
1515 |
||
1516 |
defaultAnswer |
|
1517 |
^ true |
|
1518 |
! ! |
|
1519 |
||
3968 | 1520 |
!Menu::NeedResourcesQuery methodsFor:'accessing'! |
1521 |
||
1522 |
defaultResumeValue |
|
1523 |
"the default answer, if no one handles the query and the exception is resumed" |
|
1524 |
||
1525 |
^ true |
|
1526 |
||
1527 |
"Created: / 23-07-2017 / 12:13:27 / cg" |
|
1528 |
! ! |
|
1529 |
||
451 | 1530 |
!Menu class methodsFor:'documentation'! |
1531 |
||
3845 | 1532 |
version |
1533 |
^ '$Header$' |
|
1534 |
! |
|
1535 |
||
2764 | 1536 |
version_CVS |
3752 | 1537 |
^ '$Header$' |
451 | 1538 |
! ! |
3117
3c7f6b69b2c5
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
3028
diff
changeset
|
1539 |