451
|
1 |
Object subclass:#Menu
|
|
2 |
instanceVariableNames:'items'
|
|
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 |
|
|
37 |
menuItems:aCollectionOfMenuItems groups:groups values:values
|
|
38 |
items := aCollectionOfMenuItems.
|
|
39 |
values notNil ifTrue:[
|
|
40 |
items with:values do:[:anItem :aValue |
|
|
41 |
anItem value:aValue
|
|
42 |
]
|
|
43 |
]
|
|
44 |
|
|
45 |
"Modified: 25.2.1997 / 19:36:28 / cg"
|
|
46 |
!
|
|
47 |
|
|
48 |
valueAt:index
|
|
49 |
"return a collection of values from my items"
|
|
50 |
|
|
51 |
^ (items at:index) value
|
|
52 |
|
|
53 |
"Created: 25.2.1997 / 19:49:41 / cg"
|
|
54 |
!
|
|
55 |
|
|
56 |
values
|
|
57 |
"return a collection of values from my items"
|
|
58 |
|
|
59 |
^ items collect:[:anItem | anItem value]
|
|
60 |
|
|
61 |
"Created: 25.2.1997 / 19:49:29 / cg"
|
|
62 |
! !
|
|
63 |
|
|
64 |
!Menu methodsFor:'converting'!
|
|
65 |
|
|
66 |
fromLiteralArrayEncoding:aLiteralEncodedArray
|
|
67 |
"read my contents from a aLiteralEncodedArray"
|
|
68 |
|
|
69 |
|items groups values|
|
|
70 |
|
|
71 |
items := (aLiteralEncodedArray at:2) collect:[:item | item decodeAsLiteralArray].
|
|
72 |
groups := aLiteralEncodedArray at:3.
|
452
|
73 |
values := aLiteralEncodedArray at:4.
|
451
|
74 |
self menuItems:items groups:groups values:values.
|
|
75 |
|
|
76 |
"extract from PD folder.st:
|
|
77 |
#(#Menu #(
|
|
78 |
#(#MenuItem
|
|
79 |
#rawLabel: 'left'
|
|
80 |
#value: #left )
|
|
81 |
#(#MenuItem
|
|
82 |
#rawLabel: 'center'
|
|
83 |
#value: #center )
|
|
84 |
#(#MenuItem
|
|
85 |
#rawLabel: 'right'
|
|
86 |
#value: #right )
|
|
87 |
)
|
|
88 |
#(3 )
|
|
89 |
nil
|
|
90 |
) decodeAsLiteralArray
|
|
91 |
"
|
452
|
92 |
"
|
|
93 |
#(#Menu #(
|
|
94 |
#(#MenuItem
|
|
95 |
#label: 'Straighten Up' )
|
|
96 |
#(#MenuItem
|
|
97 |
#label: 'Inspect' )
|
|
98 |
#(#MenuItem
|
|
99 |
#label: 'Coredump' )
|
|
100 |
)
|
|
101 |
#(3 )
|
|
102 |
#(#straightenUp #inspect #halt )
|
|
103 |
) decodeAsLiteralArray startUp
|
|
104 |
"
|
|
105 |
"
|
|
106 |
#(#Menu #(
|
|
107 |
#(#MenuItem
|
|
108 |
#label: 'Straighten Up' )
|
|
109 |
#(#MenuItem
|
|
110 |
#label: 'Inspect' )
|
|
111 |
#(#MenuItem
|
|
112 |
#label: 'Coredump' )
|
|
113 |
)
|
|
114 |
#(3 )
|
|
115 |
#(1 2 3 )
|
|
116 |
) decodeAsLiteralArray startUp
|
|
117 |
"
|
451
|
118 |
|
452
|
119 |
"Modified: 25.2.1997 / 20:00:18 / cg"
|
451
|
120 |
! !
|
|
121 |
|
|
122 |
!Menu methodsFor:'startup'!
|
|
123 |
|
|
124 |
startUp
|
|
125 |
"display the menu as a popUp; return the value associated with the
|
|
126 |
selected item, 0 if none was selected"
|
|
127 |
|
452
|
128 |
|m val index|
|
451
|
129 |
|
|
130 |
"/ for now, use PopUpMenu ....
|
|
131 |
|
|
132 |
m := PopUpMenu labels:self labels.
|
|
133 |
index := m startUp.
|
|
134 |
index ~~ 0 ifTrue:[
|
452
|
135 |
val := self valueAt:index.
|
|
136 |
val notNil ifTrue:[
|
|
137 |
^ val
|
|
138 |
]
|
451
|
139 |
].
|
|
140 |
^ 0
|
|
141 |
|
|
142 |
"
|
|
143 |
|m|
|
|
144 |
m := #(#Menu #(
|
|
145 |
#(#MenuItem
|
|
146 |
#rawLabel: 'left'
|
|
147 |
#value: #left )
|
|
148 |
#(#MenuItem
|
|
149 |
#rawLabel: 'center'
|
|
150 |
#value: #center )
|
|
151 |
#(#MenuItem
|
|
152 |
#rawLabel: 'right'
|
|
153 |
#value: #right ) )
|
|
154 |
#(3 )
|
|
155 |
nil
|
|
156 |
) decodeAsLiteralArray.
|
|
157 |
m startUp
|
|
158 |
"
|
|
159 |
|
452
|
160 |
"Modified: 25.2.1997 / 19:59:35 / cg"
|
451
|
161 |
! !
|
|
162 |
|
|
163 |
!Menu class methodsFor:'documentation'!
|
|
164 |
|
|
165 |
version
|
452
|
166 |
^ '$Header: /cvs/stx/stx/libview2/Menu.st,v 1.2 1997-02-25 19:21:47 cg Exp $'
|
451
|
167 |
! !
|