451
|
1 |
Object subclass:#Menu
|
454
|
2 |
instanceVariableNames:'items groupSizes'
|
451
|
3 |
classVariableNames:''
|
|
4 |
poolDictionaries:''
|
|
5 |
category:'Views-Support'
|
|
6 |
!
|
|
7 |
|
|
8 |
!Menu class methodsFor:'documentation'!
|
|
9 |
|
|
10 |
documentation
|
|
11 |
"
|
|
12 |
not yet finished Menu class - this will eventually replace
|
|
13 |
most of the MenuView and PopUpMenu stuff.
|
|
14 |
(and hopefully be ST-80 compatible ...)
|
|
15 |
|
|
16 |
For now, only a subset of the full protocol is implemented.
|
|
17 |
|
|
18 |
[author:]
|
|
19 |
Claus Gittinger
|
|
20 |
|
|
21 |
[see also:]
|
|
22 |
MenuItem
|
|
23 |
PopUpMenu
|
|
24 |
"
|
|
25 |
! !
|
|
26 |
|
|
27 |
!Menu methodsFor:'accessing'!
|
|
28 |
|
489
|
29 |
addItem:aMenuItem value:aValue
|
|
30 |
items isNil ifTrue:[
|
|
31 |
items := OrderedCollection new
|
|
32 |
].
|
|
33 |
items add:aMenuItem.
|
|
34 |
aMenuItem value:aValue
|
|
35 |
!
|
|
36 |
|
|
37 |
addItemGroup:aGroup values:values
|
|
38 |
groupSizes isNil ifTrue:[
|
|
39 |
groupSizes := OrderedCollection new
|
|
40 |
].
|
|
41 |
groupSizes add:items size.
|
|
42 |
|
|
43 |
aGroup with:values do:[:item :value |
|
|
44 |
self addItem:item value:value
|
|
45 |
].
|
|
46 |
!
|
|
47 |
|
451
|
48 |
labels
|
|
49 |
"return a collection of labels from my items"
|
|
50 |
|
|
51 |
^ items collect:[:anItem | anItem label]
|
|
52 |
|
|
53 |
"Created: 25.2.1997 / 19:47:53 / cg"
|
|
54 |
!
|
|
55 |
|
489
|
56 |
lines
|
|
57 |
"Answer the indexes of the menu items that are the last menu item in their group (except the very last)."
|
|
58 |
|
|
59 |
| lines |
|
|
60 |
groupSizes size <= 1 ifTrue: [^Array new].
|
|
61 |
lines := Array new: groupSizes size - 1.
|
|
62 |
lines at: 1 put: groupSizes first.
|
|
63 |
2 to: groupSizes size -1 do:
|
|
64 |
[:i |
|
|
65 |
lines at: i put: (lines at: i - 1) + (groupSizes at: i)].
|
|
66 |
^lines
|
|
67 |
|
|
68 |
|
|
69 |
!
|
|
70 |
|
|
71 |
menuItemAt:index
|
|
72 |
^ items at:index
|
|
73 |
!
|
|
74 |
|
|
75 |
menuItems
|
|
76 |
^ items
|
|
77 |
!
|
|
78 |
|
454
|
79 |
menuItems:aCollectionOfMenuItems groupsSizes:sizes values:values
|
456
|
80 |
|idx newItems nItems|
|
454
|
81 |
|
451
|
82 |
items := aCollectionOfMenuItems.
|
|
83 |
values notNil ifTrue:[
|
|
84 |
items with:values do:[:anItem :aValue |
|
|
85 |
anItem value:aValue
|
|
86 |
]
|
454
|
87 |
].
|
|
88 |
|
|
89 |
"/ add empty items for group-separating lines.
|
451
|
90 |
|
454
|
91 |
groupSizes := sizes.
|
|
92 |
groupSizes notNil ifTrue:[
|
|
93 |
idx := 1.
|
456
|
94 |
nItems := items size.
|
|
95 |
newItems := OrderedCollection new:(nItems + groupSizes size).
|
454
|
96 |
groupSizes do:[:aGroupSize |
|
|
97 |
items from:idx to:idx+aGroupSize-1 do:[:l | newItems add:l].
|
456
|
98 |
idx := idx + aGroupSize.
|
457
|
99 |
idx <= nItems ifTrue:[
|
456
|
100 |
newItems add:(MenuItem new label:'-').
|
|
101 |
]
|
454
|
102 |
].
|
456
|
103 |
items from:idx to:nItems do:[:l | newItems add:l].
|
454
|
104 |
items := newItems.
|
|
105 |
].
|
|
106 |
|
|
107 |
"Created: 25.2.1997 / 20:28:12 / cg"
|
457
|
108 |
"Modified: 25.2.1997 / 21:03:33 / cg"
|
451
|
109 |
!
|
|
110 |
|
494
|
111 |
numberOfItems
|
|
112 |
^ items size
|
|
113 |
|
|
114 |
"Created: 6.3.1997 / 15:15:53 / cg"
|
|
115 |
!
|
|
116 |
|
451
|
117 |
valueAt:index
|
|
118 |
"return a collection of values from my items"
|
|
119 |
|
|
120 |
^ (items at:index) value
|
|
121 |
|
|
122 |
"Created: 25.2.1997 / 19:49:41 / cg"
|
|
123 |
!
|
|
124 |
|
494
|
125 |
valueAt:anIndex put:aValue
|
|
126 |
"put value an an index"
|
|
127 |
|
|
128 |
(items at:anIndex) value:aValue
|
|
129 |
|
|
130 |
"Created: 6.3.1997 / 15:15:48 / cg"
|
|
131 |
!
|
|
132 |
|
451
|
133 |
values
|
|
134 |
"return a collection of values from my items"
|
|
135 |
|
|
136 |
^ items collect:[:anItem | anItem value]
|
|
137 |
|
|
138 |
"Created: 25.2.1997 / 19:49:29 / cg"
|
|
139 |
! !
|
|
140 |
|
|
141 |
!Menu methodsFor:'converting'!
|
|
142 |
|
|
143 |
fromLiteralArrayEncoding:aLiteralEncodedArray
|
|
144 |
"read my contents from a aLiteralEncodedArray"
|
|
145 |
|
|
146 |
|items groups values|
|
|
147 |
|
|
148 |
items := (aLiteralEncodedArray at:2) collect:[:item | item decodeAsLiteralArray].
|
|
149 |
groups := aLiteralEncodedArray at:3.
|
452
|
150 |
values := aLiteralEncodedArray at:4.
|
454
|
151 |
self menuItems:items groupsSizes:groups values:values.
|
451
|
152 |
|
|
153 |
"extract from PD folder.st:
|
|
154 |
#(#Menu #(
|
|
155 |
#(#MenuItem
|
|
156 |
#rawLabel: 'left'
|
|
157 |
#value: #left )
|
|
158 |
#(#MenuItem
|
|
159 |
#rawLabel: 'center'
|
|
160 |
#value: #center )
|
|
161 |
#(#MenuItem
|
|
162 |
#rawLabel: 'right'
|
|
163 |
#value: #right )
|
|
164 |
)
|
|
165 |
#(3 )
|
|
166 |
nil
|
|
167 |
) decodeAsLiteralArray
|
|
168 |
"
|
452
|
169 |
"
|
|
170 |
#(#Menu #(
|
|
171 |
#(#MenuItem
|
|
172 |
#label: 'Straighten Up' )
|
|
173 |
#(#MenuItem
|
|
174 |
#label: 'Inspect' )
|
|
175 |
#(#MenuItem
|
|
176 |
#label: 'Coredump' )
|
|
177 |
)
|
|
178 |
#(3 )
|
|
179 |
#(#straightenUp #inspect #halt )
|
|
180 |
) decodeAsLiteralArray startUp
|
|
181 |
"
|
457
|
182 |
|
454
|
183 |
"extract from iconicBrowser.st:
|
452
|
184 |
#(#Menu #(
|
|
185 |
#(#MenuItem
|
|
186 |
#label: 'Straighten Up' )
|
|
187 |
#(#MenuItem
|
|
188 |
#label: 'Inspect' )
|
|
189 |
#(#MenuItem
|
|
190 |
#label: 'Coredump' )
|
|
191 |
)
|
|
192 |
#(3 )
|
|
193 |
#(1 2 3 )
|
|
194 |
) decodeAsLiteralArray startUp
|
|
195 |
"
|
451
|
196 |
|
454
|
197 |
"extract from refactory213.st:
|
|
198 |
#(#Menu #(
|
|
199 |
#(#MenuItem
|
|
200 |
#label: 'File List'
|
|
201 |
#accessCharacterPosition: 1 )
|
|
202 |
#(#MenuItem #label: 'File Editor...'
|
|
203 |
#accessCharacterPosition: 6 )
|
|
204 |
#(#MenuItem #label: 'Refactoring Tool...'
|
|
205 |
#accessCharacterPosition: 1 )
|
|
206 |
#(#MenuItem #label: 'Workspace'
|
|
207 |
#accessCharacterPosition: 1 )
|
|
208 |
#(#MenuItem #label: 'New Canvas'
|
|
209 |
#accessCharacterPosition: 1 )
|
|
210 |
#(#MenuItem #label: 'Palette'
|
|
211 |
#accessCharacterPosition: 1 )
|
|
212 |
#(#MenuItem #label: 'Canvas Tool'
|
|
213 |
#accessCharacterPosition: 1 )
|
|
214 |
#(#MenuItem #label: 'Image Editor'
|
|
215 |
#accessCharacterPosition: 1 )
|
|
216 |
#(#MenuItem #label: 'Menu Editor'
|
|
217 |
#accessCharacterPosition: 1 )
|
|
218 |
#(#MenuItem #label: 'Advanced'
|
|
219 |
#accessCharacterPosition: 1 )
|
|
220 |
#(#MenuItem #label: 'DLL and C Connect'
|
|
221 |
#accessCharacterPosition: 1 )
|
|
222 |
#(#MenuItem #label: 'System Transcript'
|
|
223 |
#accessCharacterPosition: 8 )
|
|
224 |
)
|
|
225 |
#(4 5 2 1 )
|
|
226 |
#(#openFileList #openFileEditor #openRefactoringTool #toolsNewWorkspace #toolsNewCanvas #toolsPalette #toolsCanvasTool #toolsMaskEditor #toolsMenuEditor nil #openExternalFinder #toggleSystemTranscript )
|
456
|
227 |
) decodeAsLiteralArray startUp
|
454
|
228 |
"
|
|
229 |
|
457
|
230 |
"submenus:
|
|
231 |
#(#Menu #(
|
|
232 |
#(#MenuItem
|
|
233 |
#label: 'Foo'
|
|
234 |
#submenu: #(#Menu #(
|
|
235 |
#(#MenuItem #label: 'foo 1')
|
|
236 |
#(#MenuItem #label: 'foo 2')
|
|
237 |
)
|
|
238 |
nil
|
|
239 |
#(11 22)
|
|
240 |
)
|
|
241 |
)
|
|
242 |
#(#MenuItem
|
|
243 |
#label: 'Inspect' )
|
|
244 |
#(#MenuItem
|
|
245 |
#label: 'Coredump' )
|
|
246 |
)
|
|
247 |
#(3 )
|
|
248 |
#(1 2 3 )
|
|
249 |
) decodeAsLiteralArray startUp
|
|
250 |
"
|
|
251 |
|
|
252 |
"Modified: 25.2.1997 / 21:05:06 / cg"
|
489
|
253 |
!
|
|
254 |
|
|
255 |
literalArrayEncoding
|
|
256 |
"return myself encoded as a literal array"
|
|
257 |
|
|
258 |
|coll|
|
|
259 |
|
|
260 |
coll := OrderedCollection new.
|
|
261 |
coll add:#Menu.
|
|
262 |
coll add:(items literalArrayEncoding).
|
|
263 |
coll add:(groupSizes literalArrayEncoding).
|
|
264 |
coll add:nil.
|
|
265 |
^ coll asArray
|
451
|
266 |
! !
|
|
267 |
|
|
268 |
!Menu methodsFor:'startup'!
|
|
269 |
|
457
|
270 |
createPopUpMenu
|
|
271 |
"create a popUpMenu for the receiver"
|
|
272 |
|
|
273 |
|menuView val index labels |
|
|
274 |
|
|
275 |
"/ for now, use PopUpMenu ....
|
|
276 |
"/ ... eventually, MenuView will handle me directly
|
|
277 |
|
|
278 |
labels := self labels.
|
|
279 |
|
|
280 |
menuView := PopUpMenu labels:labels.
|
|
281 |
|
|
282 |
"/ manually convert subMenus ...
|
|
283 |
|
|
284 |
items keysAndValuesDo:[:idx :anItem |
|
|
285 |
|sub m|
|
|
286 |
|
|
287 |
(sub := anItem submenu) notNil ifTrue:[
|
|
288 |
m := sub createPopUpMenu.
|
|
289 |
menuView subMenuAt:idx put:m
|
|
290 |
]
|
|
291 |
].
|
|
292 |
|
|
293 |
^ menuView
|
|
294 |
|
|
295 |
"Created: 25.2.1997 / 21:02:21 / cg"
|
|
296 |
!
|
|
297 |
|
451
|
298 |
startUp
|
|
299 |
"display the menu as a popUp; return the value associated with the
|
|
300 |
selected item, 0 if none was selected"
|
|
301 |
|
457
|
302 |
|menuView val index |
|
451
|
303 |
|
|
304 |
"/ for now, use PopUpMenu ....
|
457
|
305 |
"/ ... eventually, MenuView will handle me directly
|
451
|
306 |
|
457
|
307 |
menuView := self createPopUpMenu.
|
454
|
308 |
index := menuView startUp.
|
|
309 |
menuView destroy.
|
457
|
310 |
|
454
|
311 |
(index notNil and:[index ~~ 0]) ifTrue:[
|
452
|
312 |
val := self valueAt:index.
|
|
313 |
val notNil ifTrue:[
|
|
314 |
^ val
|
|
315 |
]
|
451
|
316 |
].
|
|
317 |
^ 0
|
|
318 |
|
|
319 |
"
|
|
320 |
|m|
|
|
321 |
m := #(#Menu #(
|
|
322 |
#(#MenuItem
|
|
323 |
#rawLabel: 'left'
|
|
324 |
#value: #left )
|
|
325 |
#(#MenuItem
|
|
326 |
#rawLabel: 'center'
|
|
327 |
#value: #center )
|
|
328 |
#(#MenuItem
|
|
329 |
#rawLabel: 'right'
|
|
330 |
#value: #right ) )
|
457
|
331 |
#(3)
|
451
|
332 |
nil
|
|
333 |
) decodeAsLiteralArray.
|
457
|
334 |
m startUp
|
451
|
335 |
"
|
|
336 |
|
457
|
337 |
"Modified: 26.2.1997 / 10:41:37 / cg"
|
451
|
338 |
! !
|
|
339 |
|
|
340 |
!Menu class methodsFor:'documentation'!
|
|
341 |
|
|
342 |
version
|
494
|
343 |
^ '$Header: /cvs/stx/stx/libview2/Menu.st,v 1.7 1997-03-06 14:16:03 cg Exp $'
|
451
|
344 |
! !
|