0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
59
|
3 |
All Rights Reserved
|
0
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
EnterBox subclass:#ListSelectionBox
|
|
14 |
instanceVariableNames:'selectionList'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
38
|
17 |
category:'Views-DialogBoxes'
|
0
|
18 |
!
|
|
19 |
|
|
20 |
ListSelectionBox comment:'
|
5
|
21 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
59
|
22 |
All Rights Reserved
|
0
|
23 |
|
155
|
24 |
$Header: /cvs/stx/stx/libwidg/ListSelectionBox.st,v 1.17 1995-09-07 12:45:09 claus Exp $
|
38
|
25 |
'!
|
|
26 |
|
|
27 |
!ListSelectionBox class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
59
|
32 |
All Rights Reserved
|
38
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
0
|
42 |
|
38
|
43 |
version
|
|
44 |
"
|
155
|
45 |
$Header: /cvs/stx/stx/libwidg/ListSelectionBox.st,v 1.17 1995-09-07 12:45:09 claus Exp $
|
38
|
46 |
"
|
|
47 |
!
|
0
|
48 |
|
38
|
49 |
documentation
|
|
50 |
"
|
|
51 |
this class implements boxes for selection from a list. It offers
|
|
52 |
both an ok- and abort-buttons. The ok-button, if pressed will
|
|
53 |
evaluate the okAction (see EnterBox>>action).
|
77
|
54 |
see examples for typical uses.
|
|
55 |
|
|
56 |
Notice, for file selections there is a specialized FileSelectionBox,
|
|
57 |
which supports matchPatterns, changing directory etc.
|
|
58 |
"
|
|
59 |
!
|
|
60 |
|
|
61 |
examples
|
|
62 |
"
|
|
63 |
simple:
|
38
|
64 |
|
59
|
65 |
|box|
|
38
|
66 |
|
59
|
67 |
box := ListSelectionBox new.
|
|
68 |
box title:'select something:'.
|
|
69 |
box list:#('foo' 'bar' 'baz').
|
|
70 |
box okAction:[:sel | Transcript showCr:'the selection was:' , sel].
|
|
71 |
box showAtPointer
|
77
|
72 |
|
155
|
73 |
|
77
|
74 |
with a default:
|
|
75 |
|
|
76 |
|box|
|
|
77 |
|
|
78 |
box := ListSelectionBox new.
|
|
79 |
box title:'select something:'.
|
|
80 |
box list:#('foo' 'bar' 'baz').
|
|
81 |
box okAction:[:sel | Transcript showCr:'the selection was:' , sel].
|
|
82 |
box initialText:'foo'.
|
|
83 |
box showAtPointer
|
155
|
84 |
|
|
85 |
|
|
86 |
opening the box modeless (a stand-by box):
|
|
87 |
(in this case, the default ok- and abortActions do not hide the box;
|
|
88 |
therefore, we have to set those explicitely)
|
|
89 |
|
|
90 |
|box|
|
|
91 |
|
|
92 |
box := ListSelectionBox new.
|
|
93 |
box title:'select something:'.
|
|
94 |
box list:#('foo' 'bar' 'baz').
|
|
95 |
box abortText:'close'.
|
|
96 |
box okText:'apply'.
|
|
97 |
box okAction:[:sel | Transcript showCr:'the selection was:' , sel].
|
|
98 |
box abortAction:[:dummy | box hide].
|
|
99 |
box openModeless
|
38
|
100 |
"
|
|
101 |
! !
|
0
|
102 |
|
|
103 |
!ListSelectionBox class methodsFor:'defaults'!
|
|
104 |
|
|
105 |
defaultExtent
|
|
106 |
^ (Display pixelPerMillimeter * (80 @ 100)) rounded
|
12
|
107 |
!
|
|
108 |
|
|
109 |
listViewType
|
|
110 |
"return the type of listView
|
|
111 |
- for easier redefinition in subclasses"
|
|
112 |
|
|
113 |
^ SelectionInListView
|
0
|
114 |
! !
|
|
115 |
|
|
116 |
!ListSelectionBox class methodsFor:'instance creation'!
|
|
117 |
|
|
118 |
title:titleString okText:okText abortText:abortText list:aList action:aBlock
|
|
119 |
"create and return a new listSelectionBox with list already defined"
|
|
120 |
|
|
121 |
|newBox|
|
|
122 |
|
|
123 |
newBox := super title:titleString okText:okText abortText:abortText
|
59
|
124 |
action:aBlock.
|
0
|
125 |
^ newBox list:aList
|
|
126 |
! !
|
|
127 |
|
|
128 |
!ListSelectionBox methodsFor:'initialization'!
|
|
129 |
|
|
130 |
initialize
|
139
|
131 |
|space2 halfSpace v vbw|
|
0
|
132 |
|
|
133 |
super initialize.
|
|
134 |
|
77
|
135 |
label := 'Select or enter'.
|
|
136 |
|
0
|
137 |
"need more space than an enterBox"
|
|
138 |
|
|
139 |
"self height:(height + (font height * 5)). "
|
|
140 |
|
|
141 |
space2 := 2 * ViewSpacing.
|
125
|
142 |
halfSpace := ViewSpacing // 2.
|
0
|
143 |
|
12
|
144 |
v := ScrollableView for:(self class listViewType) in:self.
|
0
|
145 |
|
132
|
146 |
"/ old:
|
|
147 |
"/ v origin:[0.0
|
125
|
148 |
"/ @
|
132
|
149 |
"/ (enterField origin y + enterField height + ViewSpacing)]
|
|
150 |
"/ extent:[1.0
|
125
|
151 |
"/ @
|
132
|
152 |
"/ (height
|
125
|
153 |
"/ - ViewSpacing - labelField heightIncludingBorder
|
|
154 |
"/ - ViewSpacing - enterField heightIncludingBorder
|
|
155 |
"/ - buttonPanel heightIncludingBorder - ViewSpacing
|
|
156 |
"/ - space2)
|
132
|
157 |
"/ ].
|
|
158 |
|
|
159 |
"/ new:
|
|
160 |
v origin:[0.0 @ (enterField origin y + enterField height + ViewSpacing)]
|
|
161 |
corner:(1.0 @ 1.0).
|
|
162 |
v bottomInset:(buttonPanel preferredExtent y + ViewSpacing).
|
|
163 |
|
139
|
164 |
vbw := v borderWidth.
|
|
165 |
v leftInset:halfSpace+vbw;
|
|
166 |
rightInset:halfSpace+vbw.
|
110
|
167 |
|
0
|
168 |
selectionList := v scrolledView.
|
|
169 |
|
|
170 |
"self updateList."
|
|
171 |
|
132
|
172 |
"I am interested in what is done int the selectionList
|
|
173 |
(could also create a SelectionInList-model and catch its changes ...)"
|
|
174 |
selectionList action:[:lineNr | self selectionChanged].
|
|
175 |
selectionList doubleClickAction:[:lineNr | self doubleClick].
|
|
176 |
|
130
|
177 |
enterField removeDependent:self. "dont want preferredExtent-changes"
|
128
|
178 |
|
38
|
179 |
"
|
|
180 |
mhm: the lists keyboard functions are disabled,
|
|
181 |
and input passed to the enterfield
|
|
182 |
"
|
122
|
183 |
selectionList delegate:(KeyboardForwarder toView:enterField condition:#noFocus)
|
0
|
184 |
!
|
|
185 |
|
|
186 |
updateList
|
|
187 |
"setup contents of list; nothing done here but redefined in subclasses"
|
|
188 |
|
|
189 |
^ self
|
|
190 |
!
|
|
191 |
|
|
192 |
realize
|
|
193 |
self updateList.
|
|
194 |
super realize
|
77
|
195 |
!
|
|
196 |
|
|
197 |
focusSequence
|
118
|
198 |
^ Array with:enterField with:selectionList with:abortButton with:okButton
|
0
|
199 |
! !
|
|
200 |
|
59
|
201 |
!ListSelectionBox methodsFor:'queries'!
|
0
|
202 |
|
130
|
203 |
preferredExtent
|
|
204 |
"return my preferred extent - thats the minimum size
|
125
|
205 |
I like to have, to make everything visible"
|
0
|
206 |
|
|
207 |
|wWanted hWanted|
|
|
208 |
|
125
|
209 |
|
0
|
210 |
wWanted := labelField width + ViewSpacing + ViewSpacing.
|
|
211 |
(wWanted > width) ifFalse:[
|
59
|
212 |
wWanted := width
|
0
|
213 |
].
|
125
|
214 |
|
0
|
215 |
hWanted := ViewSpacing + labelField height +
|
59
|
216 |
ViewSpacing + enterField height +
|
|
217 |
ViewSpacing + selectionList height +
|
130
|
218 |
ViewSpacing + buttonPanel preferredExtent y +
|
125
|
219 |
ViewSpacing - (ViewSpacing * 2).
|
0
|
220 |
|
|
221 |
(hWanted < height) ifTrue:[
|
59
|
222 |
hWanted := height
|
0
|
223 |
].
|
59
|
224 |
^ (wWanted @ hWanted)
|
0
|
225 |
! !
|
|
226 |
|
132
|
227 |
!ListSelectionBox methodsFor:'user actions'!
|
|
228 |
|
|
229 |
selectionChanged
|
|
230 |
"selections in list get forwarded to enterfield"
|
|
231 |
|
|
232 |
enterField contents:(selectionList selectionValue)
|
|
233 |
!
|
|
234 |
|
|
235 |
doubleClick
|
|
236 |
"doubleClick on an entry is select & ok"
|
|
237 |
|
|
238 |
enterField contents:(selectionList selectionValue).
|
|
239 |
self okPressed
|
|
240 |
! !
|
|
241 |
|
0
|
242 |
!ListSelectionBox methodsFor:'accessing'!
|
|
243 |
|
128
|
244 |
initialText:someString
|
|
245 |
"in addition to showing the initial text, also select it in the list"
|
|
246 |
|
|
247 |
super initialText:someString.
|
|
248 |
selectionList selectElement:someString.
|
|
249 |
!
|
|
250 |
|
0
|
251 |
list:aList
|
|
252 |
"set the list to be displayed in selection list"
|
|
253 |
|
|
254 |
selectionList list:aList
|
|
255 |
! !
|