author | Claus Gittinger <cg@exept.de> |
Fri, 21 Jul 2000 17:54:55 +0200 | |
changeset 2200 | 8dad27a92dbd |
parent 1281 | 2852cfe9cae3 |
child 2261 | 260a8cd9905d |
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 |
||
1273 | 20 |
!ListSelectionBox class methodsFor:'documentation'! |
38 | 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'). |
|
655 | 60 |
box okAction:[:sel | Transcript showCR:'the selection was:' , sel]. |
593 | 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'). |
|
655 | 72 |
box okAction:[:sel | Transcript showCR:'the selection was:' , sel]. |
593 | 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'. |
|
655 | 89 |
box okAction:[:sel | Transcript showCR:'the selection was:' , sel]. |
593 | 90 |
box abortAction:[:dummy | box hide]. |
91 |
box openModeless |
|
92 |
[exEnd] |
|
38 | 93 |
" |
197 | 94 |
! ! |
95 |
||
1273 | 96 |
!ListSelectionBox class methodsFor:'instance creation'! |
197 | 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 |
|
1273 | 108 |
!ListSelectionBox class methodsFor:'defaults'! |
0 | 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 |
||
775
ccc53ba319bc
dont ask Display for defaultExtent - ask current screen
Claus Gittinger <cg@exept.de>
parents:
740
diff
changeset
|
115 |
^ (Screen current pixelPerMillimeter * (80 @ 100)) rounded |
571 | 116 |
|
775
ccc53ba319bc
dont ask Display for defaultExtent - ask current screen
Claus Gittinger <cg@exept.de>
parents:
740
diff
changeset
|
117 |
"Modified: 5.7.1996 / 13:53:46 / 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. |
690 | 144 |
selectionList setSelectElement:someString. |
145 |
||
146 |
"Modified: 26.5.1996 / 15:03:37 / cg" |
|
197 | 147 |
! |
148 |
||
149 |
list:aList |
|
150 |
"set the list to be displayed in selection list" |
|
151 |
||
152 |
selectionList list:aList |
|
841 | 153 |
! |
154 |
||
155 |
selectionIndex |
|
156 |
^ selectionList selection |
|
157 |
||
158 |
"Created: 14.10.1996 / 16:28:50 / cg" |
|
197 | 159 |
! ! |
0 | 160 |
|
197 | 161 |
!ListSelectionBox methodsFor:'accessing-components'! |
162 |
||
163 |
listView |
|
164 |
"return the listView component" |
|
165 |
||
166 |
^ selectionList |
|
0 | 167 |
|
197 | 168 |
"Created: 26.10.1995 / 17:08:32 / cg" |
169 |
! ! |
|
170 |
||
171 |
!ListSelectionBox methodsFor:'accessing-look'! |
|
172 |
||
173 |
noEnterField |
|
638 | 174 |
"suppress the enterField - now only existing items are selectable; |
175 |
the default is to present an enterField." |
|
176 |
||
197 | 177 |
enterField destroy. |
178 |
enterField := nil |
|
179 |
||
180 |
"Created: 26.10.1995 / 17:12:38 / cg" |
|
638 | 181 |
"Modified: 12.5.1996 / 21:49:14 / cg" |
0 | 182 |
! ! |
183 |
||
184 |
!ListSelectionBox methodsFor:'initialization'! |
|
185 |
||
186 |
initialize |
|
1281 | 187 |
|space2 halfSpace v vbw| |
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. |
740
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
724
diff
changeset
|
230 |
self makeTabable:selectionList. |
0 | 231 |
|
232 |
"self updateList." |
|
233 |
||
724 | 234 |
"I am interested in what is done in the selectionList |
132 | 235 |
(could also create a SelectionInList-model and catch its changes ...)" |
236 |
selectionList action:[:lineNr | self selectionChanged]. |
|
237 |
selectionList doubleClickAction:[:lineNr | self doubleClick]. |
|
238 |
||
130 | 239 |
enterField removeDependent:self. "dont want preferredExtent-changes" |
128 | 240 |
|
38 | 241 |
" |
242 |
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
|
243 |
and input passed to the enterfield (except cursor keys) |
38 | 244 |
" |
319
d78f5fbdee27
dont forward Cursor-motion to the enterField
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
245 |
selectionList delegate:( |
412 | 246 |
KeyboardForwarder |
247 |
toView:enterField |
|
248 |
condition:#noFocus |
|
249 |
filter:[:key | (key ~~ #CursorUp) and:[key ~~ #CursorDown]] |
|
250 |
) |
|
166 | 251 |
|
740
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
724
diff
changeset
|
252 |
"Modified: 31.5.1996 / 22:02:33 / cg" |
0 | 253 |
! |
254 |
||
1273 | 255 |
postRealize |
256 |
"update the list now. |
|
638 | 257 |
This was not done in #initialize to allow settings to be changed before, |
258 |
in case list-updating is a slow operation - such as reading a directory" |
|
259 |
||
1273 | 260 |
super postRealize. |
0 | 261 |
self updateList. |
638 | 262 |
|
263 |
"Modified: 12.5.1996 / 21:50:50 / cg" |
|
1273 | 264 |
"Created: 24.7.1997 / 18:22:19 / cg" |
77 | 265 |
! |
266 |
||
197 | 267 |
updateList |
638 | 268 |
"setup contents of list; |
269 |
nothing done here but typically redefined in subclasses." |
|
197 | 270 |
|
271 |
^ self |
|
638 | 272 |
|
273 |
"Modified: 12.5.1996 / 21:51:10 / cg" |
|
0 | 274 |
! ! |
275 |
||
59 | 276 |
!ListSelectionBox methodsFor:'queries'! |
0 | 277 |
|
130 | 278 |
preferredExtent |
279 |
"return my preferred extent - thats the minimum size |
|
125 | 280 |
I like to have, to make everything visible" |
0 | 281 |
|
371 | 282 |
|wWanted hWanted eH mm| |
283 |
||
799 | 284 |
"/ If I have an explicit preferredExtent .. |
285 |
||
713
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
286 |
preferredExtent notNil ifTrue:[ |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
287 |
^ preferredExtent |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
288 |
]. |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
690
diff
changeset
|
289 |
|
371 | 290 |
mm := ViewSpacing. |
125 | 291 |
|
371 | 292 |
wWanted := mm + labelField width + mm. |
0 | 293 |
(wWanted > width) ifFalse:[ |
371 | 294 |
wWanted := width |
0 | 295 |
]. |
125 | 296 |
|
166 | 297 |
enterField notNil ifTrue:[ |
371 | 298 |
eH := enterField height + mm |
166 | 299 |
] ifFalse:[ |
371 | 300 |
eH := 0 |
166 | 301 |
]. |
371 | 302 |
hWanted := mm + labelField height + |
303 |
eH + |
|
304 |
mm + selectionList height + |
|
305 |
mm + buttonPanel preferredExtent y + |
|
306 |
mm - (mm * 2). |
|
0 | 307 |
|
308 |
(hWanted < height) ifTrue:[ |
|
371 | 309 |
hWanted := height |
0 | 310 |
]. |
59 | 311 |
^ (wWanted @ hWanted) |
166 | 312 |
|
799 | 313 |
"Modified: 19.7.1996 / 20:44:52 / cg" |
0 | 314 |
! ! |
315 |
||
132 | 316 |
!ListSelectionBox methodsFor:'user actions'! |
317 |
||
197 | 318 |
doubleClick |
319 |
"doubleClick on an entry is select & ok" |
|
320 |
||
402
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
321 |
enterField notNil ifTrue:[ |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
322 |
enterField contents:(selectionList selectionValue). |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
323 |
]. |
197 | 324 |
self okPressed |
402
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
325 |
|
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
326 |
"Modified: 26.2.1996 / 20:05:45 / cg" |
197 | 327 |
! |
328 |
||
132 | 329 |
selectionChanged |
330 |
"selections in list get forwarded to enterfield" |
|
331 |
||
166 | 332 |
enterField notNil ifTrue:[ |
333 |
enterField contents:(selectionList selectionValue) |
|
334 |
] |
|
335 |
||
336 |
"Modified: 26.10.1995 / 17:20:06 / cg" |
|
337 |
! ! |
|
338 |
||
1273 | 339 |
!ListSelectionBox class methodsFor:'documentation'! |
243 | 340 |
|
341 |
version |
|
1281 | 342 |
^ '$Header: /cvs/stx/stx/libwidg/ListSelectionBox.st,v 1.39 1997-07-26 14:21:52 cg Exp $' |
243 | 343 |
! ! |