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