author | Claus Gittinger <cg@exept.de> |
Thu, 18 Jun 1998 16:54:43 +0200 | |
changeset 960 | fee5a1a50374 |
parent 798 | 8a27a879ff23 |
child 973 | cd6b8d08c9c9 |
permissions | -rw-r--r-- |
451 | 1 |
Object subclass:#MenuItem |
752 | 2 |
instanceVariableNames:'activeHelpKey enabled label value nameKey adornment |
798 | 3 |
translateLabel isButton startGroup isVisible' |
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 |
||
798 | 105 |
isVisible |
106 |
^ isVisible ? true |
|
107 |
! |
|
108 |
||
109 |
isVisible:something |
|
110 |
isVisible := something |
|
111 |
! |
|
112 |
||
451 | 113 |
label |
114 |
^ label |
|
115 |
||
116 |
"Created: 25.2.1997 / 19:48:16 / cg" |
|
117 |
! |
|
118 |
||
453 | 119 |
label:aString |
120 |
label := aString |
|
121 |
||
122 |
"Created: 25.2.1997 / 19:55:16 / cg" |
|
123 |
! |
|
124 |
||
581 | 125 |
labelImage |
126 |
"gets the labelImage |
|
127 |
" |
|
128 |
adornment notNil ifTrue:[ |
|
584 | 129 |
^ adornment labelImage value |
581 | 130 |
]. |
131 |
^ nil |
|
132 |
! |
|
133 |
||
134 |
labelImage:aResourceRetriever |
|
135 |
"set the labelImage |
|
136 |
" |
|
137 |
aResourceRetriever notNil ifTrue:[ |
|
138 |
self adornment labelImage:aResourceRetriever |
|
139 |
] |
|
140 |
! |
|
141 |
||
578 | 142 |
nameKey |
143 |
^ nameKey |
|
144 |
||
145 |
||
146 |
! |
|
147 |
||
148 |
nameKey:aNameKey |
|
579 | 149 |
nameKey := aNameKey. |
578 | 150 |
|
151 |
||
152 |
! |
|
153 |
||
490 | 154 |
rawLabel |
155 |
^ label |
|
156 |
||
157 |
"Created: 25.2.1997 / 19:48:16 / cg" |
|
158 |
! |
|
159 |
||
451 | 160 |
rawLabel:aString |
161 |
label := aString |
|
162 |
||
163 |
"Created: 25.2.1997 / 19:11:02 / cg" |
|
164 |
! |
|
165 |
||
490 | 166 |
shortcutKeyCharacter |
167 |
"ignored for now" |
|
168 |
||
578 | 169 |
adornment notNil ifTrue:[ |
170 |
^ adornment shortcutKeyCharacter |
|
171 |
]. |
|
490 | 172 |
^ nil |
173 |
! |
|
174 |
||
578 | 175 |
shortcutKeyCharacter:aKey |
176 |
"set the key to press to select the menu item from the keyboard |
|
177 |
" |
|
579 | 178 |
(aKey isNil and:[adornment isNil]) ifFalse:[ |
179 |
self adornment shortcutKeyCharacter:aKey |
|
180 |
] |
|
578 | 181 |
! |
182 |
||
794 | 183 |
startGroup |
184 |
"start group #left #right #center ... or nil |
|
185 |
at the moment only #right is implemented |
|
186 |
" |
|
187 |
^ startGroup |
|
188 |
! |
|
189 |
||
190 |
startGroup:aSymbol |
|
191 |
"start group #left #right #center ... |
|
192 |
at the moment only #right is implemented |
|
193 |
" |
|
194 |
(startGroup isNil or:[startGroup == #right]) ifTrue:[ |
|
195 |
startGroup := aSymbol |
|
196 |
] ifFalse:[ |
|
197 |
self warn:('not supported group: ', aSymbol printString ). |
|
198 |
] |
|
199 |
! |
|
200 |
||
458 | 201 |
submenu |
578 | 202 |
adornment notNil ifTrue:[ |
203 |
^ adornment submenu |
|
204 |
]. |
|
205 |
^ nil |
|
458 | 206 |
|
207 |
"Created: 25.2.1997 / 20:57:24 / cg" |
|
208 |
! |
|
209 |
||
210 |
submenu:aMenu |
|
211 |
self adornment submenu:aMenu |
|
212 |
||
213 |
"Created: 25.2.1997 / 20:56:20 / cg" |
|
214 |
! |
|
215 |
||
666 | 216 |
submenuChannel |
217 |
adornment notNil ifTrue:[ |
|
218 |
^ adornment submenuChannel |
|
219 |
]. |
|
220 |
^ nil |
|
221 |
! |
|
222 |
||
223 |
submenuChannel:something |
|
224 |
self adornment submenuChannel:something |
|
225 |
! |
|
226 |
||
451 | 227 |
value |
228 |
^ value |
|
229 |
||
230 |
"Created: 25.2.1997 / 19:50:14 / cg" |
|
231 |
! |
|
232 |
||
233 |
value:something |
|
234 |
value := something |
|
235 |
||
236 |
"Created: 25.2.1997 / 19:11:13 / cg" |
|
237 |
! ! |
|
238 |
||
579 | 239 |
!MenuItem methodsFor:'accessing behavior'! |
240 |
||
590 | 241 |
beOff |
242 |
"set indication off |
|
243 |
" |
|
244 |
self indication:false |
|
245 |
! |
|
246 |
||
247 |
beOn |
|
248 |
"set indication on |
|
249 |
" |
|
250 |
self indication:true |
|
251 |
! |
|
252 |
||
579 | 253 |
disable |
254 |
enabled := false |
|
255 |
||
256 |
"Created: 25.2.1997 / 19:39:09 / cg" |
|
257 |
! |
|
258 |
||
259 |
enable |
|
260 |
enabled := true |
|
261 |
||
262 |
"Created: 25.2.1997 / 19:39:00 / cg" |
|
263 |
! |
|
264 |
||
581 | 265 |
enabled |
266 |
"returns a boolean, valueHolder or block |
|
267 |
" |
|
268 |
^ enabled |
|
269 |
! |
|
579 | 270 |
|
581 | 271 |
enabled:something |
272 |
"a boolean, valueHolder or block |
|
273 |
" |
|
274 |
enabled := something |
|
590 | 275 |
! |
276 |
||
277 |
indication |
|
278 |
"test whether the menu item has an on/off indicator (CheckToggle) |
|
279 |
" |
|
280 |
adornment notNil ifTrue:[ |
|
281 |
^ adornment indication |
|
282 |
]. |
|
283 |
^ nil |
|
284 |
! |
|
285 |
||
286 |
indication:anIndication |
|
287 |
"test whether the menu item has an on/off indicator (CheckToggle) |
|
288 |
" |
|
289 |
(anIndication notNil or:[adornment notNil]) ifTrue:[ |
|
290 |
self adornment indication:anIndication. |
|
291 |
]. |
|
292 |
||
752 | 293 |
! |
294 |
||
295 |
isButton |
|
296 |
"returns whether item looks like a Button |
|
297 |
" |
|
298 |
^isButton ? false |
|
299 |
||
300 |
||
301 |
! |
|
302 |
||
303 |
isButton:anBoolean |
|
304 |
"sets whether item looks like a Button |
|
305 |
" |
|
306 |
isButton := anBoolean |
|
307 |
||
308 |
||
309 |
! |
|
310 |
||
311 |
translateLabel |
|
312 |
"returns whether label is translated |
|
313 |
" |
|
314 |
^translateLabel ? false |
|
315 |
||
316 |
||
317 |
! |
|
318 |
||
319 |
translateLabel:anBoolean |
|
320 |
"sets whether label is translated |
|
321 |
" |
|
322 |
translateLabel := anBoolean |
|
323 |
||
324 |
||
581 | 325 |
! ! |
326 |
||
327 |
!MenuItem methodsFor:'accessing resource'! |
|
328 |
||
584 | 329 |
findGuiResourcesIn:aResourceContainerOrApplication |
581 | 330 |
"setup a resource container |
331 |
" |
|
960
fee5a1a50374
adornments submenu may be a valueHolder.
Claus Gittinger <cg@exept.de>
parents:
798
diff
changeset
|
332 |
|lblImg m| |
581 | 333 |
|
752 | 334 |
self translateLabel ifTrue:[ |
335 |
label := ResourceRetriever findResourceLabel: label in: aResourceContainerOrApplication |
|
336 |
]. |
|
337 |
||
584 | 338 |
adornment notNil ifTrue:[ |
752 | 339 |
(lblImg := adornment labelImage) notNil ifTrue:[ |
340 |
lblImg findGuiResourcesIn:aResourceContainerOrApplication. |
|
341 |
lblImg labelText notNil ifTrue: [lblImg labelText: label]. |
|
342 |
]. |
|
960
fee5a1a50374
adornments submenu may be a valueHolder.
Claus Gittinger <cg@exept.de>
parents:
798
diff
changeset
|
343 |
(m := adornment submenu) notNil ifTrue:[ |
fee5a1a50374
adornments submenu may be a valueHolder.
Claus Gittinger <cg@exept.de>
parents:
798
diff
changeset
|
344 |
m := m value. |
fee5a1a50374
adornments submenu may be a valueHolder.
Claus Gittinger <cg@exept.de>
parents:
798
diff
changeset
|
345 |
m notNil ifTrue:[ |
fee5a1a50374
adornments submenu may be a valueHolder.
Claus Gittinger <cg@exept.de>
parents:
798
diff
changeset
|
346 |
m findGuiResourcesIn:aResourceContainerOrApplication |
fee5a1a50374
adornments submenu may be a valueHolder.
Claus Gittinger <cg@exept.de>
parents:
798
diff
changeset
|
347 |
] |
752 | 348 |
]. |
581 | 349 |
] |
960
fee5a1a50374
adornments submenu may be a valueHolder.
Claus Gittinger <cg@exept.de>
parents:
798
diff
changeset
|
350 |
|
fee5a1a50374
adornments submenu may be a valueHolder.
Claus Gittinger <cg@exept.de>
parents:
798
diff
changeset
|
351 |
"Modified: / 18.6.1998 / 16:54:25 / cg" |
579 | 352 |
! ! |
353 |
||
451 | 354 |
!MenuItem methodsFor:'converting'! |
355 |
||
356 |
fromLiteralArrayEncoding:aLiteralEncodedArray |
|
357 |
"read my contents from a aLiteralEncodedArray" |
|
358 |
||
359 |
2 to:aLiteralEncodedArray size by:2 do:[:i | |
|
360 |
|selector value| |
|
361 |
||
362 |
selector := aLiteralEncodedArray at:i. |
|
581 | 363 |
value := (aLiteralEncodedArray at:i+1) decodeAsLiteralArray. |
364 |
self perform:selector with:value |
|
451 | 365 |
]. |
366 |
||
367 |
" |
|
578 | 368 |
#( #MenuItem #rawLabel: 'left' #nameKey: 'identifier' #value: #left ) |
451 | 369 |
decodeAsLiteralArray |
370 |
" |
|
371 |
||
372 |
"Modified: 25.2.1997 / 19:24:22 / cg" |
|
490 | 373 |
! |
374 |
||
375 |
literalArrayEncoding |
|
376 |
"return myself encoded as a literal array" |
|
377 |
||
581 | 378 |
|coll something| |
490 | 379 |
|
380 |
coll := OrderedCollection new. |
|
381 |
coll add:#MenuItem. |
|
581 | 382 |
|
383 |
label notNil ifTrue:[ |
|
384 |
coll add:#label: ; add:(label literalArrayEncoding) |
|
385 |
]. |
|
752 | 386 |
self translateLabel ifTrue:[ |
387 |
coll add:#translateLabel: ; add:(translateLabel literalArrayEncoding) |
|
388 |
]. |
|
389 |
self isButton ifTrue:[ |
|
390 |
coll add:#isButton:; add:(isButton literalArrayEncoding) |
|
391 |
]. |
|
581 | 392 |
nameKey notNil ifTrue:[ |
393 |
coll add:#nameKey: ; add:(nameKey literalArrayEncoding) |
|
394 |
]. |
|
798 | 395 |
isVisible notNil ifTrue:[ |
396 |
isVisible ~~ true ifTrue:[ |
|
397 |
coll add:#isVisible: ; add:(isVisible literalArrayEncoding) |
|
398 |
] |
|
399 |
]. |
|
794 | 400 |
|
401 |
startGroup notNil ifTrue:[ |
|
402 |
coll add:#startGroup: ; add:(startGroup literalArrayEncoding) |
|
403 |
]. |
|
404 |
||
579 | 405 |
value notNil ifTrue:[ |
406 |
coll add:#value: ; add:(value literalArrayEncoding). |
|
407 |
]. |
|
653 | 408 |
activeHelpKey notNil ifTrue:[ |
409 |
coll add:#activeHelpKey: ; add:(activeHelpKey literalArrayEncoding). |
|
410 |
]. |
|
411 |
(something := self enabled) notNil ifTrue:[ |
|
412 |
coll add:#enabled: ; add:(enabled literalArrayEncoding). |
|
579 | 413 |
]. |
414 |
||
653 | 415 |
adornment notNil ifTrue:[ |
416 |
(something := self shortcutKeyCharacter) notNil ifTrue:[ |
|
417 |
coll add:#shortcutKeyCharacter: ; add:(something literalArrayEncoding) |
|
418 |
]. |
|
419 |
||
420 |
(something := self accessCharacterPosition) notNil ifTrue:[ |
|
421 |
coll add:#accessCharacterPosition: ; add:(something literalArrayEncoding) |
|
422 |
]. |
|
423 |
||
684 | 424 |
(something := self argument) notNil ifTrue:[ |
425 |
coll add:#argument: ; add:(something literalArrayEncoding) |
|
426 |
]. |
|
427 |
||
661 | 428 |
adornment labelImage notNil ifTrue:[ |
653 | 429 |
coll add:#labelImage: ; add:(adornment labelImage literalArrayEncoding) |
430 |
]. |
|
431 |
(something := self indication) notNil ifTrue:[ |
|
432 |
coll add:#indication: ; add:(something literalArrayEncoding) |
|
666 | 433 |
]. |
579 | 434 |
|
666 | 435 |
(something := self submenuChannel) notNil ifTrue:[ |
436 |
coll add:#submenuChannel: ; add:(something literalArrayEncoding) |
|
437 |
]. |
|
438 |
||
439 |
self hasSubmenu ifTrue:[ |
|
440 |
coll add:#submenu:; add:(self submenu literalArrayEncoding) |
|
441 |
]. |
|
581 | 442 |
]. |
653 | 443 |
|
579 | 444 |
^ coll asArray |
451 | 445 |
! ! |
446 |
||
458 | 447 |
!MenuItem methodsFor:'private - accessing'! |
448 |
||
449 |
adornment |
|
450 |
adornment isNil ifTrue:[ |
|
451 |
adornment := MenuItemAdornment new |
|
452 |
]. |
|
453 |
^ adornment |
|
454 |
||
455 |
"Created: 25.2.1997 / 20:57:05 / cg" |
|
456 |
! ! |
|
457 |
||
579 | 458 |
!MenuItem methodsFor:'queries'! |
459 |
||
590 | 460 |
hasIndication |
461 |
"test whether indication on/off exists |
|
462 |
" |
|
463 |
^ self indication notNil |
|
464 |
! |
|
465 |
||
579 | 466 |
hasSubmenu |
584 | 467 |
^ self submenu notNil |
579 | 468 |
|
469 |
"Created: 25.2.1997 / 20:56:20 / cg" |
|
470 |
! |
|
471 |
||
472 |
isEnabled |
|
581 | 473 |
^ enabled value ? true |
579 | 474 |
|
475 |
"Created: 25.2.1997 / 19:39:17 / cg" |
|
590 | 476 |
! |
477 |
||
724 | 478 |
isHidden |
479 |
"not yet supported" |
|
480 |
||
481 |
^ false |
|
482 |
||
483 |
"Created: / 27.10.1997 / 15:13:43 / cg" |
|
484 |
! |
|
485 |
||
590 | 486 |
isOff |
487 |
"test whether indication on/off exists and is off |
|
488 |
" |
|
489 |
|indication| |
|
490 |
||
491 |
indication := self indication. |
|
492 |
^ indication value == false |
|
493 |
! |
|
494 |
||
495 |
isOn |
|
496 |
"test whether indication on/off exists and is on |
|
497 |
" |
|
498 |
|indication| |
|
499 |
||
500 |
indication := self indication. |
|
501 |
^ indication value == true |
|
579 | 502 |
! ! |
503 |
||
458 | 504 |
!MenuItem::MenuItemAdornment methodsFor:'accessing'! |
505 |
||
579 | 506 |
accessCharacterPosition |
507 |
"return the value of the instance variable 'accessCharacterPosition' (automatically generated)" |
|
508 |
||
509 |
^ accessCharacterPosition! |
|
510 |
||
511 |
accessCharacterPosition:something |
|
512 |
"set the value of the instance variable 'accessCharacterPosition' (automatically generated)" |
|
513 |
||
514 |
accessCharacterPosition := something.! |
|
515 |
||
684 | 516 |
argument |
517 |
"return the value of the instance variable 'argument' (automatically generated)" |
|
518 |
||
519 |
^ argument |
|
520 |
||
521 |
"Created: 25.2.1997 / 20:59:28 / cg" |
|
522 |
! |
|
523 |
||
524 |
argument:something |
|
525 |
"set the value of the instance variable 'argument' (automatically generated)" |
|
526 |
||
527 |
argument := something. |
|
528 |
||
529 |
"Created: 25.2.1997 / 20:59:28 / cg" |
|
530 |
! |
|
531 |
||
458 | 532 |
color |
533 |
"return the value of the instance variable 'color' (automatically generated)" |
|
534 |
||
535 |
^ color |
|
536 |
||
537 |
"Created: 25.2.1997 / 20:59:28 / cg" |
|
538 |
! |
|
539 |
||
540 |
color:something |
|
541 |
"set the value of the instance variable 'color' (automatically generated)" |
|
542 |
||
543 |
color := something. |
|
544 |
||
545 |
"Created: 25.2.1997 / 20:59:28 / cg" |
|
546 |
! |
|
547 |
||
548 |
indication |
|
590 | 549 |
"test whether the menu item has an on/off indicator (CheckToggle) |
550 |
" |
|
458 | 551 |
^ indication |
552 |
||
553 |
"Created: 25.2.1997 / 20:59:28 / cg" |
|
554 |
! |
|
555 |
||
556 |
indication:something |
|
590 | 557 |
"test whether the menu item has an on/off indicator (CheckToggle) |
558 |
" |
|
458 | 559 |
indication := something. |
560 |
||
561 |
"Created: 25.2.1997 / 20:59:28 / cg" |
|
562 |
! |
|
563 |
||
581 | 564 |
labelImage |
565 |
"return the value of the instance variable 'labelImage' (automatically generated)" |
|
566 |
||
567 |
^ labelImage! |
|
568 |
||
569 |
labelImage:something |
|
570 |
"set the value of the instance variable 'labelImage' (automatically generated)" |
|
571 |
||
572 |
labelImage := something.! |
|
573 |
||
578 | 574 |
labelText |
575 |
"get the text appear as the menu label |
|
576 |
" |
|
577 |
^ labelText |
|
578 |
! |
|
579 |
||
580 |
labelText:something |
|
581 |
"set the text appear as the menu label |
|
582 |
" |
|
583 |
labelText := something. |
|
584 |
! |
|
585 |
||
586 |
shortcutKeyCharacter |
|
587 |
"get the key to press to select the menu item from the keyboard |
|
588 |
" |
|
589 |
^ shortcutKey |
|
590 |
! |
|
591 |
||
592 |
shortcutKeyCharacter:something |
|
593 |
"set the key to press to select the menu item from the keyboard |
|
594 |
" |
|
595 |
shortcutKey := something. |
|
596 |
! |
|
597 |
||
458 | 598 |
submenu |
578 | 599 |
"get the submenu or nil |
600 |
" |
|
458 | 601 |
^ submenu |
602 |
||
603 |
"Created: 25.2.1997 / 20:59:28 / cg" |
|
604 |
! |
|
605 |
||
606 |
submenu:something |
|
578 | 607 |
"set the submenu or nil |
608 |
" |
|
458 | 609 |
submenu := something. |
610 |
||
611 |
"Created: 25.2.1997 / 20:59:28 / cg" |
|
666 | 612 |
! |
613 |
||
614 |
submenuChannel |
|
615 |
"get the submenuChannel or nil |
|
616 |
" |
|
617 |
^ submenuChannel |
|
618 |
! |
|
619 |
||
620 |
submenuChannel:something |
|
621 |
"set the submenuChannel or nil |
|
622 |
" |
|
623 |
submenuChannel := something. |
|
458 | 624 |
! ! |
625 |
||
451 | 626 |
!MenuItem class methodsFor:'documentation'! |
627 |
||
628 |
version |
|
960
fee5a1a50374
adornments submenu may be a valueHolder.
Claus Gittinger <cg@exept.de>
parents:
798
diff
changeset
|
629 |
^ '$Header: /cvs/stx/stx/libview2/MenuItem.st,v 1.21 1998-06-18 14:54:43 cg Exp $' |
451 | 630 |
! ! |