author | Claus Gittinger <cg@exept.de> |
Sat, 27 Apr 1996 20:21:37 +0200 | |
changeset 593 | 86dd024ed773 |
parent 585 | 8f395aba0173 |
child 638 | 72c3d36df4d8 |
permissions | -rw-r--r-- |
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 |
|
371 | 14 |
instanceVariableNames:'selectionList' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Views-DialogBoxes' |
|
0 | 18 |
! |
19 |
||
38 | 20 |
!ListSelectionBox class methodsFor:'documentation'! |
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1990 by Claus Gittinger |
|
59 | 25 |
All Rights Reserved |
38 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
0 | 35 |
|
38 | 36 |
documentation |
37 |
" |
|
38 |
this class implements boxes for selection from a list. It offers |
|
39 |
both an ok- and abort-buttons. The ok-button, if pressed will |
|
40 |
evaluate the okAction (see EnterBox>>action). |
|
77 | 41 |
see examples for typical uses. |
42 |
||
43 |
Notice, for file selections there is a specialized FileSelectionBox, |
|
44 |
which supports matchPatterns, changing directory etc. |
|
585 | 45 |
|
46 |
[author:] |
|
47 |
Claus Gittinger |
|
77 | 48 |
" |
49 |
! |
|
50 |
||
51 |
examples |
|
52 |
" |
|
53 |
simple: |
|
593 | 54 |
[exBegin] |
55 |
|box| |
|
38 | 56 |
|
593 | 57 |
box := ListSelectionBox new. |
58 |
box title:'select something:'. |
|
59 |
box list:#('foo' 'bar' 'baz'). |
|
60 |
box okAction:[:sel | Transcript showCr:'the selection was:' , sel]. |
|
61 |
box showAtPointer |
|
62 |
[exEnd] |
|
77 | 63 |
|
155 | 64 |
|
77 | 65 |
with a default: |
593 | 66 |
[exBegin] |
67 |
|box| |
|
77 | 68 |
|
593 | 69 |
box := ListSelectionBox new. |
70 |
box title:'select something:'. |
|
71 |
box list:#('foo' 'bar' 'baz'). |
|
72 |
box okAction:[:sel | Transcript showCr:'the selection was:' , sel]. |
|
73 |
box initialText:'foo'. |
|
74 |
box showAtPointer |
|
75 |
[exEnd] |
|
155 | 76 |
|
77 |
||
78 |
opening the box modeless (a stand-by box): |
|
79 |
(in this case, the default ok- and abortActions do not hide the box; |
|
80 |
therefore, we have to set those explicitely) |
|
593 | 81 |
[exBegin] |
82 |
|box| |
|
155 | 83 |
|
593 | 84 |
box := ListSelectionBox new. |
85 |
box title:'select something:'. |
|
86 |
box list:#('foo' 'bar' 'baz'). |
|
87 |
box abortText:'close'. |
|
88 |
box okText:'apply'. |
|
89 |
box okAction:[:sel | Transcript showCr:'the selection was:' , sel]. |
|
90 |
box abortAction:[:dummy | box hide]. |
|
91 |
box openModeless |
|
92 |
[exEnd] |
|
38 | 93 |
" |
197 | 94 |
! ! |
95 |
||
96 |
!ListSelectionBox class methodsFor:'instance creation'! |
|
97 |
||
98 |
title:titleString okText:okText abortText:abortText list:aList action:aBlock |
|
99 |
"create and return a new listSelectionBox with list already defined" |
|
100 |
||
101 |
|newBox| |
|
102 |
||
103 |
newBox := super title:titleString okText:okText abortText:abortText |
|
104 |
action:aBlock. |
|
105 |
^ newBox list:aList |
|
38 | 106 |
! ! |
0 | 107 |
|
108 |
!ListSelectionBox class methodsFor:'defaults'! |
|
109 |
||
110 |
defaultExtent |
|
571 | 111 |
"return the default extent of my instances. |
112 |
The value returned here is usually ignored, and |
|
113 |
the value from preferredExtent taken instead." |
|
114 |
||
0 | 115 |
^ (Display pixelPerMillimeter * (80 @ 100)) rounded |
571 | 116 |
|
117 |
"Modified: 22.4.1996 / 23:36:49 / cg" |
|
12 | 118 |
! |
119 |
||
120 |
listViewType |
|
121 |
"return the type of listView |
|
122 |
- for easier redefinition in subclasses" |
|
123 |
||
124 |
^ SelectionInListView |
|
0 | 125 |
! ! |
126 |
||
197 | 127 |
!ListSelectionBox methodsFor:'accessing'! |
128 |
||
402
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
129 |
contents |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
130 |
"return my contents" |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
131 |
|
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
132 |
enterField isNil ifTrue:[ |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
133 |
^ selectionList selectionValue |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
134 |
]. |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
135 |
^ super contents |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
136 |
|
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
137 |
"Created: 26.2.1996 / 20:05:47 / cg" |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
138 |
! |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
139 |
|
197 | 140 |
initialText:someString |
141 |
"in addition to showing the initial text, also select it in the list" |
|
0 | 142 |
|
197 | 143 |
super initialText:someString. |
144 |
selectionList selectElement:someString. |
|
145 |
! |
|
146 |
||
147 |
list:aList |
|
148 |
"set the list to be displayed in selection list" |
|
149 |
||
150 |
selectionList list:aList |
|
151 |
! ! |
|
0 | 152 |
|
197 | 153 |
!ListSelectionBox methodsFor:'accessing-components'! |
154 |
||
155 |
listView |
|
156 |
"return the listView component" |
|
157 |
||
158 |
^ selectionList |
|
0 | 159 |
|
197 | 160 |
"Created: 26.10.1995 / 17:08:32 / cg" |
161 |
! ! |
|
162 |
||
163 |
!ListSelectionBox methodsFor:'accessing-look'! |
|
164 |
||
165 |
noEnterField |
|
166 |
enterField destroy. |
|
167 |
enterField := nil |
|
168 |
||
169 |
"Created: 26.10.1995 / 17:12:38 / cg" |
|
0 | 170 |
! ! |
171 |
||
172 |
!ListSelectionBox methodsFor:'initialization'! |
|
173 |
||
197 | 174 |
focusSequence |
175 |
^ Array with:enterField with:selectionList with:abortButton with:okButton |
|
176 |
! |
|
177 |
||
0 | 178 |
initialize |
166 | 179 |
|space2 halfSpace v vbw eH| |
0 | 180 |
|
181 |
super initialize. |
|
182 |
||
412 | 183 |
label := resources string:'Select or enter'. |
77 | 184 |
|
0 | 185 |
"need more space than an enterBox" |
186 |
||
187 |
"self height:(height + (font height * 5)). " |
|
188 |
||
189 |
space2 := 2 * ViewSpacing. |
|
125 | 190 |
halfSpace := ViewSpacing // 2. |
0 | 191 |
|
12 | 192 |
v := ScrollableView for:(self class listViewType) in:self. |
0 | 193 |
|
132 | 194 |
"/ old: |
195 |
"/ v origin:[0.0 |
|
125 | 196 |
"/ @ |
132 | 197 |
"/ (enterField origin y + enterField height + ViewSpacing)] |
198 |
"/ extent:[1.0 |
|
125 | 199 |
"/ @ |
132 | 200 |
"/ (height |
125 | 201 |
"/ - ViewSpacing - labelField heightIncludingBorder |
202 |
"/ - ViewSpacing - enterField heightIncludingBorder |
|
203 |
"/ - buttonPanel heightIncludingBorder - ViewSpacing |
|
204 |
"/ - space2) |
|
132 | 205 |
"/ ]. |
206 |
||
207 |
"/ new: |
|
166 | 208 |
v origin:[enterField notNil ifTrue:[ |
412 | 209 |
0.0 @ (enterField origin y + enterField height + ViewSpacing) |
210 |
] ifFalse:[ |
|
211 |
0.0 @ (labelField origin y + labelField height + ViewSpacing) |
|
212 |
] |
|
213 |
] |
|
132 | 214 |
corner:(1.0 @ 1.0). |
215 |
v bottomInset:(buttonPanel preferredExtent y + ViewSpacing). |
|
216 |
||
139 | 217 |
vbw := v borderWidth. |
218 |
v leftInset:halfSpace+vbw; |
|
219 |
rightInset:halfSpace+vbw. |
|
110 | 220 |
|
0 | 221 |
selectionList := v scrolledView. |
222 |
||
223 |
"self updateList." |
|
224 |
||
132 | 225 |
"I am interested in what is done int the selectionList |
226 |
(could also create a SelectionInList-model and catch its changes ...)" |
|
227 |
selectionList action:[:lineNr | self selectionChanged]. |
|
228 |
selectionList doubleClickAction:[:lineNr | self doubleClick]. |
|
229 |
||
130 | 230 |
enterField removeDependent:self. "dont want preferredExtent-changes" |
128 | 231 |
|
38 | 232 |
" |
233 |
mhm: the lists keyboard functions are disabled, |
|
319
d78f5fbdee27
dont forward Cursor-motion to the enterField
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
234 |
and input passed to the enterfield (except cursor keys) |
38 | 235 |
" |
319
d78f5fbdee27
dont forward Cursor-motion to the enterField
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
236 |
selectionList delegate:( |
412 | 237 |
KeyboardForwarder |
238 |
toView:enterField |
|
239 |
condition:#noFocus |
|
240 |
filter:[:key | (key ~~ #CursorUp) and:[key ~~ #CursorDown]] |
|
241 |
) |
|
166 | 242 |
|
412 | 243 |
"Modified: 27.2.1996 / 01:11:41 / cg" |
0 | 244 |
! |
245 |
||
246 |
realize |
|
247 |
self updateList. |
|
248 |
super realize |
|
77 | 249 |
! |
250 |
||
197 | 251 |
updateList |
252 |
"setup contents of list; nothing done here but redefined in subclasses" |
|
253 |
||
254 |
^ self |
|
0 | 255 |
! ! |
256 |
||
59 | 257 |
!ListSelectionBox methodsFor:'queries'! |
0 | 258 |
|
130 | 259 |
preferredExtent |
260 |
"return my preferred extent - thats the minimum size |
|
125 | 261 |
I like to have, to make everything visible" |
0 | 262 |
|
371 | 263 |
|wWanted hWanted eH mm| |
264 |
||
265 |
mm := ViewSpacing. |
|
125 | 266 |
|
371 | 267 |
wWanted := mm + labelField width + mm. |
0 | 268 |
(wWanted > width) ifFalse:[ |
371 | 269 |
wWanted := width |
0 | 270 |
]. |
125 | 271 |
|
166 | 272 |
enterField notNil ifTrue:[ |
371 | 273 |
eH := enterField height + mm |
166 | 274 |
] ifFalse:[ |
371 | 275 |
eH := 0 |
166 | 276 |
]. |
371 | 277 |
hWanted := mm + labelField height + |
278 |
eH + |
|
279 |
mm + selectionList height + |
|
280 |
mm + buttonPanel preferredExtent y + |
|
281 |
mm - (mm * 2). |
|
0 | 282 |
|
283 |
(hWanted < height) ifTrue:[ |
|
371 | 284 |
hWanted := height |
0 | 285 |
]. |
59 | 286 |
^ (wWanted @ hWanted) |
166 | 287 |
|
371 | 288 |
"Modified: 21.2.1996 / 01:01:02 / cg" |
0 | 289 |
! ! |
290 |
||
132 | 291 |
!ListSelectionBox methodsFor:'user actions'! |
292 |
||
197 | 293 |
doubleClick |
294 |
"doubleClick on an entry is select & ok" |
|
295 |
||
402
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
296 |
enterField notNil ifTrue:[ |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
297 |
enterField contents:(selectionList selectionValue). |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
298 |
]. |
197 | 299 |
self okPressed |
402
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
300 |
|
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
301 |
"Modified: 26.2.1996 / 20:05:45 / cg" |
197 | 302 |
! |
303 |
||
132 | 304 |
selectionChanged |
305 |
"selections in list get forwarded to enterfield" |
|
306 |
||
166 | 307 |
enterField notNil ifTrue:[ |
308 |
enterField contents:(selectionList selectionValue) |
|
309 |
] |
|
310 |
||
311 |
"Modified: 26.10.1995 / 17:20:06 / cg" |
|
312 |
! ! |
|
313 |
||
243 | 314 |
!ListSelectionBox class methodsFor:'documentation'! |
315 |
||
316 |
version |
|
593 | 317 |
^ '$Header: /cvs/stx/stx/libwidg/ListSelectionBox.st,v 1.28 1996-04-27 18:16:14 cg Exp $' |
243 | 318 |
! ! |