451
|
1 |
Object subclass:#MenuItem
|
640
|
2 |
instanceVariableNames:'activeHelpKey enabled label value nameKey adornment'
|
451
|
3 |
classVariableNames:''
|
|
4 |
poolDictionaries:''
|
|
5 |
category:'Views-Support'
|
|
6 |
!
|
|
7 |
|
|
8 |
Object subclass:#MenuItemAdornment
|
581
|
9 |
instanceVariableNames:'color indication submenu shortcutKey labelText labelImage
|
579
|
10 |
accessCharacterPosition'
|
451
|
11 |
classVariableNames:''
|
|
12 |
poolDictionaries:''
|
|
13 |
privateIn:MenuItem
|
|
14 |
!
|
|
15 |
|
|
16 |
!MenuItem class methodsFor:'documentation'!
|
|
17 |
|
|
18 |
documentation
|
|
19 |
"
|
|
20 |
not yet finished MenuItem class - this will eventually replace
|
|
21 |
most of the MenuView and PopUpMenu stuff.
|
|
22 |
(and hopefully be ST-80 compatible ...)
|
|
23 |
|
|
24 |
For now, only a subset of the full protocol is implemented.
|
|
25 |
|
|
26 |
[author:]
|
|
27 |
Claus Gittinger
|
|
28 |
|
|
29 |
[see also:]
|
|
30 |
MenuItem
|
|
31 |
PopUpMenu
|
|
32 |
"
|
|
33 |
|
|
34 |
! !
|
|
35 |
|
490
|
36 |
!MenuItem class methodsFor:'instance creation'!
|
|
37 |
|
|
38 |
labeled:aString
|
|
39 |
^ self new label:aString
|
|
40 |
! !
|
|
41 |
|
451
|
42 |
!MenuItem methodsFor:'accessing'!
|
|
43 |
|
579
|
44 |
accessCharacterPosition
|
|
45 |
"get the index of the access character in the label text or string, or nil if none
|
|
46 |
"
|
|
47 |
adornment notNil ifTrue:[
|
|
48 |
^ adornment accessCharacterPosition
|
|
49 |
].
|
|
50 |
^ nil
|
451
|
51 |
!
|
|
52 |
|
579
|
53 |
accessCharacterPosition:index
|
|
54 |
"set the index of the access character in the label text or string, or nil if none
|
|
55 |
"
|
|
56 |
(index isNil and:[adornment isNil]) ifFalse:[
|
|
57 |
self adornment accessCharacterPosition:index
|
|
58 |
]
|
451
|
59 |
!
|
|
60 |
|
640
|
61 |
activeHelpKey
|
|
62 |
^ activeHelpKey
|
|
63 |
!
|
|
64 |
|
|
65 |
activeHelpKey:aKey
|
|
66 |
activeHelpKey := aKey
|
|
67 |
!
|
|
68 |
|
451
|
69 |
label
|
|
70 |
^ label
|
|
71 |
|
|
72 |
"Created: 25.2.1997 / 19:48:16 / cg"
|
|
73 |
!
|
|
74 |
|
453
|
75 |
label:aString
|
|
76 |
label := aString
|
|
77 |
|
|
78 |
"Created: 25.2.1997 / 19:55:16 / cg"
|
|
79 |
!
|
|
80 |
|
581
|
81 |
labelImage
|
|
82 |
"gets the labelImage
|
|
83 |
"
|
|
84 |
adornment notNil ifTrue:[
|
584
|
85 |
^ adornment labelImage value
|
581
|
86 |
].
|
|
87 |
^ nil
|
|
88 |
!
|
|
89 |
|
|
90 |
labelImage:aResourceRetriever
|
|
91 |
"set the labelImage
|
|
92 |
"
|
|
93 |
aResourceRetriever notNil ifTrue:[
|
|
94 |
self adornment labelImage:aResourceRetriever
|
|
95 |
]
|
|
96 |
!
|
|
97 |
|
578
|
98 |
nameKey
|
|
99 |
^ nameKey
|
|
100 |
|
|
101 |
|
|
102 |
!
|
|
103 |
|
|
104 |
nameKey:aNameKey
|
579
|
105 |
nameKey := aNameKey.
|
578
|
106 |
|
|
107 |
|
|
108 |
!
|
|
109 |
|
490
|
110 |
rawLabel
|
|
111 |
^ label
|
|
112 |
|
|
113 |
"Created: 25.2.1997 / 19:48:16 / cg"
|
|
114 |
!
|
|
115 |
|
451
|
116 |
rawLabel:aString
|
|
117 |
label := aString
|
|
118 |
|
|
119 |
"Created: 25.2.1997 / 19:11:02 / cg"
|
|
120 |
!
|
|
121 |
|
490
|
122 |
shortcutKeyCharacter
|
|
123 |
"ignored for now"
|
|
124 |
|
578
|
125 |
adornment notNil ifTrue:[
|
|
126 |
^ adornment shortcutKeyCharacter
|
|
127 |
].
|
490
|
128 |
^ nil
|
|
129 |
!
|
|
130 |
|
578
|
131 |
shortcutKeyCharacter:aKey
|
|
132 |
"set the key to press to select the menu item from the keyboard
|
|
133 |
"
|
579
|
134 |
(aKey isNil and:[adornment isNil]) ifFalse:[
|
|
135 |
self adornment shortcutKeyCharacter:aKey
|
|
136 |
]
|
578
|
137 |
!
|
|
138 |
|
458
|
139 |
submenu
|
578
|
140 |
adornment notNil ifTrue:[
|
|
141 |
^ adornment submenu
|
|
142 |
].
|
|
143 |
^ nil
|
458
|
144 |
|
|
145 |
"Created: 25.2.1997 / 20:57:24 / cg"
|
|
146 |
!
|
|
147 |
|
|
148 |
submenu:aMenu
|
|
149 |
self adornment submenu:aMenu
|
|
150 |
|
|
151 |
"Created: 25.2.1997 / 20:56:20 / cg"
|
|
152 |
!
|
|
153 |
|
451
|
154 |
value
|
|
155 |
^ value
|
|
156 |
|
|
157 |
"Created: 25.2.1997 / 19:50:14 / cg"
|
|
158 |
!
|
|
159 |
|
|
160 |
value:something
|
|
161 |
value := something
|
|
162 |
|
|
163 |
"Created: 25.2.1997 / 19:11:13 / cg"
|
|
164 |
! !
|
|
165 |
|
579
|
166 |
!MenuItem methodsFor:'accessing behavior'!
|
|
167 |
|
590
|
168 |
beOff
|
|
169 |
"set indication off
|
|
170 |
"
|
|
171 |
self indication:false
|
|
172 |
!
|
|
173 |
|
|
174 |
beOn
|
|
175 |
"set indication on
|
|
176 |
"
|
|
177 |
self indication:true
|
|
178 |
!
|
|
179 |
|
579
|
180 |
disable
|
|
181 |
enabled := false
|
|
182 |
|
|
183 |
"Created: 25.2.1997 / 19:39:09 / cg"
|
|
184 |
!
|
|
185 |
|
|
186 |
enable
|
|
187 |
enabled := true
|
|
188 |
|
|
189 |
"Created: 25.2.1997 / 19:39:00 / cg"
|
|
190 |
!
|
|
191 |
|
581
|
192 |
enabled
|
|
193 |
"returns a boolean, valueHolder or block
|
|
194 |
"
|
|
195 |
^ enabled
|
|
196 |
!
|
579
|
197 |
|
581
|
198 |
enabled:something
|
|
199 |
"a boolean, valueHolder or block
|
|
200 |
"
|
|
201 |
enabled := something
|
590
|
202 |
!
|
|
203 |
|
|
204 |
indication
|
|
205 |
"test whether the menu item has an on/off indicator (CheckToggle)
|
|
206 |
"
|
|
207 |
adornment notNil ifTrue:[
|
|
208 |
^ adornment indication
|
|
209 |
].
|
|
210 |
^ nil
|
|
211 |
!
|
|
212 |
|
|
213 |
indication:anIndication
|
|
214 |
"test whether the menu item has an on/off indicator (CheckToggle)
|
|
215 |
"
|
|
216 |
(anIndication notNil or:[adornment notNil]) ifTrue:[
|
|
217 |
self adornment indication:anIndication.
|
|
218 |
].
|
|
219 |
|
581
|
220 |
! !
|
|
221 |
|
|
222 |
!MenuItem methodsFor:'accessing resource'!
|
|
223 |
|
584
|
224 |
findGuiResourcesIn:aResourceContainerOrApplication
|
581
|
225 |
"setup a resource container
|
|
226 |
"
|
584
|
227 |
|lblImg|
|
581
|
228 |
|
584
|
229 |
adornment notNil ifTrue:[
|
|
230 |
(lblImg := adornment labelImage) notNil ifTrue:[
|
|
231 |
lblImg findGuiResourcesIn:aResourceContainerOrApplication
|
|
232 |
]
|
581
|
233 |
]
|
579
|
234 |
! !
|
|
235 |
|
451
|
236 |
!MenuItem methodsFor:'converting'!
|
|
237 |
|
|
238 |
fromLiteralArrayEncoding:aLiteralEncodedArray
|
|
239 |
"read my contents from a aLiteralEncodedArray"
|
|
240 |
|
|
241 |
2 to:aLiteralEncodedArray size by:2 do:[:i |
|
|
242 |
|selector value|
|
|
243 |
|
|
244 |
selector := aLiteralEncodedArray at:i.
|
581
|
245 |
value := (aLiteralEncodedArray at:i+1) decodeAsLiteralArray.
|
|
246 |
self perform:selector with:value
|
451
|
247 |
].
|
|
248 |
|
|
249 |
"
|
578
|
250 |
#( #MenuItem #rawLabel: 'left' #nameKey: 'identifier' #value: #left )
|
451
|
251 |
decodeAsLiteralArray
|
|
252 |
"
|
|
253 |
|
|
254 |
"Modified: 25.2.1997 / 19:24:22 / cg"
|
490
|
255 |
!
|
|
256 |
|
|
257 |
literalArrayEncoding
|
|
258 |
"return myself encoded as a literal array"
|
|
259 |
|
581
|
260 |
|coll something|
|
490
|
261 |
|
|
262 |
coll := OrderedCollection new.
|
|
263 |
coll add:#MenuItem.
|
581
|
264 |
|
|
265 |
label notNil ifTrue:[
|
|
266 |
coll add:#label: ; add:(label literalArrayEncoding)
|
|
267 |
].
|
|
268 |
|
|
269 |
nameKey notNil ifTrue:[
|
|
270 |
coll add:#nameKey: ; add:(nameKey literalArrayEncoding)
|
|
271 |
].
|
|
272 |
|
|
273 |
(something := self enabled) ifFalse:[
|
|
274 |
coll add:#enabled: ; add:(something literalArrayEncoding).
|
|
275 |
].
|
579
|
276 |
|
|
277 |
value notNil ifTrue:[
|
|
278 |
coll add:#value: ; add:(value literalArrayEncoding).
|
|
279 |
].
|
|
280 |
|
581
|
281 |
(something := self shortcutKeyCharacter) notNil ifTrue:[
|
|
282 |
coll add:#shortcutKeyCharacter: ; add:(something literalArrayEncoding)
|
579
|
283 |
].
|
|
284 |
|
581
|
285 |
(something := self accessCharacterPosition) notNil ifTrue:[
|
|
286 |
coll add:#accessCharacterPosition: ; add:(something literalArrayEncoding)
|
579
|
287 |
].
|
|
288 |
|
581
|
289 |
(something := self labelImage) notNil ifTrue:[
|
|
290 |
coll add:#labelImage: ; add:(something literalArrayEncoding)
|
|
291 |
].
|
579
|
292 |
^ coll asArray
|
451
|
293 |
! !
|
|
294 |
|
458
|
295 |
!MenuItem methodsFor:'private - accessing'!
|
|
296 |
|
|
297 |
adornment
|
|
298 |
adornment isNil ifTrue:[
|
|
299 |
adornment := MenuItemAdornment new
|
|
300 |
].
|
|
301 |
^ adornment
|
|
302 |
|
|
303 |
"Created: 25.2.1997 / 20:57:05 / cg"
|
|
304 |
! !
|
|
305 |
|
579
|
306 |
!MenuItem methodsFor:'queries'!
|
|
307 |
|
590
|
308 |
hasIndication
|
|
309 |
"test whether indication on/off exists
|
|
310 |
"
|
|
311 |
^ self indication notNil
|
|
312 |
!
|
|
313 |
|
579
|
314 |
hasSubmenu
|
584
|
315 |
^ self submenu notNil
|
579
|
316 |
|
|
317 |
"Created: 25.2.1997 / 20:56:20 / cg"
|
|
318 |
!
|
|
319 |
|
|
320 |
isEnabled
|
581
|
321 |
^ enabled value ? true
|
579
|
322 |
|
|
323 |
"Created: 25.2.1997 / 19:39:17 / cg"
|
590
|
324 |
!
|
|
325 |
|
|
326 |
isOff
|
|
327 |
"test whether indication on/off exists and is off
|
|
328 |
"
|
|
329 |
|indication|
|
|
330 |
|
|
331 |
indication := self indication.
|
|
332 |
^ indication value == false
|
|
333 |
!
|
|
334 |
|
|
335 |
isOn
|
|
336 |
"test whether indication on/off exists and is on
|
|
337 |
"
|
|
338 |
|indication|
|
|
339 |
|
|
340 |
indication := self indication.
|
|
341 |
^ indication value == true
|
579
|
342 |
! !
|
|
343 |
|
458
|
344 |
!MenuItem::MenuItemAdornment methodsFor:'accessing'!
|
|
345 |
|
579
|
346 |
accessCharacterPosition
|
|
347 |
"return the value of the instance variable 'accessCharacterPosition' (automatically generated)"
|
|
348 |
|
|
349 |
^ accessCharacterPosition!
|
|
350 |
|
|
351 |
accessCharacterPosition:something
|
|
352 |
"set the value of the instance variable 'accessCharacterPosition' (automatically generated)"
|
|
353 |
|
|
354 |
accessCharacterPosition := something.!
|
|
355 |
|
458
|
356 |
color
|
|
357 |
"return the value of the instance variable 'color' (automatically generated)"
|
|
358 |
|
|
359 |
^ color
|
|
360 |
|
|
361 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
|
362 |
!
|
|
363 |
|
|
364 |
color:something
|
|
365 |
"set the value of the instance variable 'color' (automatically generated)"
|
|
366 |
|
|
367 |
color := something.
|
|
368 |
|
|
369 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
|
370 |
!
|
|
371 |
|
|
372 |
indication
|
590
|
373 |
"test whether the menu item has an on/off indicator (CheckToggle)
|
|
374 |
"
|
458
|
375 |
^ indication
|
|
376 |
|
|
377 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
|
378 |
!
|
|
379 |
|
|
380 |
indication:something
|
590
|
381 |
"test whether the menu item has an on/off indicator (CheckToggle)
|
|
382 |
"
|
458
|
383 |
indication := something.
|
|
384 |
|
|
385 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
|
386 |
!
|
|
387 |
|
581
|
388 |
labelImage
|
|
389 |
"return the value of the instance variable 'labelImage' (automatically generated)"
|
|
390 |
|
|
391 |
^ labelImage!
|
|
392 |
|
|
393 |
labelImage:something
|
|
394 |
"set the value of the instance variable 'labelImage' (automatically generated)"
|
|
395 |
|
|
396 |
labelImage := something.!
|
|
397 |
|
578
|
398 |
labelText
|
|
399 |
"get the text appear as the menu label
|
|
400 |
"
|
|
401 |
^ labelText
|
|
402 |
!
|
|
403 |
|
|
404 |
labelText:something
|
|
405 |
"set the text appear as the menu label
|
|
406 |
"
|
|
407 |
labelText := something.
|
|
408 |
!
|
|
409 |
|
|
410 |
shortcutKeyCharacter
|
|
411 |
"get the key to press to select the menu item from the keyboard
|
|
412 |
"
|
|
413 |
^ shortcutKey
|
|
414 |
!
|
|
415 |
|
|
416 |
shortcutKeyCharacter:something
|
|
417 |
"set the key to press to select the menu item from the keyboard
|
|
418 |
"
|
|
419 |
shortcutKey := something.
|
|
420 |
!
|
|
421 |
|
458
|
422 |
submenu
|
578
|
423 |
"get the submenu or nil
|
|
424 |
"
|
458
|
425 |
^ submenu
|
|
426 |
|
|
427 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
|
428 |
!
|
|
429 |
|
|
430 |
submenu:something
|
578
|
431 |
"set the submenu or nil
|
|
432 |
"
|
458
|
433 |
submenu := something.
|
|
434 |
|
|
435 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
|
436 |
! !
|
|
437 |
|
451
|
438 |
!MenuItem class methodsFor:'documentation'!
|
|
439 |
|
|
440 |
version
|
640
|
441 |
^ '$Header: /cvs/stx/stx/libview2/MenuItem.st,v 1.12 1997-06-28 13:12:32 ca Exp $'
|
451
|
442 |
! !
|