451
|
1 |
Object subclass:#Menu
|
579
|
2 |
instanceVariableNames:'items groupSizes receiver'
|
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 |
|
578
|
48 |
groupSizes
|
|
49 |
"return the value of the instance variable 'groupSizes' (automatically generated)"
|
|
50 |
|
|
51 |
^ groupSizes!
|
|
52 |
|
|
53 |
groupSizes:something
|
|
54 |
"set the value of the instance variable 'groupSizes' (automatically generated)"
|
|
55 |
|
|
56 |
groupSizes := something.!
|
|
57 |
|
451
|
58 |
labels
|
|
59 |
"return a collection of labels from my items"
|
|
60 |
|
|
61 |
^ items collect:[:anItem | anItem label]
|
|
62 |
|
|
63 |
"Created: 25.2.1997 / 19:47:53 / cg"
|
|
64 |
!
|
|
65 |
|
489
|
66 |
lines
|
579
|
67 |
"Answer the indexes of the menu items that are the last menu item in their group (except the very last)."
|
489
|
68 |
|
579
|
69 |
| lines |
|
|
70 |
groupSizes size <= 1 ifTrue: [^Array new].
|
|
71 |
lines := Array new: groupSizes size - 1.
|
|
72 |
lines at: 1 put: groupSizes first.
|
|
73 |
2 to: groupSizes size -1 do:
|
|
74 |
[:i |
|
|
75 |
lines at: i put: (lines at: i - 1) + (groupSizes at: i)].
|
|
76 |
^lines
|
489
|
77 |
|
|
78 |
|
|
79 |
!
|
|
80 |
|
|
81 |
menuItemAt:index
|
|
82 |
^ items at:index
|
|
83 |
!
|
|
84 |
|
|
85 |
menuItems
|
|
86 |
^ items
|
|
87 |
!
|
|
88 |
|
454
|
89 |
menuItems:aCollectionOfMenuItems groupsSizes:sizes values:values
|
456
|
90 |
|idx newItems nItems|
|
454
|
91 |
|
451
|
92 |
items := aCollectionOfMenuItems.
|
579
|
93 |
groupSizes := sizes.
|
451
|
94 |
|
579
|
95 |
values notNil ifTrue:[
|
|
96 |
items with:values do:[:anItem :aValue |anItem value:aValue]
|
454
|
97 |
].
|
451
|
98 |
!
|
|
99 |
|
494
|
100 |
numberOfItems
|
|
101 |
^ items size
|
|
102 |
|
|
103 |
"Created: 6.3.1997 / 15:15:53 / cg"
|
|
104 |
!
|
|
105 |
|
579
|
106 |
receiver
|
|
107 |
"return the value of the instance variable 'receiver' (automatically generated)"
|
|
108 |
|
|
109 |
^ receiver!
|
|
110 |
|
|
111 |
receiver:something
|
|
112 |
"set the value of the instance variable 'receiver' (automatically generated)"
|
|
113 |
|
|
114 |
receiver := something.!
|
|
115 |
|
451
|
116 |
valueAt:index
|
|
117 |
"return a collection of values from my items"
|
|
118 |
|
|
119 |
^ (items at:index) value
|
|
120 |
|
|
121 |
"Created: 25.2.1997 / 19:49:41 / cg"
|
|
122 |
!
|
|
123 |
|
494
|
124 |
valueAt:anIndex put:aValue
|
|
125 |
"put value an an index"
|
|
126 |
|
|
127 |
(items at:anIndex) value:aValue
|
|
128 |
|
|
129 |
"Created: 6.3.1997 / 15:15:48 / cg"
|
|
130 |
!
|
|
131 |
|
451
|
132 |
values
|
|
133 |
"return a collection of values from my items"
|
|
134 |
|
|
135 |
^ items collect:[:anItem | anItem value]
|
|
136 |
|
|
137 |
"Created: 25.2.1997 / 19:49:29 / cg"
|
|
138 |
! !
|
|
139 |
|
582
|
140 |
!Menu methodsFor:'accessing resource'!
|
|
141 |
|
|
142 |
findGuiResourcesIn:aResourceContainer
|
|
143 |
"setup a resource owner
|
|
144 |
"
|
|
145 |
aResourceContainer notNil ifTrue:[
|
|
146 |
items notNil ifTrue:[
|
|
147 |
items do:[:anItem| anItem findGuiResourcesIn:aResourceContainer ]
|
|
148 |
]
|
|
149 |
]
|
|
150 |
|
|
151 |
! !
|
|
152 |
|
451
|
153 |
!Menu methodsFor:'converting'!
|
|
154 |
|
|
155 |
fromLiteralArrayEncoding:aLiteralEncodedArray
|
|
156 |
"read my contents from a aLiteralEncodedArray"
|
|
157 |
|
|
158 |
|items groups values|
|
|
159 |
|
|
160 |
items := (aLiteralEncodedArray at:2) collect:[:item | item decodeAsLiteralArray].
|
|
161 |
groups := aLiteralEncodedArray at:3.
|
452
|
162 |
values := aLiteralEncodedArray at:4.
|
454
|
163 |
self menuItems:items groupsSizes:groups values:values.
|
451
|
164 |
|
|
165 |
"extract from PD folder.st:
|
|
166 |
#(#Menu #(
|
|
167 |
#(#MenuItem
|
|
168 |
#rawLabel: 'left'
|
|
169 |
#value: #left )
|
|
170 |
#(#MenuItem
|
|
171 |
#rawLabel: 'center'
|
|
172 |
#value: #center )
|
|
173 |
#(#MenuItem
|
|
174 |
#rawLabel: 'right'
|
|
175 |
#value: #right )
|
|
176 |
)
|
|
177 |
#(3 )
|
|
178 |
nil
|
|
179 |
) decodeAsLiteralArray
|
|
180 |
"
|
452
|
181 |
"
|
|
182 |
#(#Menu #(
|
|
183 |
#(#MenuItem
|
|
184 |
#label: 'Straighten Up' )
|
|
185 |
#(#MenuItem
|
|
186 |
#label: 'Inspect' )
|
|
187 |
#(#MenuItem
|
|
188 |
#label: 'Coredump' )
|
|
189 |
)
|
|
190 |
#(3 )
|
|
191 |
#(#straightenUp #inspect #halt )
|
|
192 |
) decodeAsLiteralArray startUp
|
|
193 |
"
|
457
|
194 |
|
454
|
195 |
"extract from iconicBrowser.st:
|
452
|
196 |
#(#Menu #(
|
|
197 |
#(#MenuItem
|
|
198 |
#label: 'Straighten Up' )
|
|
199 |
#(#MenuItem
|
|
200 |
#label: 'Inspect' )
|
|
201 |
#(#MenuItem
|
|
202 |
#label: 'Coredump' )
|
|
203 |
)
|
|
204 |
#(3 )
|
|
205 |
#(1 2 3 )
|
|
206 |
) decodeAsLiteralArray startUp
|
|
207 |
"
|
451
|
208 |
|
454
|
209 |
"extract from refactory213.st:
|
|
210 |
#(#Menu #(
|
|
211 |
#(#MenuItem
|
|
212 |
#label: 'File List'
|
|
213 |
#accessCharacterPosition: 1 )
|
|
214 |
#(#MenuItem #label: 'File Editor...'
|
|
215 |
#accessCharacterPosition: 6 )
|
|
216 |
#(#MenuItem #label: 'Refactoring Tool...'
|
|
217 |
#accessCharacterPosition: 1 )
|
|
218 |
#(#MenuItem #label: 'Workspace'
|
|
219 |
#accessCharacterPosition: 1 )
|
|
220 |
#(#MenuItem #label: 'New Canvas'
|
|
221 |
#accessCharacterPosition: 1 )
|
|
222 |
#(#MenuItem #label: 'Palette'
|
|
223 |
#accessCharacterPosition: 1 )
|
|
224 |
#(#MenuItem #label: 'Canvas Tool'
|
|
225 |
#accessCharacterPosition: 1 )
|
|
226 |
#(#MenuItem #label: 'Image Editor'
|
|
227 |
#accessCharacterPosition: 1 )
|
|
228 |
#(#MenuItem #label: 'Menu Editor'
|
|
229 |
#accessCharacterPosition: 1 )
|
|
230 |
#(#MenuItem #label: 'Advanced'
|
|
231 |
#accessCharacterPosition: 1 )
|
|
232 |
#(#MenuItem #label: 'DLL and C Connect'
|
|
233 |
#accessCharacterPosition: 1 )
|
|
234 |
#(#MenuItem #label: 'System Transcript'
|
|
235 |
#accessCharacterPosition: 8 )
|
|
236 |
)
|
|
237 |
#(4 5 2 1 )
|
|
238 |
#(#openFileList #openFileEditor #openRefactoringTool #toolsNewWorkspace #toolsNewCanvas #toolsPalette #toolsCanvasTool #toolsMaskEditor #toolsMenuEditor nil #openExternalFinder #toggleSystemTranscript )
|
456
|
239 |
) decodeAsLiteralArray startUp
|
454
|
240 |
"
|
|
241 |
|
457
|
242 |
"submenus:
|
|
243 |
#(#Menu #(
|
|
244 |
#(#MenuItem
|
|
245 |
#label: 'Foo'
|
|
246 |
#submenu: #(#Menu #(
|
|
247 |
#(#MenuItem #label: 'foo 1')
|
|
248 |
#(#MenuItem #label: 'foo 2')
|
|
249 |
)
|
|
250 |
nil
|
|
251 |
#(11 22)
|
|
252 |
)
|
|
253 |
)
|
|
254 |
#(#MenuItem
|
|
255 |
#label: 'Inspect' )
|
|
256 |
#(#MenuItem
|
|
257 |
#label: 'Coredump' )
|
|
258 |
)
|
|
259 |
#(3 )
|
|
260 |
#(1 2 3 )
|
|
261 |
) decodeAsLiteralArray startUp
|
|
262 |
"
|
|
263 |
|
|
264 |
"Modified: 25.2.1997 / 21:05:06 / cg"
|
489
|
265 |
!
|
|
266 |
|
|
267 |
literalArrayEncoding
|
|
268 |
"return myself encoded as a literal array"
|
|
269 |
|
|
270 |
|coll|
|
|
271 |
|
|
272 |
coll := OrderedCollection new.
|
|
273 |
coll add:#Menu.
|
|
274 |
coll add:(items literalArrayEncoding).
|
|
275 |
coll add:(groupSizes literalArrayEncoding).
|
|
276 |
coll add:nil.
|
579
|
277 |
^ coll asArray
|
451
|
278 |
! !
|
|
279 |
|
|
280 |
!Menu methodsFor:'startup'!
|
|
281 |
|
|
282 |
startUp
|
|
283 |
"display the menu as a popUp; return the value associated with the
|
|
284 |
selected item, 0 if none was selected"
|
|
285 |
|
579
|
286 |
|menu|
|
457
|
287 |
|
579
|
288 |
menu := MenuPanel menu:self.
|
|
289 |
^ menu startUp
|
451
|
290 |
|
579
|
291 |
"
|
451
|
292 |
|m|
|
579
|
293 |
|
451
|
294 |
m := #(#Menu #(
|
|
295 |
#(#MenuItem
|
|
296 |
#rawLabel: 'left'
|
|
297 |
#value: #left )
|
|
298 |
#(#MenuItem
|
|
299 |
#rawLabel: 'center'
|
|
300 |
#value: #center )
|
|
301 |
#(#MenuItem
|
|
302 |
#rawLabel: 'right'
|
|
303 |
#value: #right ) )
|
579
|
304 |
#(2)
|
451
|
305 |
nil
|
|
306 |
) decodeAsLiteralArray.
|
|
307 |
|
579
|
308 |
Transcript showCR:(m startUp)
|
|
309 |
"
|
451
|
310 |
! !
|
|
311 |
|
|
312 |
!Menu class methodsFor:'documentation'!
|
|
313 |
|
|
314 |
version
|
582
|
315 |
^ '$Header: /cvs/stx/stx/libview2/Menu.st,v 1.10 1997-05-23 14:04:26 ca Exp $'
|
451
|
316 |
! !
|