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
|
666
|
9 |
instanceVariableNames:'color indication submenu submenuChannel shortcutKey labelText
|
684
|
10 |
labelImage accessCharacterPosition argument'
|
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 |
|
724
|
42 |
!MenuItem methodsFor:'ST-80 compatibility'!
|
|
43 |
|
|
44 |
isEnabled:aBoolean
|
|
45 |
self enabled:aBoolean
|
|
46 |
|
|
47 |
"Created: / 27.10.1997 / 16:34:55 / cg"
|
|
48 |
! !
|
|
49 |
|
451
|
50 |
!MenuItem methodsFor:'accessing'!
|
|
51 |
|
579
|
52 |
accessCharacterPosition
|
|
53 |
"get the index of the access character in the label text or string, or nil if none
|
|
54 |
"
|
|
55 |
adornment notNil ifTrue:[
|
|
56 |
^ adornment accessCharacterPosition
|
|
57 |
].
|
|
58 |
^ nil
|
451
|
59 |
!
|
|
60 |
|
579
|
61 |
accessCharacterPosition:index
|
|
62 |
"set the index of the access character in the label text or string, or nil if none
|
|
63 |
"
|
|
64 |
(index isNil and:[adornment isNil]) ifFalse:[
|
|
65 |
self adornment accessCharacterPosition:index
|
|
66 |
]
|
451
|
67 |
!
|
|
68 |
|
640
|
69 |
activeHelpKey
|
|
70 |
^ activeHelpKey
|
|
71 |
!
|
|
72 |
|
|
73 |
activeHelpKey:aKey
|
|
74 |
activeHelpKey := aKey
|
|
75 |
!
|
|
76 |
|
684
|
77 |
argument
|
|
78 |
"get argument given to the value (selector)
|
|
79 |
"
|
|
80 |
adornment notNil ifTrue:[
|
|
81 |
^ adornment argument
|
|
82 |
].
|
|
83 |
^ nil
|
|
84 |
!
|
|
85 |
|
|
86 |
argument:something
|
|
87 |
"set argument given to the value (selector)
|
|
88 |
"
|
|
89 |
|arg|
|
|
90 |
|
|
91 |
(arg := something) notNil ifTrue:[
|
|
92 |
arg isString ifTrue:[
|
|
93 |
(arg size == 0 or:[(arg indexOfNonSeparatorStartingAt:1) == 0]) ifTrue:[
|
|
94 |
arg := nil
|
|
95 |
]
|
|
96 |
]
|
|
97 |
].
|
|
98 |
|
|
99 |
(arg isNil and:[adornment isNil]) ifFalse:[
|
|
100 |
self adornment argument:arg
|
|
101 |
]
|
|
102 |
!
|
|
103 |
|
451
|
104 |
label
|
|
105 |
^ label
|
|
106 |
|
|
107 |
"Created: 25.2.1997 / 19:48:16 / cg"
|
|
108 |
!
|
|
109 |
|
453
|
110 |
label:aString
|
|
111 |
label := aString
|
|
112 |
|
|
113 |
"Created: 25.2.1997 / 19:55:16 / cg"
|
|
114 |
!
|
|
115 |
|
581
|
116 |
labelImage
|
|
117 |
"gets the labelImage
|
|
118 |
"
|
|
119 |
adornment notNil ifTrue:[
|
584
|
120 |
^ adornment labelImage value
|
581
|
121 |
].
|
|
122 |
^ nil
|
|
123 |
!
|
|
124 |
|
|
125 |
labelImage:aResourceRetriever
|
|
126 |
"set the labelImage
|
|
127 |
"
|
|
128 |
aResourceRetriever notNil ifTrue:[
|
|
129 |
self adornment labelImage:aResourceRetriever
|
|
130 |
]
|
|
131 |
!
|
|
132 |
|
578
|
133 |
nameKey
|
|
134 |
^ nameKey
|
|
135 |
|
|
136 |
|
|
137 |
!
|
|
138 |
|
|
139 |
nameKey:aNameKey
|
579
|
140 |
nameKey := aNameKey.
|
578
|
141 |
|
|
142 |
|
|
143 |
!
|
|
144 |
|
490
|
145 |
rawLabel
|
|
146 |
^ label
|
|
147 |
|
|
148 |
"Created: 25.2.1997 / 19:48:16 / cg"
|
|
149 |
!
|
|
150 |
|
451
|
151 |
rawLabel:aString
|
|
152 |
label := aString
|
|
153 |
|
|
154 |
"Created: 25.2.1997 / 19:11:02 / cg"
|
|
155 |
!
|
|
156 |
|
490
|
157 |
shortcutKeyCharacter
|
|
158 |
"ignored for now"
|
|
159 |
|
578
|
160 |
adornment notNil ifTrue:[
|
|
161 |
^ adornment shortcutKeyCharacter
|
|
162 |
].
|
490
|
163 |
^ nil
|
|
164 |
!
|
|
165 |
|
578
|
166 |
shortcutKeyCharacter:aKey
|
|
167 |
"set the key to press to select the menu item from the keyboard
|
|
168 |
"
|
579
|
169 |
(aKey isNil and:[adornment isNil]) ifFalse:[
|
|
170 |
self adornment shortcutKeyCharacter:aKey
|
|
171 |
]
|
578
|
172 |
!
|
|
173 |
|
458
|
174 |
submenu
|
578
|
175 |
adornment notNil ifTrue:[
|
|
176 |
^ adornment submenu
|
|
177 |
].
|
|
178 |
^ nil
|
458
|
179 |
|
|
180 |
"Created: 25.2.1997 / 20:57:24 / cg"
|
|
181 |
!
|
|
182 |
|
|
183 |
submenu:aMenu
|
|
184 |
self adornment submenu:aMenu
|
|
185 |
|
|
186 |
"Created: 25.2.1997 / 20:56:20 / cg"
|
|
187 |
!
|
|
188 |
|
666
|
189 |
submenuChannel
|
|
190 |
adornment notNil ifTrue:[
|
|
191 |
^ adornment submenuChannel
|
|
192 |
].
|
|
193 |
^ nil
|
|
194 |
!
|
|
195 |
|
|
196 |
submenuChannel:something
|
|
197 |
self adornment submenuChannel:something
|
|
198 |
!
|
|
199 |
|
451
|
200 |
value
|
|
201 |
^ value
|
|
202 |
|
|
203 |
"Created: 25.2.1997 / 19:50:14 / cg"
|
|
204 |
!
|
|
205 |
|
|
206 |
value:something
|
|
207 |
value := something
|
|
208 |
|
|
209 |
"Created: 25.2.1997 / 19:11:13 / cg"
|
|
210 |
! !
|
|
211 |
|
579
|
212 |
!MenuItem methodsFor:'accessing behavior'!
|
|
213 |
|
590
|
214 |
beOff
|
|
215 |
"set indication off
|
|
216 |
"
|
|
217 |
self indication:false
|
|
218 |
!
|
|
219 |
|
|
220 |
beOn
|
|
221 |
"set indication on
|
|
222 |
"
|
|
223 |
self indication:true
|
|
224 |
!
|
|
225 |
|
579
|
226 |
disable
|
|
227 |
enabled := false
|
|
228 |
|
|
229 |
"Created: 25.2.1997 / 19:39:09 / cg"
|
|
230 |
!
|
|
231 |
|
|
232 |
enable
|
|
233 |
enabled := true
|
|
234 |
|
|
235 |
"Created: 25.2.1997 / 19:39:00 / cg"
|
|
236 |
!
|
|
237 |
|
581
|
238 |
enabled
|
|
239 |
"returns a boolean, valueHolder or block
|
|
240 |
"
|
|
241 |
^ enabled
|
|
242 |
!
|
579
|
243 |
|
581
|
244 |
enabled:something
|
|
245 |
"a boolean, valueHolder or block
|
|
246 |
"
|
|
247 |
enabled := something
|
590
|
248 |
!
|
|
249 |
|
|
250 |
indication
|
|
251 |
"test whether the menu item has an on/off indicator (CheckToggle)
|
|
252 |
"
|
|
253 |
adornment notNil ifTrue:[
|
|
254 |
^ adornment indication
|
|
255 |
].
|
|
256 |
^ nil
|
|
257 |
!
|
|
258 |
|
|
259 |
indication:anIndication
|
|
260 |
"test whether the menu item has an on/off indicator (CheckToggle)
|
|
261 |
"
|
|
262 |
(anIndication notNil or:[adornment notNil]) ifTrue:[
|
|
263 |
self adornment indication:anIndication.
|
|
264 |
].
|
|
265 |
|
581
|
266 |
! !
|
|
267 |
|
|
268 |
!MenuItem methodsFor:'accessing resource'!
|
|
269 |
|
584
|
270 |
findGuiResourcesIn:aResourceContainerOrApplication
|
581
|
271 |
"setup a resource container
|
|
272 |
"
|
584
|
273 |
|lblImg|
|
581
|
274 |
|
584
|
275 |
adornment notNil ifTrue:[
|
|
276 |
(lblImg := adornment labelImage) notNil ifTrue:[
|
|
277 |
lblImg findGuiResourcesIn:aResourceContainerOrApplication
|
|
278 |
]
|
581
|
279 |
]
|
579
|
280 |
! !
|
|
281 |
|
451
|
282 |
!MenuItem methodsFor:'converting'!
|
|
283 |
|
|
284 |
fromLiteralArrayEncoding:aLiteralEncodedArray
|
|
285 |
"read my contents from a aLiteralEncodedArray"
|
|
286 |
|
|
287 |
2 to:aLiteralEncodedArray size by:2 do:[:i |
|
|
288 |
|selector value|
|
|
289 |
|
|
290 |
selector := aLiteralEncodedArray at:i.
|
581
|
291 |
value := (aLiteralEncodedArray at:i+1) decodeAsLiteralArray.
|
|
292 |
self perform:selector with:value
|
451
|
293 |
].
|
|
294 |
|
|
295 |
"
|
578
|
296 |
#( #MenuItem #rawLabel: 'left' #nameKey: 'identifier' #value: #left )
|
451
|
297 |
decodeAsLiteralArray
|
|
298 |
"
|
|
299 |
|
|
300 |
"Modified: 25.2.1997 / 19:24:22 / cg"
|
490
|
301 |
!
|
|
302 |
|
|
303 |
literalArrayEncoding
|
|
304 |
"return myself encoded as a literal array"
|
|
305 |
|
581
|
306 |
|coll something|
|
490
|
307 |
|
|
308 |
coll := OrderedCollection new.
|
|
309 |
coll add:#MenuItem.
|
581
|
310 |
|
|
311 |
label notNil ifTrue:[
|
|
312 |
coll add:#label: ; add:(label literalArrayEncoding)
|
|
313 |
].
|
|
314 |
|
|
315 |
nameKey notNil ifTrue:[
|
|
316 |
coll add:#nameKey: ; add:(nameKey literalArrayEncoding)
|
|
317 |
].
|
579
|
318 |
value notNil ifTrue:[
|
|
319 |
coll add:#value: ; add:(value literalArrayEncoding).
|
|
320 |
].
|
653
|
321 |
activeHelpKey notNil ifTrue:[
|
|
322 |
coll add:#activeHelpKey: ; add:(activeHelpKey literalArrayEncoding).
|
|
323 |
].
|
|
324 |
(something := self enabled) notNil ifTrue:[
|
|
325 |
coll add:#enabled: ; add:(enabled literalArrayEncoding).
|
579
|
326 |
].
|
|
327 |
|
653
|
328 |
adornment notNil ifTrue:[
|
|
329 |
(something := self shortcutKeyCharacter) notNil ifTrue:[
|
|
330 |
coll add:#shortcutKeyCharacter: ; add:(something literalArrayEncoding)
|
|
331 |
].
|
|
332 |
|
|
333 |
(something := self accessCharacterPosition) notNil ifTrue:[
|
|
334 |
coll add:#accessCharacterPosition: ; add:(something literalArrayEncoding)
|
|
335 |
].
|
|
336 |
|
684
|
337 |
(something := self argument) notNil ifTrue:[
|
|
338 |
coll add:#argument: ; add:(something literalArrayEncoding)
|
|
339 |
].
|
|
340 |
|
661
|
341 |
adornment labelImage notNil ifTrue:[
|
653
|
342 |
coll add:#labelImage: ; add:(adornment labelImage literalArrayEncoding)
|
|
343 |
].
|
|
344 |
(something := self indication) notNil ifTrue:[
|
|
345 |
coll add:#indication: ; add:(something literalArrayEncoding)
|
666
|
346 |
].
|
579
|
347 |
|
666
|
348 |
(something := self submenuChannel) notNil ifTrue:[
|
|
349 |
coll add:#submenuChannel: ; add:(something literalArrayEncoding)
|
|
350 |
].
|
|
351 |
|
|
352 |
self hasSubmenu ifTrue:[
|
|
353 |
coll add:#submenu:; add:(self submenu literalArrayEncoding)
|
|
354 |
].
|
581
|
355 |
].
|
653
|
356 |
|
579
|
357 |
^ coll asArray
|
451
|
358 |
! !
|
|
359 |
|
458
|
360 |
!MenuItem methodsFor:'private - accessing'!
|
|
361 |
|
|
362 |
adornment
|
|
363 |
adornment isNil ifTrue:[
|
|
364 |
adornment := MenuItemAdornment new
|
|
365 |
].
|
|
366 |
^ adornment
|
|
367 |
|
|
368 |
"Created: 25.2.1997 / 20:57:05 / cg"
|
|
369 |
! !
|
|
370 |
|
579
|
371 |
!MenuItem methodsFor:'queries'!
|
|
372 |
|
590
|
373 |
hasIndication
|
|
374 |
"test whether indication on/off exists
|
|
375 |
"
|
|
376 |
^ self indication notNil
|
|
377 |
!
|
|
378 |
|
579
|
379 |
hasSubmenu
|
584
|
380 |
^ self submenu notNil
|
579
|
381 |
|
|
382 |
"Created: 25.2.1997 / 20:56:20 / cg"
|
|
383 |
!
|
|
384 |
|
|
385 |
isEnabled
|
581
|
386 |
^ enabled value ? true
|
579
|
387 |
|
|
388 |
"Created: 25.2.1997 / 19:39:17 / cg"
|
590
|
389 |
!
|
|
390 |
|
724
|
391 |
isHidden
|
|
392 |
"not yet supported"
|
|
393 |
|
|
394 |
^ false
|
|
395 |
|
|
396 |
"Created: / 27.10.1997 / 15:13:43 / cg"
|
|
397 |
!
|
|
398 |
|
590
|
399 |
isOff
|
|
400 |
"test whether indication on/off exists and is off
|
|
401 |
"
|
|
402 |
|indication|
|
|
403 |
|
|
404 |
indication := self indication.
|
|
405 |
^ indication value == false
|
|
406 |
!
|
|
407 |
|
|
408 |
isOn
|
|
409 |
"test whether indication on/off exists and is on
|
|
410 |
"
|
|
411 |
|indication|
|
|
412 |
|
|
413 |
indication := self indication.
|
|
414 |
^ indication value == true
|
579
|
415 |
! !
|
|
416 |
|
458
|
417 |
!MenuItem::MenuItemAdornment methodsFor:'accessing'!
|
|
418 |
|
579
|
419 |
accessCharacterPosition
|
|
420 |
"return the value of the instance variable 'accessCharacterPosition' (automatically generated)"
|
|
421 |
|
|
422 |
^ accessCharacterPosition!
|
|
423 |
|
|
424 |
accessCharacterPosition:something
|
|
425 |
"set the value of the instance variable 'accessCharacterPosition' (automatically generated)"
|
|
426 |
|
|
427 |
accessCharacterPosition := something.!
|
|
428 |
|
684
|
429 |
argument
|
|
430 |
"return the value of the instance variable 'argument' (automatically generated)"
|
|
431 |
|
|
432 |
^ argument
|
|
433 |
|
|
434 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
|
435 |
!
|
|
436 |
|
|
437 |
argument:something
|
|
438 |
"set the value of the instance variable 'argument' (automatically generated)"
|
|
439 |
|
|
440 |
argument := something.
|
|
441 |
|
|
442 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
|
443 |
!
|
|
444 |
|
458
|
445 |
color
|
|
446 |
"return the value of the instance variable 'color' (automatically generated)"
|
|
447 |
|
|
448 |
^ color
|
|
449 |
|
|
450 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
|
451 |
!
|
|
452 |
|
|
453 |
color:something
|
|
454 |
"set the value of the instance variable 'color' (automatically generated)"
|
|
455 |
|
|
456 |
color := something.
|
|
457 |
|
|
458 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
|
459 |
!
|
|
460 |
|
|
461 |
indication
|
590
|
462 |
"test whether the menu item has an on/off indicator (CheckToggle)
|
|
463 |
"
|
458
|
464 |
^ indication
|
|
465 |
|
|
466 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
|
467 |
!
|
|
468 |
|
|
469 |
indication:something
|
590
|
470 |
"test whether the menu item has an on/off indicator (CheckToggle)
|
|
471 |
"
|
458
|
472 |
indication := something.
|
|
473 |
|
|
474 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
|
475 |
!
|
|
476 |
|
581
|
477 |
labelImage
|
|
478 |
"return the value of the instance variable 'labelImage' (automatically generated)"
|
|
479 |
|
|
480 |
^ labelImage!
|
|
481 |
|
|
482 |
labelImage:something
|
|
483 |
"set the value of the instance variable 'labelImage' (automatically generated)"
|
|
484 |
|
|
485 |
labelImage := something.!
|
|
486 |
|
578
|
487 |
labelText
|
|
488 |
"get the text appear as the menu label
|
|
489 |
"
|
|
490 |
^ labelText
|
|
491 |
!
|
|
492 |
|
|
493 |
labelText:something
|
|
494 |
"set the text appear as the menu label
|
|
495 |
"
|
|
496 |
labelText := something.
|
|
497 |
!
|
|
498 |
|
|
499 |
shortcutKeyCharacter
|
|
500 |
"get the key to press to select the menu item from the keyboard
|
|
501 |
"
|
|
502 |
^ shortcutKey
|
|
503 |
!
|
|
504 |
|
|
505 |
shortcutKeyCharacter:something
|
|
506 |
"set the key to press to select the menu item from the keyboard
|
|
507 |
"
|
|
508 |
shortcutKey := something.
|
|
509 |
!
|
|
510 |
|
458
|
511 |
submenu
|
578
|
512 |
"get the submenu or nil
|
|
513 |
"
|
458
|
514 |
^ submenu
|
|
515 |
|
|
516 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
|
517 |
!
|
|
518 |
|
|
519 |
submenu:something
|
578
|
520 |
"set the submenu or nil
|
|
521 |
"
|
458
|
522 |
submenu := something.
|
|
523 |
|
|
524 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
666
|
525 |
!
|
|
526 |
|
|
527 |
submenuChannel
|
|
528 |
"get the submenuChannel or nil
|
|
529 |
"
|
|
530 |
^ submenuChannel
|
|
531 |
!
|
|
532 |
|
|
533 |
submenuChannel:something
|
|
534 |
"set the submenuChannel or nil
|
|
535 |
"
|
|
536 |
submenuChannel := something.
|
458
|
537 |
! !
|
|
538 |
|
451
|
539 |
!MenuItem class methodsFor:'documentation'!
|
|
540 |
|
|
541 |
version
|
724
|
542 |
^ '$Header: /cvs/stx/stx/libview2/MenuItem.st,v 1.17 1997-10-28 19:49:53 cg Exp $'
|
451
|
543 |
! !
|