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