author | Claus Gittinger <cg@exept.de> |
Sun, 12 May 1996 21:51:43 +0200 | |
changeset 638 | 72c3d36df4d8 |
parent 593 | 86dd024ed773 |
child 655 | acad3ef3a46c |
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 |
|
638 | 166 |
"suppress the enterField - now only existing items are selectable; |
167 |
the default is to present an enterField." |
|
168 |
||
197 | 169 |
enterField destroy. |
170 |
enterField := nil |
|
171 |
||
172 |
"Created: 26.10.1995 / 17:12:38 / cg" |
|
638 | 173 |
"Modified: 12.5.1996 / 21:49:14 / cg" |
0 | 174 |
! ! |
175 |
||
176 |
!ListSelectionBox methodsFor:'initialization'! |
|
177 |
||
197 | 178 |
focusSequence |
638 | 179 |
"return a sequence for tabbing through my components" |
180 |
||
181 |
^ Array with:enterField with:selectionList with:abortButton with:okButton |
|
182 |
||
183 |
"Modified: 12.5.1996 / 21:49:37 / cg" |
|
197 | 184 |
! |
185 |
||
0 | 186 |
initialize |
166 | 187 |
|space2 halfSpace v vbw eH| |
0 | 188 |
|
189 |
super initialize. |
|
190 |
||
412 | 191 |
label := resources string:'Select or enter'. |
77 | 192 |
|
0 | 193 |
"need more space than an enterBox" |
194 |
||
195 |
"self height:(height + (font height * 5)). " |
|
196 |
||
197 |
space2 := 2 * ViewSpacing. |
|
125 | 198 |
halfSpace := ViewSpacing // 2. |
0 | 199 |
|
12 | 200 |
v := ScrollableView for:(self class listViewType) in:self. |
0 | 201 |
|
132 | 202 |
"/ old: |
203 |
"/ v origin:[0.0 |
|
125 | 204 |
"/ @ |
132 | 205 |
"/ (enterField origin y + enterField height + ViewSpacing)] |
206 |
"/ extent:[1.0 |
|
125 | 207 |
"/ @ |
132 | 208 |
"/ (height |
125 | 209 |
"/ - ViewSpacing - labelField heightIncludingBorder |
210 |
"/ - ViewSpacing - enterField heightIncludingBorder |
|
211 |
"/ - buttonPanel heightIncludingBorder - ViewSpacing |
|
212 |
"/ - space2) |
|
132 | 213 |
"/ ]. |
214 |
||
215 |
"/ new: |
|
166 | 216 |
v origin:[enterField notNil ifTrue:[ |
412 | 217 |
0.0 @ (enterField origin y + enterField height + ViewSpacing) |
218 |
] ifFalse:[ |
|
219 |
0.0 @ (labelField origin y + labelField height + ViewSpacing) |
|
220 |
] |
|
221 |
] |
|
132 | 222 |
corner:(1.0 @ 1.0). |
223 |
v bottomInset:(buttonPanel preferredExtent y + ViewSpacing). |
|
224 |
||
139 | 225 |
vbw := v borderWidth. |
226 |
v leftInset:halfSpace+vbw; |
|
227 |
rightInset:halfSpace+vbw. |
|
110 | 228 |
|
0 | 229 |
selectionList := v scrolledView. |
230 |
||
231 |
"self updateList." |
|
232 |
||
132 | 233 |
"I am interested in what is done int the selectionList |
234 |
(could also create a SelectionInList-model and catch its changes ...)" |
|
235 |
selectionList action:[:lineNr | self selectionChanged]. |
|
236 |
selectionList doubleClickAction:[:lineNr | self doubleClick]. |
|
237 |
||
130 | 238 |
enterField removeDependent:self. "dont want preferredExtent-changes" |
128 | 239 |
|
38 | 240 |
" |
241 |
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
|
242 |
and input passed to the enterfield (except cursor keys) |
38 | 243 |
" |
319
d78f5fbdee27
dont forward Cursor-motion to the enterField
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
244 |
selectionList delegate:( |
412 | 245 |
KeyboardForwarder |
246 |
toView:enterField |
|
247 |
condition:#noFocus |
|
248 |
filter:[:key | (key ~~ #CursorUp) and:[key ~~ #CursorDown]] |
|
249 |
) |
|
166 | 250 |
|
412 | 251 |
"Modified: 27.2.1996 / 01:11:41 / cg" |
0 | 252 |
! |
253 |
||
254 |
realize |
|
638 | 255 |
"redefined to update the list now. |
256 |
This was not done in #initialize to allow settings to be changed before, |
|
257 |
in case list-updating is a slow operation - such as reading a directory" |
|
258 |
||
0 | 259 |
self updateList. |
260 |
super realize |
|
638 | 261 |
|
262 |
"Modified: 12.5.1996 / 21:50:50 / cg" |
|
77 | 263 |
! |
264 |
||
197 | 265 |
updateList |
638 | 266 |
"setup contents of list; |
267 |
nothing done here but typically redefined in subclasses." |
|
197 | 268 |
|
269 |
^ self |
|
638 | 270 |
|
271 |
"Modified: 12.5.1996 / 21:51:10 / cg" |
|
0 | 272 |
! ! |
273 |
||
59 | 274 |
!ListSelectionBox methodsFor:'queries'! |
0 | 275 |
|
130 | 276 |
preferredExtent |
277 |
"return my preferred extent - thats the minimum size |
|
125 | 278 |
I like to have, to make everything visible" |
0 | 279 |
|
371 | 280 |
|wWanted hWanted eH mm| |
281 |
||
282 |
mm := ViewSpacing. |
|
125 | 283 |
|
371 | 284 |
wWanted := mm + labelField width + mm. |
0 | 285 |
(wWanted > width) ifFalse:[ |
371 | 286 |
wWanted := width |
0 | 287 |
]. |
125 | 288 |
|
166 | 289 |
enterField notNil ifTrue:[ |
371 | 290 |
eH := enterField height + mm |
166 | 291 |
] ifFalse:[ |
371 | 292 |
eH := 0 |
166 | 293 |
]. |
371 | 294 |
hWanted := mm + labelField height + |
295 |
eH + |
|
296 |
mm + selectionList height + |
|
297 |
mm + buttonPanel preferredExtent y + |
|
298 |
mm - (mm * 2). |
|
0 | 299 |
|
300 |
(hWanted < height) ifTrue:[ |
|
371 | 301 |
hWanted := height |
0 | 302 |
]. |
59 | 303 |
^ (wWanted @ hWanted) |
166 | 304 |
|
371 | 305 |
"Modified: 21.2.1996 / 01:01:02 / cg" |
0 | 306 |
! ! |
307 |
||
132 | 308 |
!ListSelectionBox methodsFor:'user actions'! |
309 |
||
197 | 310 |
doubleClick |
311 |
"doubleClick on an entry is select & ok" |
|
312 |
||
402
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
313 |
enterField notNil ifTrue:[ |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
314 |
enterField contents:(selectionList selectionValue). |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
315 |
]. |
197 | 316 |
self okPressed |
402
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
317 |
|
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
318 |
"Modified: 26.2.1996 / 20:05:45 / cg" |
197 | 319 |
! |
320 |
||
132 | 321 |
selectionChanged |
322 |
"selections in list get forwarded to enterfield" |
|
323 |
||
166 | 324 |
enterField notNil ifTrue:[ |
325 |
enterField contents:(selectionList selectionValue) |
|
326 |
] |
|
327 |
||
328 |
"Modified: 26.10.1995 / 17:20:06 / cg" |
|
329 |
! ! |
|
330 |
||
243 | 331 |
!ListSelectionBox class methodsFor:'documentation'! |
332 |
||
333 |
version |
|
638 | 334 |
^ '$Header: /cvs/stx/stx/libwidg/ListSelectionBox.st,v 1.29 1996-05-12 19:51:43 cg Exp $' |
243 | 335 |
! ! |