author | Claus Gittinger <cg@exept.de> |
Fri, 01 Mar 1996 14:02:46 +0100 | |
changeset 441 | e170bca66a78 |
parent 412 | bb3d94d97b91 |
child 571 | ddc5d56bd636 |
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. |
|
45 |
" |
|
46 |
! |
|
47 |
||
48 |
examples |
|
49 |
" |
|
50 |
simple: |
|
38 | 51 |
|
59 | 52 |
|box| |
38 | 53 |
|
59 | 54 |
box := ListSelectionBox new. |
55 |
box title:'select something:'. |
|
56 |
box list:#('foo' 'bar' 'baz'). |
|
57 |
box okAction:[:sel | Transcript showCr:'the selection was:' , sel]. |
|
58 |
box showAtPointer |
|
77 | 59 |
|
155 | 60 |
|
77 | 61 |
with a default: |
62 |
||
63 |
|box| |
|
64 |
||
65 |
box := ListSelectionBox new. |
|
66 |
box title:'select something:'. |
|
67 |
box list:#('foo' 'bar' 'baz'). |
|
68 |
box okAction:[:sel | Transcript showCr:'the selection was:' , sel]. |
|
69 |
box initialText:'foo'. |
|
70 |
box showAtPointer |
|
155 | 71 |
|
72 |
||
73 |
opening the box modeless (a stand-by box): |
|
74 |
(in this case, the default ok- and abortActions do not hide the box; |
|
75 |
therefore, we have to set those explicitely) |
|
76 |
||
77 |
|box| |
|
78 |
||
79 |
box := ListSelectionBox new. |
|
80 |
box title:'select something:'. |
|
81 |
box list:#('foo' 'bar' 'baz'). |
|
82 |
box abortText:'close'. |
|
83 |
box okText:'apply'. |
|
84 |
box okAction:[:sel | Transcript showCr:'the selection was:' , sel]. |
|
85 |
box abortAction:[:dummy | box hide]. |
|
86 |
box openModeless |
|
38 | 87 |
" |
197 | 88 |
! ! |
89 |
||
90 |
!ListSelectionBox class methodsFor:'instance creation'! |
|
91 |
||
92 |
title:titleString okText:okText abortText:abortText list:aList action:aBlock |
|
93 |
"create and return a new listSelectionBox with list already defined" |
|
94 |
||
95 |
|newBox| |
|
96 |
||
97 |
newBox := super title:titleString okText:okText abortText:abortText |
|
98 |
action:aBlock. |
|
99 |
^ newBox list:aList |
|
38 | 100 |
! ! |
0 | 101 |
|
102 |
!ListSelectionBox class methodsFor:'defaults'! |
|
103 |
||
104 |
defaultExtent |
|
105 |
^ (Display pixelPerMillimeter * (80 @ 100)) rounded |
|
12 | 106 |
! |
107 |
||
108 |
listViewType |
|
109 |
"return the type of listView |
|
110 |
- for easier redefinition in subclasses" |
|
111 |
||
112 |
^ SelectionInListView |
|
0 | 113 |
! ! |
114 |
||
197 | 115 |
!ListSelectionBox methodsFor:'accessing'! |
116 |
||
402
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
117 |
contents |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
118 |
"return my contents" |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
119 |
|
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
120 |
enterField isNil ifTrue:[ |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
121 |
^ selectionList selectionValue |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
122 |
]. |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
123 |
^ super contents |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
124 |
|
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
125 |
"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
|
126 |
! |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
127 |
|
197 | 128 |
initialText:someString |
129 |
"in addition to showing the initial text, also select it in the list" |
|
0 | 130 |
|
197 | 131 |
super initialText:someString. |
132 |
selectionList selectElement:someString. |
|
133 |
! |
|
134 |
||
135 |
list:aList |
|
136 |
"set the list to be displayed in selection list" |
|
137 |
||
138 |
selectionList list:aList |
|
139 |
! ! |
|
0 | 140 |
|
197 | 141 |
!ListSelectionBox methodsFor:'accessing-components'! |
142 |
||
143 |
listView |
|
144 |
"return the listView component" |
|
145 |
||
146 |
^ selectionList |
|
0 | 147 |
|
197 | 148 |
"Created: 26.10.1995 / 17:08:32 / cg" |
149 |
! ! |
|
150 |
||
151 |
!ListSelectionBox methodsFor:'accessing-look'! |
|
152 |
||
153 |
noEnterField |
|
154 |
enterField destroy. |
|
155 |
enterField := nil |
|
156 |
||
157 |
"Created: 26.10.1995 / 17:12:38 / cg" |
|
0 | 158 |
! ! |
159 |
||
160 |
!ListSelectionBox methodsFor:'initialization'! |
|
161 |
||
197 | 162 |
focusSequence |
163 |
^ Array with:enterField with:selectionList with:abortButton with:okButton |
|
164 |
! |
|
165 |
||
0 | 166 |
initialize |
166 | 167 |
|space2 halfSpace v vbw eH| |
0 | 168 |
|
169 |
super initialize. |
|
170 |
||
412 | 171 |
label := resources string:'Select or enter'. |
77 | 172 |
|
0 | 173 |
"need more space than an enterBox" |
174 |
||
175 |
"self height:(height + (font height * 5)). " |
|
176 |
||
177 |
space2 := 2 * ViewSpacing. |
|
125 | 178 |
halfSpace := ViewSpacing // 2. |
0 | 179 |
|
12 | 180 |
v := ScrollableView for:(self class listViewType) in:self. |
0 | 181 |
|
132 | 182 |
"/ old: |
183 |
"/ v origin:[0.0 |
|
125 | 184 |
"/ @ |
132 | 185 |
"/ (enterField origin y + enterField height + ViewSpacing)] |
186 |
"/ extent:[1.0 |
|
125 | 187 |
"/ @ |
132 | 188 |
"/ (height |
125 | 189 |
"/ - ViewSpacing - labelField heightIncludingBorder |
190 |
"/ - ViewSpacing - enterField heightIncludingBorder |
|
191 |
"/ - buttonPanel heightIncludingBorder - ViewSpacing |
|
192 |
"/ - space2) |
|
132 | 193 |
"/ ]. |
194 |
||
195 |
"/ new: |
|
166 | 196 |
v origin:[enterField notNil ifTrue:[ |
412 | 197 |
0.0 @ (enterField origin y + enterField height + ViewSpacing) |
198 |
] ifFalse:[ |
|
199 |
0.0 @ (labelField origin y + labelField height + ViewSpacing) |
|
200 |
] |
|
201 |
] |
|
132 | 202 |
corner:(1.0 @ 1.0). |
203 |
v bottomInset:(buttonPanel preferredExtent y + ViewSpacing). |
|
204 |
||
139 | 205 |
vbw := v borderWidth. |
206 |
v leftInset:halfSpace+vbw; |
|
207 |
rightInset:halfSpace+vbw. |
|
110 | 208 |
|
0 | 209 |
selectionList := v scrolledView. |
210 |
||
211 |
"self updateList." |
|
212 |
||
132 | 213 |
"I am interested in what is done int the selectionList |
214 |
(could also create a SelectionInList-model and catch its changes ...)" |
|
215 |
selectionList action:[:lineNr | self selectionChanged]. |
|
216 |
selectionList doubleClickAction:[:lineNr | self doubleClick]. |
|
217 |
||
130 | 218 |
enterField removeDependent:self. "dont want preferredExtent-changes" |
128 | 219 |
|
38 | 220 |
" |
221 |
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
|
222 |
and input passed to the enterfield (except cursor keys) |
38 | 223 |
" |
319
d78f5fbdee27
dont forward Cursor-motion to the enterField
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
224 |
selectionList delegate:( |
412 | 225 |
KeyboardForwarder |
226 |
toView:enterField |
|
227 |
condition:#noFocus |
|
228 |
filter:[:key | (key ~~ #CursorUp) and:[key ~~ #CursorDown]] |
|
229 |
) |
|
166 | 230 |
|
412 | 231 |
"Modified: 27.2.1996 / 01:11:41 / cg" |
0 | 232 |
! |
233 |
||
234 |
realize |
|
235 |
self updateList. |
|
236 |
super realize |
|
77 | 237 |
! |
238 |
||
197 | 239 |
updateList |
240 |
"setup contents of list; nothing done here but redefined in subclasses" |
|
241 |
||
242 |
^ self |
|
0 | 243 |
! ! |
244 |
||
59 | 245 |
!ListSelectionBox methodsFor:'queries'! |
0 | 246 |
|
130 | 247 |
preferredExtent |
248 |
"return my preferred extent - thats the minimum size |
|
125 | 249 |
I like to have, to make everything visible" |
0 | 250 |
|
371 | 251 |
|wWanted hWanted eH mm| |
252 |
||
253 |
mm := ViewSpacing. |
|
125 | 254 |
|
371 | 255 |
wWanted := mm + labelField width + mm. |
0 | 256 |
(wWanted > width) ifFalse:[ |
371 | 257 |
wWanted := width |
0 | 258 |
]. |
125 | 259 |
|
166 | 260 |
enterField notNil ifTrue:[ |
371 | 261 |
eH := enterField height + mm |
166 | 262 |
] ifFalse:[ |
371 | 263 |
eH := 0 |
166 | 264 |
]. |
371 | 265 |
hWanted := mm + labelField height + |
266 |
eH + |
|
267 |
mm + selectionList height + |
|
268 |
mm + buttonPanel preferredExtent y + |
|
269 |
mm - (mm * 2). |
|
0 | 270 |
|
271 |
(hWanted < height) ifTrue:[ |
|
371 | 272 |
hWanted := height |
0 | 273 |
]. |
59 | 274 |
^ (wWanted @ hWanted) |
166 | 275 |
|
371 | 276 |
"Modified: 21.2.1996 / 01:01:02 / cg" |
0 | 277 |
! ! |
278 |
||
132 | 279 |
!ListSelectionBox methodsFor:'user actions'! |
280 |
||
197 | 281 |
doubleClick |
282 |
"doubleClick on an entry is select & ok" |
|
283 |
||
402
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
284 |
enterField notNil ifTrue:[ |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
285 |
enterField contents:(selectionList selectionValue). |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
286 |
]. |
197 | 287 |
self okPressed |
402
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
288 |
|
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
289 |
"Modified: 26.2.1996 / 20:05:45 / cg" |
197 | 290 |
! |
291 |
||
132 | 292 |
selectionChanged |
293 |
"selections in list get forwarded to enterfield" |
|
294 |
||
166 | 295 |
enterField notNil ifTrue:[ |
296 |
enterField contents:(selectionList selectionValue) |
|
297 |
] |
|
298 |
||
299 |
"Modified: 26.10.1995 / 17:20:06 / cg" |
|
300 |
! ! |
|
301 |
||
243 | 302 |
!ListSelectionBox class methodsFor:'documentation'! |
303 |
||
304 |
version |
|
412 | 305 |
^ '$Header: /cvs/stx/stx/libwidg/Attic/LSelBox.st,v 1.25 1996-02-27 00:12:10 cg Exp $' |
243 | 306 |
! ! |