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