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 |
|
|
29 |
labels
|
|
30 |
"return a collection of labels from my items"
|
|
31 |
|
|
32 |
^ items collect:[:anItem | anItem label]
|
|
33 |
|
|
34 |
"Created: 25.2.1997 / 19:47:53 / cg"
|
|
35 |
!
|
|
36 |
|
454
|
37 |
menuItems:aCollectionOfMenuItems groupsSizes:sizes values:values
|
456
|
38 |
|idx newItems nItems|
|
454
|
39 |
|
451
|
40 |
items := aCollectionOfMenuItems.
|
|
41 |
values notNil ifTrue:[
|
|
42 |
items with:values do:[:anItem :aValue |
|
|
43 |
anItem value:aValue
|
|
44 |
]
|
454
|
45 |
].
|
|
46 |
|
|
47 |
"/ add empty items for group-separating lines.
|
451
|
48 |
|
454
|
49 |
groupSizes := sizes.
|
|
50 |
groupSizes notNil ifTrue:[
|
|
51 |
idx := 1.
|
456
|
52 |
nItems := items size.
|
|
53 |
newItems := OrderedCollection new:(nItems + groupSizes size).
|
454
|
54 |
groupSizes do:[:aGroupSize |
|
|
55 |
items from:idx to:idx+aGroupSize-1 do:[:l | newItems add:l].
|
456
|
56 |
idx := idx + aGroupSize.
|
|
57 |
idx < nItems ifTrue:[
|
|
58 |
newItems add:(MenuItem new label:'-').
|
|
59 |
]
|
454
|
60 |
].
|
456
|
61 |
items from:idx to:nItems do:[:l | newItems add:l].
|
454
|
62 |
items := newItems.
|
|
63 |
].
|
|
64 |
|
|
65 |
"Created: 25.2.1997 / 20:28:12 / cg"
|
456
|
66 |
"Modified: 25.2.1997 / 20:44:54 / cg"
|
451
|
67 |
!
|
|
68 |
|
|
69 |
valueAt:index
|
|
70 |
"return a collection of values from my items"
|
|
71 |
|
|
72 |
^ (items at:index) value
|
|
73 |
|
|
74 |
"Created: 25.2.1997 / 19:49:41 / cg"
|
|
75 |
!
|
|
76 |
|
|
77 |
values
|
|
78 |
"return a collection of values from my items"
|
|
79 |
|
|
80 |
^ items collect:[:anItem | anItem value]
|
|
81 |
|
|
82 |
"Created: 25.2.1997 / 19:49:29 / cg"
|
|
83 |
! !
|
|
84 |
|
|
85 |
!Menu methodsFor:'converting'!
|
|
86 |
|
|
87 |
fromLiteralArrayEncoding:aLiteralEncodedArray
|
|
88 |
"read my contents from a aLiteralEncodedArray"
|
|
89 |
|
|
90 |
|items groups values|
|
|
91 |
|
|
92 |
items := (aLiteralEncodedArray at:2) collect:[:item | item decodeAsLiteralArray].
|
|
93 |
groups := aLiteralEncodedArray at:3.
|
452
|
94 |
values := aLiteralEncodedArray at:4.
|
454
|
95 |
self menuItems:items groupsSizes:groups values:values.
|
451
|
96 |
|
|
97 |
"extract from PD folder.st:
|
|
98 |
#(#Menu #(
|
|
99 |
#(#MenuItem
|
|
100 |
#rawLabel: 'left'
|
|
101 |
#value: #left )
|
|
102 |
#(#MenuItem
|
|
103 |
#rawLabel: 'center'
|
|
104 |
#value: #center )
|
|
105 |
#(#MenuItem
|
|
106 |
#rawLabel: 'right'
|
|
107 |
#value: #right )
|
|
108 |
)
|
|
109 |
#(3 )
|
|
110 |
nil
|
|
111 |
) decodeAsLiteralArray
|
|
112 |
"
|
452
|
113 |
"
|
|
114 |
#(#Menu #(
|
|
115 |
#(#MenuItem
|
|
116 |
#label: 'Straighten Up' )
|
|
117 |
#(#MenuItem
|
|
118 |
#label: 'Inspect' )
|
|
119 |
#(#MenuItem
|
|
120 |
#label: 'Coredump' )
|
|
121 |
)
|
|
122 |
#(3 )
|
|
123 |
#(#straightenUp #inspect #halt )
|
|
124 |
) decodeAsLiteralArray startUp
|
|
125 |
"
|
454
|
126 |
"extract from iconicBrowser.st:
|
452
|
127 |
#(#Menu #(
|
|
128 |
#(#MenuItem
|
|
129 |
#label: 'Straighten Up' )
|
|
130 |
#(#MenuItem
|
|
131 |
#label: 'Inspect' )
|
|
132 |
#(#MenuItem
|
|
133 |
#label: 'Coredump' )
|
|
134 |
)
|
|
135 |
#(3 )
|
|
136 |
#(1 2 3 )
|
|
137 |
) decodeAsLiteralArray startUp
|
|
138 |
"
|
451
|
139 |
|
454
|
140 |
"extract from refactory213.st:
|
|
141 |
#(#Menu #(
|
|
142 |
#(#MenuItem
|
|
143 |
#label: 'File List'
|
|
144 |
#accessCharacterPosition: 1 )
|
|
145 |
#(#MenuItem #label: 'File Editor...'
|
|
146 |
#accessCharacterPosition: 6 )
|
|
147 |
#(#MenuItem #label: 'Refactoring Tool...'
|
|
148 |
#accessCharacterPosition: 1 )
|
|
149 |
#(#MenuItem #label: 'Workspace'
|
|
150 |
#accessCharacterPosition: 1 )
|
|
151 |
#(#MenuItem #label: 'New Canvas'
|
|
152 |
#accessCharacterPosition: 1 )
|
|
153 |
#(#MenuItem #label: 'Palette'
|
|
154 |
#accessCharacterPosition: 1 )
|
|
155 |
#(#MenuItem #label: 'Canvas Tool'
|
|
156 |
#accessCharacterPosition: 1 )
|
|
157 |
#(#MenuItem #label: 'Image Editor'
|
|
158 |
#accessCharacterPosition: 1 )
|
|
159 |
#(#MenuItem #label: 'Menu Editor'
|
|
160 |
#accessCharacterPosition: 1 )
|
|
161 |
#(#MenuItem #label: 'Advanced'
|
|
162 |
#accessCharacterPosition: 1 )
|
|
163 |
#(#MenuItem #label: 'DLL and C Connect'
|
|
164 |
#accessCharacterPosition: 1 )
|
|
165 |
#(#MenuItem #label: 'System Transcript'
|
|
166 |
#accessCharacterPosition: 8 )
|
|
167 |
)
|
|
168 |
#(4 5 2 1 )
|
|
169 |
#(#openFileList #openFileEditor #openRefactoringTool #toolsNewWorkspace #toolsNewCanvas #toolsPalette #toolsCanvasTool #toolsMaskEditor #toolsMenuEditor nil #openExternalFinder #toggleSystemTranscript )
|
456
|
170 |
) decodeAsLiteralArray startUp
|
454
|
171 |
"
|
|
172 |
|
456
|
173 |
"Modified: 25.2.1997 / 20:43:22 / cg"
|
451
|
174 |
! !
|
|
175 |
|
|
176 |
!Menu methodsFor:'startup'!
|
|
177 |
|
|
178 |
startUp
|
|
179 |
"display the menu as a popUp; return the value associated with the
|
|
180 |
selected item, 0 if none was selected"
|
|
181 |
|
454
|
182 |
|menuView val index labels |
|
451
|
183 |
|
|
184 |
"/ for now, use PopUpMenu ....
|
|
185 |
|
454
|
186 |
labels := self labels.
|
|
187 |
|
|
188 |
menuView := PopUpMenu labels:labels.
|
|
189 |
index := menuView startUp.
|
|
190 |
menuView destroy.
|
|
191 |
(index notNil and:[index ~~ 0]) ifTrue:[
|
452
|
192 |
val := self valueAt:index.
|
|
193 |
val notNil ifTrue:[
|
|
194 |
^ val
|
|
195 |
]
|
451
|
196 |
].
|
|
197 |
^ 0
|
|
198 |
|
|
199 |
"
|
|
200 |
|m|
|
|
201 |
m := #(#Menu #(
|
|
202 |
#(#MenuItem
|
|
203 |
#rawLabel: 'left'
|
|
204 |
#value: #left )
|
|
205 |
#(#MenuItem
|
|
206 |
#rawLabel: 'center'
|
|
207 |
#value: #center )
|
|
208 |
#(#MenuItem
|
|
209 |
#rawLabel: 'right'
|
|
210 |
#value: #right ) )
|
454
|
211 |
#(1 1 )
|
451
|
212 |
nil
|
|
213 |
) decodeAsLiteralArray.
|
|
214 |
m startUp
|
|
215 |
"
|
|
216 |
|
454
|
217 |
"Modified: 25.2.1997 / 20:42:29 / cg"
|
451
|
218 |
! !
|
|
219 |
|
|
220 |
!Menu class methodsFor:'documentation'!
|
|
221 |
|
|
222 |
version
|
456
|
223 |
^ '$Header: /cvs/stx/stx/libview2/Menu.st,v 1.4 1997-02-25 19:45:18 cg Exp $'
|
451
|
224 |
! !
|