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
|
579
|
9 |
instanceVariableNames:'color indication submenu shortcutKey labelText
|
|
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 |
|
578
|
84 |
nameKey
|
|
85 |
^ nameKey
|
|
86 |
|
|
87 |
|
|
88 |
!
|
|
89 |
|
|
90 |
nameKey:aNameKey
|
579
|
91 |
nameKey := aNameKey.
|
578
|
92 |
|
|
93 |
|
|
94 |
!
|
|
95 |
|
490
|
96 |
rawLabel
|
|
97 |
^ label
|
|
98 |
|
|
99 |
"Created: 25.2.1997 / 19:48:16 / cg"
|
|
100 |
!
|
|
101 |
|
451
|
102 |
rawLabel:aString
|
|
103 |
label := aString
|
|
104 |
|
|
105 |
"Created: 25.2.1997 / 19:11:02 / cg"
|
|
106 |
!
|
|
107 |
|
490
|
108 |
shortcutKeyCharacter
|
|
109 |
"ignored for now"
|
|
110 |
|
578
|
111 |
adornment notNil ifTrue:[
|
|
112 |
^ adornment shortcutKeyCharacter
|
|
113 |
].
|
490
|
114 |
^ nil
|
|
115 |
!
|
|
116 |
|
578
|
117 |
shortcutKeyCharacter:aKey
|
|
118 |
"set the key to press to select the menu item from the keyboard
|
|
119 |
"
|
579
|
120 |
(aKey isNil and:[adornment isNil]) ifFalse:[
|
|
121 |
self adornment shortcutKeyCharacter:aKey
|
|
122 |
]
|
578
|
123 |
!
|
|
124 |
|
458
|
125 |
submenu
|
578
|
126 |
adornment notNil ifTrue:[
|
|
127 |
^ adornment submenu
|
|
128 |
].
|
|
129 |
^ nil
|
458
|
130 |
|
|
131 |
"Created: 25.2.1997 / 20:57:24 / cg"
|
|
132 |
!
|
|
133 |
|
|
134 |
submenu:aMenu
|
|
135 |
self adornment submenu:aMenu
|
|
136 |
|
|
137 |
"Created: 25.2.1997 / 20:56:20 / cg"
|
|
138 |
!
|
|
139 |
|
451
|
140 |
value
|
|
141 |
^ value
|
|
142 |
|
|
143 |
"Created: 25.2.1997 / 19:50:14 / cg"
|
|
144 |
!
|
|
145 |
|
|
146 |
value:something
|
|
147 |
value := something
|
|
148 |
|
|
149 |
"Created: 25.2.1997 / 19:11:13 / cg"
|
|
150 |
! !
|
|
151 |
|
579
|
152 |
!MenuItem methodsFor:'accessing behavior'!
|
|
153 |
|
|
154 |
disable
|
|
155 |
enabled := false
|
|
156 |
|
|
157 |
"Created: 25.2.1997 / 19:39:09 / cg"
|
|
158 |
!
|
|
159 |
|
|
160 |
enable
|
|
161 |
enabled := true
|
|
162 |
|
|
163 |
"Created: 25.2.1997 / 19:39:00 / cg"
|
|
164 |
!
|
|
165 |
|
|
166 |
enabled:aBoolean
|
|
167 |
enabled := aBoolean
|
|
168 |
|
|
169 |
"Created: 25.2.1997 / 19:39:27 / cg"
|
|
170 |
! !
|
|
171 |
|
451
|
172 |
!MenuItem methodsFor:'converting'!
|
|
173 |
|
|
174 |
fromLiteralArrayEncoding:aLiteralEncodedArray
|
|
175 |
"read my contents from a aLiteralEncodedArray"
|
|
176 |
|
|
177 |
2 to:aLiteralEncodedArray size by:2 do:[:i |
|
|
178 |
|selector value|
|
|
179 |
|
|
180 |
selector := aLiteralEncodedArray at:i.
|
580
|
181 |
selector == #labelImage: ifFalse:[
|
|
182 |
value := (aLiteralEncodedArray at:i+1) decodeAsLiteralArray.
|
451
|
183 |
|
580
|
184 |
self perform:selector with:value
|
|
185 |
]
|
451
|
186 |
].
|
|
187 |
|
|
188 |
"
|
578
|
189 |
#( #MenuItem #rawLabel: 'left' #nameKey: 'identifier' #value: #left )
|
451
|
190 |
decodeAsLiteralArray
|
|
191 |
"
|
|
192 |
|
|
193 |
"Modified: 25.2.1997 / 19:24:22 / cg"
|
490
|
194 |
!
|
|
195 |
|
|
196 |
literalArrayEncoding
|
|
197 |
"return myself encoded as a literal array"
|
|
198 |
|
579
|
199 |
|coll key|
|
490
|
200 |
|
|
201 |
coll := OrderedCollection new.
|
|
202 |
coll add:#MenuItem.
|
|
203 |
coll add:#label: ; add:(label literalArrayEncoding).
|
578
|
204 |
coll add:#nameKey: ; add:(nameKey literalArrayEncoding).
|
490
|
205 |
coll add:#enabled: ; add:(enabled literalArrayEncoding).
|
579
|
206 |
|
|
207 |
value notNil ifTrue:[
|
|
208 |
coll add:#value: ; add:(value literalArrayEncoding).
|
|
209 |
].
|
|
210 |
|
|
211 |
(key := self shortcutKeyCharacter) notNil ifTrue:[
|
|
212 |
coll add:#shortcutKeyCharacter: ; add:(key literalArrayEncoding)
|
|
213 |
].
|
|
214 |
|
|
215 |
(key := self accessCharacterPosition) notNil ifTrue:[
|
|
216 |
coll add:#accessCharacterPosition: ; add:(key literalArrayEncoding)
|
|
217 |
].
|
|
218 |
|
|
219 |
^ coll asArray
|
451
|
220 |
! !
|
|
221 |
|
458
|
222 |
!MenuItem methodsFor:'private - accessing'!
|
|
223 |
|
|
224 |
adornment
|
|
225 |
adornment isNil ifTrue:[
|
|
226 |
adornment := MenuItemAdornment new
|
|
227 |
].
|
|
228 |
^ adornment
|
|
229 |
|
|
230 |
"Created: 25.2.1997 / 20:57:05 / cg"
|
|
231 |
! !
|
|
232 |
|
579
|
233 |
!MenuItem methodsFor:'queries'!
|
|
234 |
|
|
235 |
hasSubmenu
|
|
236 |
^ self subMenu notNil
|
|
237 |
|
|
238 |
"Created: 25.2.1997 / 20:56:20 / cg"
|
|
239 |
!
|
|
240 |
|
|
241 |
isEnabled
|
|
242 |
^ enabled ? true
|
|
243 |
|
|
244 |
"Created: 25.2.1997 / 19:39:17 / cg"
|
|
245 |
! !
|
|
246 |
|
458
|
247 |
!MenuItem::MenuItemAdornment methodsFor:'accessing'!
|
|
248 |
|
579
|
249 |
accessCharacterPosition
|
|
250 |
"return the value of the instance variable 'accessCharacterPosition' (automatically generated)"
|
|
251 |
|
|
252 |
^ accessCharacterPosition!
|
|
253 |
|
|
254 |
accessCharacterPosition:something
|
|
255 |
"set the value of the instance variable 'accessCharacterPosition' (automatically generated)"
|
|
256 |
|
|
257 |
accessCharacterPosition := something.!
|
|
258 |
|
458
|
259 |
color
|
|
260 |
"return the value of the instance variable 'color' (automatically generated)"
|
|
261 |
|
|
262 |
^ color
|
|
263 |
|
|
264 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
|
265 |
!
|
|
266 |
|
|
267 |
color:something
|
|
268 |
"set the value of the instance variable 'color' (automatically generated)"
|
|
269 |
|
|
270 |
color := something.
|
|
271 |
|
|
272 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
|
273 |
!
|
|
274 |
|
|
275 |
indication
|
|
276 |
"return the value of the instance variable 'indication' (automatically generated)"
|
|
277 |
|
|
278 |
^ indication
|
|
279 |
|
|
280 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
|
281 |
!
|
|
282 |
|
|
283 |
indication:something
|
|
284 |
"set the value of the instance variable 'indication' (automatically generated)"
|
|
285 |
|
|
286 |
indication := something.
|
|
287 |
|
|
288 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
|
289 |
!
|
|
290 |
|
578
|
291 |
labelText
|
|
292 |
"get the text appear as the menu label
|
|
293 |
"
|
|
294 |
^ labelText
|
|
295 |
!
|
|
296 |
|
|
297 |
labelText:something
|
|
298 |
"set the text appear as the menu label
|
|
299 |
"
|
|
300 |
labelText := something.
|
|
301 |
!
|
|
302 |
|
|
303 |
shortcutKeyCharacter
|
|
304 |
"get the key to press to select the menu item from the keyboard
|
|
305 |
"
|
|
306 |
^ shortcutKey
|
|
307 |
!
|
|
308 |
|
|
309 |
shortcutKeyCharacter:something
|
|
310 |
"set the key to press to select the menu item from the keyboard
|
|
311 |
"
|
|
312 |
shortcutKey := something.
|
|
313 |
!
|
|
314 |
|
458
|
315 |
submenu
|
578
|
316 |
"get the submenu or nil
|
|
317 |
"
|
458
|
318 |
^ submenu
|
|
319 |
|
|
320 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
|
321 |
!
|
|
322 |
|
|
323 |
submenu:something
|
578
|
324 |
"set the submenu or nil
|
|
325 |
"
|
458
|
326 |
submenu := something.
|
|
327 |
|
|
328 |
"Created: 25.2.1997 / 20:59:28 / cg"
|
|
329 |
! !
|
|
330 |
|
451
|
331 |
!MenuItem class methodsFor:'documentation'!
|
|
332 |
|
|
333 |
version
|
580
|
334 |
^ '$Header: /cvs/stx/stx/libview2/MenuItem.st,v 1.8 1997-05-22 11:39:07 ca Exp $'
|
451
|
335 |
! !
|