451
|
1 |
Object subclass:#MenuItem
|
458
|
2 |
instanceVariableNames:'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 |
|
580
|
61 |
indication
|
|
62 |
"not yet supported
|
|
63 |
"
|
|
64 |
^ true
|
|
65 |
!
|
|
66 |
|
|
67 |
indication:anIndication
|
|
68 |
"not yet supported
|
|
69 |
"
|
|
70 |
!
|
|
71 |
|
451
|
72 |
label
|
|
73 |
^ label
|
|
74 |
|
|
75 |
"Created: 25.2.1997 / 19:48:16 / cg"
|
|
76 |
!
|
|
77 |
|
453
|
78 |
label:aString
|
|
79 |
label := aString
|
|
80 |
|
|
81 |
"Created: 25.2.1997 / 19:55:16 / cg"
|
|
82 |
!
|
|
83 |
|
581
|
84 |
labelImage
|
|
85 |
"gets the labelImage
|
|
86 |
"
|
|
87 |
adornment notNil ifTrue:[
|
584
|
88 |
^ adornment labelImage value
|
581
|
89 |
].
|
|
90 |
^ nil
|
|
91 |
!
|
|
92 |
|
|
93 |
labelImage:aResourceRetriever
|
|
94 |
"set the labelImage
|
|
95 |
"
|
|
96 |
aResourceRetriever notNil ifTrue:[
|
|
97 |
self adornment labelImage:aResourceRetriever
|
|
98 |
]
|
|
99 |
!
|
|
100 |
|
578
|
101 |
nameKey
|
|
102 |
^ nameKey
|
|
103 |
|
|
104 |
|
|
105 |
!
|
|
106 |
|
|
107 |
nameKey:aNameKey
|
579
|
108 |
nameKey := aNameKey.
|
578
|
109 |
|
|
110 |
|
|
111 |
!
|
|
112 |
|
490
|
113 |
rawLabel
|
|
114 |
^ label
|
|
115 |
|
|
116 |
"Created: 25.2.1997 / 19:48:16 / cg"
|
|
117 |
!
|
|
118 |
|
451
|
119 |
rawLabel:aString
|
|
120 |
label := aString
|
|
121 |
|
|
122 |
"Created: 25.2.1997 / 19:11:02 / cg"
|
|
123 |
!
|
|
124 |
|
490
|
125 |
shortcutKeyCharacter
|
|
126 |
"ignored for now"
|
|
127 |
|
578
|
128 |
adornment notNil ifTrue:[
|
|
129 |
^ adornment shortcutKeyCharacter
|
|
130 |
].
|
490
|
131 |
^ nil
|
|
132 |
!
|
|
133 |
|
578
|
134 |
shortcutKeyCharacter:aKey
|
|
135 |
"set the key to press to select the menu item from the keyboard
|
|
136 |
"
|
579
|
137 |
(aKey isNil and:[adornment isNil]) ifFalse:[
|
|
138 |
self adornment shortcutKeyCharacter:aKey
|
|
139 |
]
|
578
|
140 |
!
|
|
141 |
|
458
|
142 |
submenu
|
578
|
143 |
adornment notNil ifTrue:[
|
|
144 |
^ adornment submenu
|
|
145 |
].
|
|
146 |
^ nil
|
458
|
147 |
|
|
148 |
"Created: 25.2.1997 / 20:57:24 / cg"
|
|
149 |
!
|
|
150 |
|
|
151 |
submenu:aMenu
|
|
152 |
self adornment submenu:aMenu
|
|
153 |
|
|
154 |
"Created: 25.2.1997 / 20:56:20 / cg"
|
|
155 |
!
|
|
156 |
|
451
|
157 |
value
|
|
158 |
^ value
|
|
159 |
|
|
160 |
"Created: 25.2.1997 / 19:50:14 / cg"
|
|
161 |
!
|
|
162 |
|
|
163 |
value:something
|
|
164 |
value := something
|
|
165 |
|
|
166 |
"Created: 25.2.1997 / 19:11:13 / cg"
|
|
167 |
! !
|
|
168 |
|
579
|
169 |
!MenuItem methodsFor:'accessing behavior'!
|
|
170 |
|
|
171 |
disable
|
|
172 |
enabled := false
|
|
173 |
|
|
174 |
"Created: 25.2.1997 / 19:39:09 / cg"
|
|
175 |
!
|
|
176 |
|
|
177 |
enable
|
|
178 |
enabled := true
|
|
179 |
|
|
180 |
"Created: 25.2.1997 / 19:39:00 / cg"
|
|
181 |
!
|
|
182 |
|
581
|
183 |
enabled
|
|
184 |
"returns a boolean, valueHolder or block
|
|
185 |
"
|
|
186 |
^ enabled
|
|
187 |
!
|
579
|
188 |
|
581
|
189 |
enabled:something
|
|
190 |
"a boolean, valueHolder or block
|
|
191 |
"
|
|
192 |
enabled := something
|
|
193 |
! !
|
|
194 |
|
|
195 |
!MenuItem methodsFor:'accessing resource'!
|
|
196 |
|
584
|
197 |
findGuiResourcesIn:aResourceContainerOrApplication
|
581
|
198 |
"setup a resource container
|
|
199 |
"
|
584
|
200 |
|lblImg|
|
581
|
201 |
|
584
|
202 |
adornment notNil ifTrue:[
|
|
203 |
(lblImg := adornment labelImage) notNil ifTrue:[
|
|
204 |
lblImg findGuiResourcesIn:aResourceContainerOrApplication
|
|
205 |
]
|
581
|
206 |
]
|
579
|
207 |
! !
|
|
208 |
|
451
|
209 |
!MenuItem methodsFor:'converting'!
|
|
210 |
|
|
211 |
fromLiteralArrayEncoding:aLiteralEncodedArray
|
|
212 |
"read my contents from a aLiteralEncodedArray"
|
|
213 |
|
|
214 |
2 to:aLiteralEncodedArray size by:2 do:[:i |
|
|
215 |
|selector value|
|
|
216 |
|
|
217 |
selector := aLiteralEncodedArray at:i.
|
581
|
218 |
value := (aLiteralEncodedArray at:i+1) decodeAsLiteralArray.
|
|
219 |
self perform:selector with:value
|
451
|
220 |
].
|
|
221 |
|
|
222 |
"
|
578
|
223 |
#( #MenuItem #rawLabel: 'left' #nameKey: 'identifier' #value: #left )
|
451
|
224 |
decodeAsLiteralArray
|
|
225 |
"
|
|
226 |
|
|
227 |
"Modified: 25.2.1997 / 19:24:22 / cg"
|
490
|
228 |
!
|
|
229 |
|
|
230 |
literalArrayEncoding
|
|
231 |
"return myself encoded as a literal array"
|
|
232 |
|
581
|
233 |
|coll something|
|
490
|
234 |
|
|
235 |
coll := OrderedCollection new.
|
|
236 |
coll add:#MenuItem.
|
581
|
237 |
|
|
238 |
label notNil ifTrue:[
|
|
239 |
coll add:#label: ; add:(label literalArrayEncoding)
|
|
240 |
].
|
|
241 |
|
|
242 |
nameKey notNil ifTrue:[
|
|
243 |
coll add:#nameKey: ; add:(nameKey literalArrayEncoding)
|
|
244 |
].
|
|
245 |
|
|
246 |
(something := self enabled) ifFalse:[
|
|
247 |
coll add:#enabled: ; add:(something literalArrayEncoding).
|
|
248 |
].
|
579
|
249 |
|
|
250 |
value notNil ifTrue:[
|
|
251 |
coll add:#value: ; add:(value literalArrayEncoding).
|
|
252 |
].
|
|
253 |
|
581
|
254 |
(something := self shortcutKeyCharacter) notNil ifTrue:[
|
|
255 |
coll add:#shortcutKeyCharacter: ; add:(something literalArrayEncoding)
|
579
|
256 |
].
|
|
257 |
|
581
|
258 |
(something := self accessCharacterPosition) notNil ifTrue:[
|
|
259 |
coll add:#accessCharacterPosition: ; add:(something literalArrayEncoding)
|
579
|
260 |
].
|
|
261 |
|
581
|
262 |
(something := self labelImage) notNil ifTrue:[
|
|
263 |
coll add:#labelImage: ; add:(something literalArrayEncoding)
|
|
264 |
].
|
579
|
265 |
^ coll asArray
|
451
|
266 |
! !
|
|
267 |
|
458
|
268 |
!MenuItem methodsFor:'private - accessing'!
|
|
269 |
|
|
270 |
adornment
|
|
271 |
adornment isNil ifTrue:[
|
|
272 |
adornment := MenuItemAdornment new
|
|
273 |
].
|
|
274 |
^ adornment
|
|
275 |
|
|
276 |
"Created: 25.2.1997 / 20:57:05 / cg"
|
|
277 |
! !
|
|
278 |
|
579
|
279 |
!MenuItem methodsFor:'queries'!
|
|
280 |
|
|
281 |
hasSubmenu
|
584
|
282 |
^ self submenu notNil
|
579
|
283 |
|
|
284 |
"Created: 25.2.1997 / 20:56:20 / cg"
|
|
285 |
!
|
|
286 |
|
|
287 |
isEnabled
|
581
|
288 |
^ enabled value ? true
|
579
|
289 |
|
|
290 |
"Created: 25.2.1997 / 19:39:17 / cg"
|
|
291 |
! !
|
|
292 |
|
458
|
293 |
!MenuItem::MenuItemAdornment methodsFor:'accessing'!
|
|
294 |
|
579
|
295 |
accessCharacterPosition
|
|
296 |
"return the value of the instance variable 'accessCharacterPosition' (automatically generated)"
|
|
297 |
|
|
298 |
^ accessCharacterPosition!
|
|
299 |
|
|
300 |
accessCharacterPosition:something
|
|
301 |
"set the value of the instance variable 'accessCharacterPosition' (automatically generated)"
|
|
302 |
|
|
303 |
accessCharacterPosition := something.!
|
|
304 |
|
458
|
305 |
color
|
|
306 |
"return the value of the instance variable 'color' (automatically generated)"
|
|
307 |
|
|
308 |
^ color
|
|
309 |
|
|
310 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
|
311 |
!
|
|
312 |
|
|
313 |
color:something
|
|
314 |
"set the value of the instance variable 'color' (automatically generated)"
|
|
315 |
|
|
316 |
color := something.
|
|
317 |
|
|
318 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
|
319 |
!
|
|
320 |
|
|
321 |
indication
|
|
322 |
"return the value of the instance variable 'indication' (automatically generated)"
|
|
323 |
|
|
324 |
^ indication
|
|
325 |
|
|
326 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
|
327 |
!
|
|
328 |
|
|
329 |
indication:something
|
|
330 |
"set the value of the instance variable 'indication' (automatically generated)"
|
|
331 |
|
|
332 |
indication := something.
|
|
333 |
|
|
334 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
|
335 |
!
|
|
336 |
|
581
|
337 |
labelImage
|
|
338 |
"return the value of the instance variable 'labelImage' (automatically generated)"
|
|
339 |
|
|
340 |
^ labelImage!
|
|
341 |
|
|
342 |
labelImage:something
|
|
343 |
"set the value of the instance variable 'labelImage' (automatically generated)"
|
|
344 |
|
|
345 |
labelImage := something.!
|
|
346 |
|
578
|
347 |
labelText
|
|
348 |
"get the text appear as the menu label
|
|
349 |
"
|
|
350 |
^ labelText
|
|
351 |
!
|
|
352 |
|
|
353 |
labelText:something
|
|
354 |
"set the text appear as the menu label
|
|
355 |
"
|
|
356 |
labelText := something.
|
|
357 |
!
|
|
358 |
|
|
359 |
shortcutKeyCharacter
|
|
360 |
"get the key to press to select the menu item from the keyboard
|
|
361 |
"
|
|
362 |
^ shortcutKey
|
|
363 |
!
|
|
364 |
|
|
365 |
shortcutKeyCharacter:something
|
|
366 |
"set the key to press to select the menu item from the keyboard
|
|
367 |
"
|
|
368 |
shortcutKey := something.
|
|
369 |
!
|
|
370 |
|
458
|
371 |
submenu
|
578
|
372 |
"get the submenu or nil
|
|
373 |
"
|
458
|
374 |
^ submenu
|
|
375 |
|
|
376 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
|
377 |
!
|
|
378 |
|
|
379 |
submenu:something
|
578
|
380 |
"set the submenu or nil
|
|
381 |
"
|
458
|
382 |
submenu := something.
|
|
383 |
|
|
384 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
|
385 |
! !
|
|
386 |
|
451
|
387 |
!MenuItem class methodsFor:'documentation'!
|
|
388 |
|
|
389 |
version
|
584
|
390 |
^ '$Header: /cvs/stx/stx/libview2/MenuItem.st,v 1.10 1997-05-27 09:11:29 ca Exp $'
|
451
|
391 |
! !
|