author | Claus Gittinger <cg@exept.de> |
Thu, 12 Dec 2019 15:25:14 +0100 | |
changeset 6754 | 5a3dd7334670 |
parent 6730 | a173941d35d8 |
permissions | -rw-r--r-- |
6754 | 1 |
"{ Encoding: utf8 }" |
2 |
||
0 | 3 |
" |
5 | 4 |
COPYRIGHT (c) 1990 by Claus Gittinger |
59 | 5 |
All Rights Reserved |
0 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
2261
260a8cd9905d
added a selectionChanged callback
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
14 |
"{ Package: 'stx:libwidg' }" |
260a8cd9905d
added a selectionChanged callback
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
15 |
|
5553 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
0 | 18 |
EnterBox subclass:#ListSelectionBox |
4407 | 19 |
instanceVariableNames:'panel list selectionList selectionChangeCallback useIndex |
5553 | 20 |
searchJob clearEntryFieldOnDeselect' |
371 | 21 |
classVariableNames:'' |
22 |
poolDictionaries:'' |
|
23 |
category:'Views-DialogBoxes' |
|
0 | 24 |
! |
25 |
||
1273 | 26 |
!ListSelectionBox class methodsFor:'documentation'! |
38 | 27 |
|
28 |
copyright |
|
29 |
" |
|
30 |
COPYRIGHT (c) 1990 by Claus Gittinger |
|
59 | 31 |
All Rights Reserved |
38 | 32 |
|
33 |
This software is furnished under a license and may be used |
|
34 |
only in accordance with the terms of that license and with the |
|
35 |
inclusion of the above copyright notice. This software may not |
|
36 |
be provided or otherwise made available to, or used by, any |
|
37 |
other person. No title to or ownership of the software is |
|
38 |
hereby transferred. |
|
39 |
" |
|
40 |
! |
|
0 | 41 |
|
38 | 42 |
documentation |
43 |
" |
|
44 |
this class implements boxes for selection from a list. It offers |
|
45 |
both an ok- and abort-buttons. The ok-button, if pressed will |
|
46 |
evaluate the okAction (see EnterBox>>action). |
|
77 | 47 |
see examples for typical uses. |
48 |
||
49 |
Notice, for file selections there is a specialized FileSelectionBox, |
|
50 |
which supports matchPatterns, changing directory etc. |
|
585 | 51 |
|
52 |
[author:] |
|
53 |
Claus Gittinger |
|
77 | 54 |
" |
55 |
! |
|
56 |
||
57 |
examples |
|
58 |
" |
|
59 |
simple: |
|
593 | 60 |
[exBegin] |
61 |
|box| |
|
38 | 62 |
|
593 | 63 |
box := ListSelectionBox new. |
64 |
box title:'select something:'. |
|
65 |
box list:#('foo' 'bar' 'baz'). |
|
2543 | 66 |
box okAction:[:sel | Transcript show:'the selection was:' ; showCR:sel]. |
593 | 67 |
box showAtPointer |
68 |
[exEnd] |
|
77 | 69 |
|
2541 | 70 |
with index (instead of list-entry) and without an enterField: |
71 |
[exBegin] |
|
72 |
|box| |
|
73 |
||
74 |
box := ListSelectionBox new. |
|
6689 | 75 |
box label:'bla bla'. |
2541 | 76 |
box title:'select something:'. |
77 |
box list:#('foo' 'bar' 'baz'). |
|
78 |
box useIndex:true. |
|
79 |
box okAction:[:sel | Transcript show:'the selection was:' ; showCR:sel]. |
|
80 |
box showAtPointer |
|
81 |
[exEnd] |
|
82 |
||
155 | 83 |
|
77 | 84 |
with a default: |
593 | 85 |
[exBegin] |
86 |
|box| |
|
77 | 87 |
|
593 | 88 |
box := ListSelectionBox new. |
89 |
box title:'select something:'. |
|
90 |
box list:#('foo' 'bar' 'baz'). |
|
2543 | 91 |
box okAction:[:sel | Transcript show:'the selection was:' ; showCR:sel]. |
593 | 92 |
box initialText:'foo'. |
93 |
box showAtPointer |
|
94 |
[exEnd] |
|
155 | 95 |
|
96 |
||
97 |
opening the box modeless (a stand-by box): |
|
98 |
(in this case, the default ok- and abortActions do not hide the box; |
|
99 |
therefore, we have to set those explicitely) |
|
593 | 100 |
[exBegin] |
101 |
|box| |
|
155 | 102 |
|
593 | 103 |
box := ListSelectionBox new. |
104 |
box title:'select something:'. |
|
105 |
box list:#('foo' 'bar' 'baz'). |
|
106 |
box abortText:'close'. |
|
107 |
box okText:'apply'. |
|
2543 | 108 |
box okAction:[:sel | Transcript show:'the selection was:' ; showCR:sel]. |
593 | 109 |
box abortAction:[:dummy | box hide]. |
110 |
box openModeless |
|
111 |
[exEnd] |
|
2280
d9ee8906706e
scroll to make the typed-in string visible in the list (if present)
Claus Gittinger <cg@exept.de>
parents:
2261
diff
changeset
|
112 |
|
d9ee8906706e
scroll to make the typed-in string visible in the list (if present)
Claus Gittinger <cg@exept.de>
parents:
2261
diff
changeset
|
113 |
showing fileNames: |
d9ee8906706e
scroll to make the typed-in string visible in the list (if present)
Claus Gittinger <cg@exept.de>
parents:
2261
diff
changeset
|
114 |
[exBegin] |
d9ee8906706e
scroll to make the typed-in string visible in the list (if present)
Claus Gittinger <cg@exept.de>
parents:
2261
diff
changeset
|
115 |
|box| |
d9ee8906706e
scroll to make the typed-in string visible in the list (if present)
Claus Gittinger <cg@exept.de>
parents:
2261
diff
changeset
|
116 |
|
d9ee8906706e
scroll to make the typed-in string visible in the list (if present)
Claus Gittinger <cg@exept.de>
parents:
2261
diff
changeset
|
117 |
box := ListSelectionBox new. |
d9ee8906706e
scroll to make the typed-in string visible in the list (if present)
Claus Gittinger <cg@exept.de>
parents:
2261
diff
changeset
|
118 |
box title:'select something:'. |
d9ee8906706e
scroll to make the typed-in string visible in the list (if present)
Claus Gittinger <cg@exept.de>
parents:
2261
diff
changeset
|
119 |
box list:('.' asFilename directoryContents). |
2543 | 120 |
box okAction:[:sel | Transcript show:'the selection was:' ; showCR:sel]. |
2280
d9ee8906706e
scroll to make the typed-in string visible in the list (if present)
Claus Gittinger <cg@exept.de>
parents:
2261
diff
changeset
|
121 |
box showAtPointer |
d9ee8906706e
scroll to make the typed-in string visible in the list (if present)
Claus Gittinger <cg@exept.de>
parents:
2261
diff
changeset
|
122 |
[exEnd] |
d9ee8906706e
scroll to make the typed-in string visible in the list (if present)
Claus Gittinger <cg@exept.de>
parents:
2261
diff
changeset
|
123 |
|
d9ee8906706e
scroll to make the typed-in string visible in the list (if present)
Claus Gittinger <cg@exept.de>
parents:
2261
diff
changeset
|
124 |
|
38 | 125 |
" |
197 | 126 |
! ! |
127 |
||
1273 | 128 |
!ListSelectionBox class methodsFor:'instance creation'! |
197 | 129 |
|
130 |
title:titleString okText:okText abortText:abortText list:aList action:aBlock |
|
131 |
"create and return a new listSelectionBox with list already defined" |
|
132 |
||
133 |
|newBox| |
|
134 |
||
2543 | 135 |
newBox := self |
136 |
title:titleString okText:okText abortText:abortText |
|
137 |
action:aBlock. |
|
138 |
newBox list:aList. |
|
139 |
^ newBox |
|
38 | 140 |
! ! |
0 | 141 |
|
1273 | 142 |
!ListSelectionBox class methodsFor:'defaults'! |
0 | 143 |
|
144 |
defaultExtent |
|
571 | 145 |
"return the default extent of my instances. |
146 |
The value returned here is usually ignored, and |
|
147 |
the value from preferredExtent taken instead." |
|
148 |
||
775
ccc53ba319bc
dont ask Display for defaultExtent - ask current screen
Claus Gittinger <cg@exept.de>
parents:
740
diff
changeset
|
149 |
^ (Screen current pixelPerMillimeter * (80 @ 100)) rounded |
571 | 150 |
|
775
ccc53ba319bc
dont ask Display for defaultExtent - ask current screen
Claus Gittinger <cg@exept.de>
parents:
740
diff
changeset
|
151 |
"Modified: 5.7.1996 / 13:53:46 / cg" |
12 | 152 |
! |
153 |
||
154 |
listViewType |
|
155 |
"return the type of listView |
|
156 |
- for easier redefinition in subclasses" |
|
157 |
||
158 |
^ SelectionInListView |
|
0 | 159 |
! ! |
160 |
||
197 | 161 |
!ListSelectionBox methodsFor:'accessing'! |
162 |
||
402
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
163 |
contents |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
164 |
"return my contents" |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
165 |
|
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
166 |
enterField isNil ifTrue:[ |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
167 |
^ selectionList selectionValue |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
168 |
]. |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
169 |
^ super contents |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
170 |
|
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
171 |
"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
|
172 |
! |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
173 |
|
3048 | 174 |
initialSelection:selected |
175 |
"select some item in the list" |
|
176 |
||
177 |
||
178 |
selectionList selection:selected |
|
179 |
! |
|
180 |
||
2444 | 181 |
initialText:someString selected:selected |
182 |
"in addition to showing the initial text; optionally also select it in the list" |
|
0 | 183 |
|
2444 | 184 |
super initialText:someString selected:selected. |
185 |
selected ifTrue:[ |
|
186 |
selectionList setSelectElement:someString |
|
187 |
]. |
|
690 | 188 |
|
189 |
"Modified: 26.5.1996 / 15:03:37 / cg" |
|
197 | 190 |
! |
191 |
||
192 |
list:aList |
|
193 |
"set the list to be displayed in selection list" |
|
194 |
||
4298
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
195 |
list := aList. |
197 | 196 |
selectionList list:aList |
4298
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
197 |
|
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
198 |
"Modified: / 03-08-2011 / 12:30:00 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
841 | 199 |
! |
200 |
||
2261
260a8cd9905d
added a selectionChanged callback
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
201 |
selectionChangeCallback:aBlock |
2359 | 202 |
"allows special actions to be hooked in, when the selection changes" |
2261
260a8cd9905d
added a selectionChanged callback
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
203 |
|
260a8cd9905d
added a selectionChanged callback
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
204 |
selectionChangeCallback := aBlock. |
260a8cd9905d
added a selectionChanged callback
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
205 |
! |
260a8cd9905d
added a selectionChanged callback
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
206 |
|
841 | 207 |
selectionIndex |
208 |
^ selectionList selection |
|
209 |
||
210 |
"Created: 14.10.1996 / 16:28:50 / cg" |
|
2958 | 211 |
! |
212 |
||
213 |
selectionList |
|
214 |
||
215 |
^selectionList |
|
2546 | 216 |
! ! |
217 |
||
218 |
!ListSelectionBox methodsFor:'accessing-behavior'! |
|
2541 | 219 |
|
5553 | 220 |
clearEntryFieldOnDeselect |
221 |
"normally, the entryfield's contents is not cleared, |
|
222 |
when the list is deselected. |
|
223 |
This can be changed here." |
|
224 |
||
225 |
^ clearEntryFieldOnDeselect ? false |
|
226 |
! |
|
227 |
||
228 |
clearEntryFieldOnDeselect:aBoolean |
|
229 |
"normally, the entryfield's contents is not cleared, |
|
230 |
when the list is deselected. |
|
231 |
This can be changed here." |
|
232 |
||
233 |
clearEntryFieldOnDeselect := aBoolean. |
|
234 |
! |
|
235 |
||
2541 | 236 |
useIndex:aBoolean |
237 |
aBoolean ifTrue:[ |
|
238 |
self noEnterField |
|
239 |
]. |
|
2545 | 240 |
useIndex := aBoolean |
197 | 241 |
! ! |
0 | 242 |
|
197 | 243 |
!ListSelectionBox methodsFor:'accessing-components'! |
244 |
||
245 |
listView |
|
246 |
"return the listView component" |
|
247 |
||
248 |
^ selectionList |
|
0 | 249 |
|
197 | 250 |
"Created: 26.10.1995 / 17:08:32 / cg" |
4407 | 251 |
! |
252 |
||
253 |
panelView |
|
6754 | 254 |
"the panelView is the container for the listView; |
255 |
can be accessed to add more components" |
|
256 |
||
257 |
^ panel |
|
258 |
||
259 |
"Created: / 22-03-2012 / 10:30:16 / cg" |
|
260 |
! |
|
261 |
||
262 |
verticalPanel |
|
263 |
"for protocol compatibility with Info/Dialog boxes. |
|
264 |
the panelView is the container for the listView; |
|
265 |
can be accessed to add more components" |
|
266 |
||
4407 | 267 |
^ panel |
268 |
||
269 |
"Created: / 22-03-2012 / 10:30:16 / cg" |
|
197 | 270 |
! ! |
271 |
||
272 |
!ListSelectionBox methodsFor:'accessing-look'! |
|
273 |
||
274 |
noEnterField |
|
638 | 275 |
"suppress the enterField - now only existing items are selectable; |
276 |
the default is to present an enterField." |
|
277 |
||
197 | 278 |
enterField destroy. |
279 |
enterField := nil |
|
280 |
||
281 |
"Created: 26.10.1995 / 17:12:38 / cg" |
|
638 | 282 |
"Modified: 12.5.1996 / 21:49:14 / cg" |
2556 | 283 |
! |
284 |
||
285 |
useComboBoxWithList:list |
|
286 |
"change the enterField to be a ComboList" |
|
287 |
||
288 |
self addEnterField:(ComboBoxView new). |
|
289 |
enterField leaveAction:[:key | self okPressed]. |
|
290 |
enterField list:list. |
|
0 | 291 |
! ! |
292 |
||
293 |
!ListSelectionBox methodsFor:'initialization'! |
|
294 |
||
4298
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
295 |
beLiveSearchBox |
5222 | 296 |
#todo. "/ Jan, please comment what it does and who needs it |
4298
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
297 |
|
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
298 |
enterField delegate:( |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
299 |
KeyboardForwarder |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
300 |
toView:selectionList |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
301 |
condition:[:type :key :view|(key == #CursorUp) or:[key == #CursorDown]] |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
302 |
filter:[:key | (key == #CursorUp) or:[key == #CursorDown]] |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
303 |
). |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
304 |
|
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
305 |
searchJob := BackgroundJob |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
306 |
named: 'List Selection Box Search Job' |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
307 |
on: [self filterList]. |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
308 |
|
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
309 |
enterField immediateAccept: true. |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
310 |
enterField model: ValueHolder new. |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
311 |
enterField model onChangeSend: #restart to: searchJob. |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
312 |
|
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
313 |
"Created: / 03-08-2011 / 12:27:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
314 |
! |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
315 |
|
0 | 316 |
initialize |
1281 | 317 |
|space2 halfSpace v vbw| |
0 | 318 |
|
319 |
super initialize. |
|
320 |
||
2545 | 321 |
useIndex := false. |
4166 | 322 |
"/ label := resources string:'Select or Enter'. |
323 |
label := resources string:'Please Select'. |
|
77 | 324 |
|
0 | 325 |
"need more space than an enterBox" |
326 |
||
327 |
"self height:(height + (font height * 5)). " |
|
328 |
||
329 |
space2 := 2 * ViewSpacing. |
|
125 | 330 |
halfSpace := ViewSpacing // 2. |
0 | 331 |
|
4407 | 332 |
panel := VerticalPanelView in:self. |
6730 | 333 |
panel horizontalLayout:#fit verticalLayout:#topFit. |
4407 | 334 |
|
335 |
v := HVScrollableView for:(self class listViewType) in:panel. |
|
2295 | 336 |
v horizontalScrollable:true; horizontalMini:true; autoHideHorizontalScrollBar:true. |
0 | 337 |
|
132 | 338 |
"/ old: |
339 |
"/ v origin:[0.0 |
|
125 | 340 |
"/ @ |
132 | 341 |
"/ (enterField origin y + enterField height + ViewSpacing)] |
342 |
"/ extent:[1.0 |
|
125 | 343 |
"/ @ |
132 | 344 |
"/ (height |
125 | 345 |
"/ - ViewSpacing - labelField heightIncludingBorder |
346 |
"/ - ViewSpacing - enterField heightIncludingBorder |
|
347 |
"/ - buttonPanel heightIncludingBorder - ViewSpacing |
|
348 |
"/ - space2) |
|
132 | 349 |
"/ ]. |
350 |
||
351 |
"/ new: |
|
4407 | 352 |
panel origin:[enterField notNil ifTrue:[ |
412 | 353 |
0.0 @ (enterField origin y + enterField height + ViewSpacing) |
354 |
] ifFalse:[ |
|
355 |
0.0 @ (labelField origin y + labelField height + ViewSpacing) |
|
356 |
] |
|
357 |
] |
|
132 | 358 |
corner:(1.0 @ 1.0). |
4407 | 359 |
panel bottomInset:(buttonPanel preferredHeight + ViewSpacing). |
132 | 360 |
|
139 | 361 |
vbw := v borderWidth. |
6636 | 362 |
v leftInset:(halfSpace+vbw) rightInset:(halfSpace+vbw). |
110 | 363 |
|
0 | 364 |
selectionList := v scrolledView. |
740
2d5cb01c7e11
no need for focusSequence - DialogBox does it
Claus Gittinger <cg@exept.de>
parents:
724
diff
changeset
|
365 |
self makeTabable:selectionList. |
0 | 366 |
|
367 |
"self updateList." |
|
368 |
||
724 | 369 |
"I am interested in what is done in the selectionList |
132 | 370 |
(could also create a SelectionInList-model and catch its changes ...)" |
371 |
selectionList action:[:lineNr | self selectionChanged]. |
|
372 |
selectionList doubleClickAction:[:lineNr | self doubleClick]. |
|
373 |
||
2511
639be3067ff8
suppress focus from going to listView.
Claus Gittinger <cg@exept.de>
parents:
2500
diff
changeset
|
374 |
selectionList doNotRequestFocusOnPointerEnter:true. |
639be3067ff8
suppress focus from going to listView.
Claus Gittinger <cg@exept.de>
parents:
2500
diff
changeset
|
375 |
|
5586 | 376 |
enterField removeDependent:self. "don't want preferredExtent-changes" |
128 | 377 |
|
2280
d9ee8906706e
scroll to make the typed-in string visible in the list (if present)
Claus Gittinger <cg@exept.de>
parents:
2261
diff
changeset
|
378 |
enterField immediateAccept:true. |
d9ee8906706e
scroll to make the typed-in string visible in the list (if present)
Claus Gittinger <cg@exept.de>
parents:
2261
diff
changeset
|
379 |
enterField acceptAction: |
d9ee8906706e
scroll to make the typed-in string visible in the list (if present)
Claus Gittinger <cg@exept.de>
parents:
2261
diff
changeset
|
380 |
[:text | |string index| |
2282 | 381 |
enterField notNil ifTrue:[ |
382 |
string := enterField contents. |
|
5936 | 383 |
string notEmptyOrNil ifTrue:[ |
384 |
"/ find the first list-entry, starting with entered text |
|
385 |
index := (selectionList list ? #()) findFirst:[:line | (line ? '') string startsWith:string string]. |
|
386 |
index ~~ 0 ifTrue:[ |
|
387 |
selectionList scrollToLine:index "/ makeLineVisible:index. |
|
388 |
]. |
|
2282 | 389 |
]. |
2280
d9ee8906706e
scroll to make the typed-in string visible in the list (if present)
Claus Gittinger <cg@exept.de>
parents:
2261
diff
changeset
|
390 |
]. |
d9ee8906706e
scroll to make the typed-in string visible in the list (if present)
Claus Gittinger <cg@exept.de>
parents:
2261
diff
changeset
|
391 |
]. |
d9ee8906706e
scroll to make the typed-in string visible in the list (if present)
Claus Gittinger <cg@exept.de>
parents:
2261
diff
changeset
|
392 |
|
38 | 393 |
" |
394 |
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
|
395 |
and input passed to the enterfield (except cursor keys) |
38 | 396 |
" |
319
d78f5fbdee27
dont forward Cursor-motion to the enterField
Claus Gittinger <cg@exept.de>
parents:
243
diff
changeset
|
397 |
selectionList delegate:( |
412 | 398 |
KeyboardForwarder |
399 |
toView:enterField |
|
400 |
condition:#noFocus |
|
401 |
filter:[:key | (key ~~ #CursorUp) and:[key ~~ #CursorDown]] |
|
402 |
) |
|
166 | 403 |
|
4407 | 404 |
"Modified (format): / 22-03-2012 / 10:30:03 / cg" |
6636 | 405 |
"Modified: / 16-07-2019 / 16:38:10 / Claus Gittinger" |
0 | 406 |
! |
407 |
||
1273 | 408 |
postRealize |
409 |
"update the list now. |
|
638 | 410 |
This was not done in #initialize to allow settings to be changed before, |
411 |
in case list-updating is a slow operation - such as reading a directory" |
|
412 |
||
1273 | 413 |
super postRealize. |
0 | 414 |
self updateList. |
5699 | 415 |
self setupEditfieldToMoveToListOnCursorDown. |
416 |
||
638 | 417 |
"Modified: 12.5.1996 / 21:50:50 / cg" |
1273 | 418 |
"Created: 24.7.1997 / 18:22:19 / cg" |
77 | 419 |
! |
420 |
||
5699 | 421 |
setupEditfieldToMoveToListOnCursorDown |
5702 | 422 |
|inputField| |
423 |
||
424 |
(inputField := self enterField) isNil ifTrue:[^ self]. |
|
425 |
inputField |
|
5699 | 426 |
onKey:#CursorDown |
427 |
leaveWith:[ |
|
428 |
|listView| |
|
429 |
||
430 |
listView := self listView. |
|
431 |
listView windowGroup focusView:listView byTab:true. |
|
432 |
listView hasSelection ifFalse:[ |
|
433 |
listView selectFirst |
|
434 |
] ifTrue:[ |
|
435 |
listView selectNext |
|
436 |
]. |
|
437 |
]. |
|
438 |
! |
|
439 |
||
197 | 440 |
updateList |
638 | 441 |
"setup contents of list; |
442 |
nothing done here but typically redefined in subclasses." |
|
197 | 443 |
|
444 |
^ self |
|
638 | 445 |
|
446 |
"Modified: 12.5.1996 / 21:51:10 / cg" |
|
0 | 447 |
! ! |
448 |
||
4298
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
449 |
!ListSelectionBox methodsFor:'private'! |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
450 |
|
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
451 |
filterList |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
452 |
|
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
453 |
| pattern filteredList | |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
454 |
|
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
455 |
pattern := enterField model value. |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
456 |
pattern isEmptyOrNil ifTrue:[ |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
457 |
filteredList := list. |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
458 |
] ifFalse:[ |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
459 |
filteredList := list select:[:each|each asString startsWith: pattern]. |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
460 |
]. |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
461 |
self sensor pushUserEvent: #list: for: selectionList withArgument: filteredList |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
462 |
|
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
463 |
"Created: / 03-08-2011 / 12:27:25 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
464 |
! ! |
331907254f82
added live-search support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
4166
diff
changeset
|
465 |
|
59 | 466 |
!ListSelectionBox methodsFor:'queries'! |
0 | 467 |
|
6506 | 468 |
computePreferredExtent |
5874 | 469 |
"return my preferred extent |
470 |
- that's the minimum size I like to have, to make everything visible" |
|
0 | 471 |
|
2500
fc1ee2b3fa81
ListSelectionBox is at least as wide as its buttonPanel.
Stefan Vogel <sv@exept.de>
parents:
2444
diff
changeset
|
472 |
|wWanted hWanted eH mm bw| |
371 | 473 |
|
474 |
mm := ViewSpacing. |
|
125 | 475 |
|
371 | 476 |
wWanted := mm + labelField width + mm. |
0 | 477 |
(wWanted > width) ifFalse:[ |
371 | 478 |
wWanted := width |
0 | 479 |
]. |
3611
a1654baf3f37
added preferredWidth & preferredHeight
Claus Gittinger <cg@exept.de>
parents:
3048
diff
changeset
|
480 |
bw := buttonPanel preferredWidth. |
2500
fc1ee2b3fa81
ListSelectionBox is at least as wide as its buttonPanel.
Stefan Vogel <sv@exept.de>
parents:
2444
diff
changeset
|
481 |
bw > wWanted ifTrue:[ |
fc1ee2b3fa81
ListSelectionBox is at least as wide as its buttonPanel.
Stefan Vogel <sv@exept.de>
parents:
2444
diff
changeset
|
482 |
wWanted := bw. |
fc1ee2b3fa81
ListSelectionBox is at least as wide as its buttonPanel.
Stefan Vogel <sv@exept.de>
parents:
2444
diff
changeset
|
483 |
]. |
125 | 484 |
|
166 | 485 |
enterField notNil ifTrue:[ |
371 | 486 |
eH := enterField height + mm |
166 | 487 |
] ifFalse:[ |
371 | 488 |
eH := 0 |
166 | 489 |
]. |
371 | 490 |
hWanted := mm + labelField height + |
491 |
eH + |
|
492 |
mm + selectionList height + |
|
3611
a1654baf3f37
added preferredWidth & preferredHeight
Claus Gittinger <cg@exept.de>
parents:
3048
diff
changeset
|
493 |
mm + buttonPanel preferredHeight + |
371 | 494 |
mm - (mm * 2). |
0 | 495 |
|
496 |
(hWanted < height) ifTrue:[ |
|
371 | 497 |
hWanted := height |
0 | 498 |
]. |
59 | 499 |
^ (wWanted @ hWanted) |
166 | 500 |
|
6506 | 501 |
"Created: / 09-11-2018 / 19:56:31 / Claus Gittinger" |
0 | 502 |
! ! |
503 |
||
132 | 504 |
!ListSelectionBox methodsFor:'user actions'! |
505 |
||
2541 | 506 |
actionArgument |
2545 | 507 |
useIndex ifTrue:[ |
2541 | 508 |
^self selectionIndex. |
509 |
]. |
|
510 |
^ super actionArgument |
|
511 |
! |
|
512 |
||
197 | 513 |
doubleClick |
514 |
"doubleClick on an entry is select & ok" |
|
515 |
||
402
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
516 |
enterField notNil ifTrue:[ |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
517 |
enterField contents:(selectionList selectionValue). |
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
518 |
]. |
197 | 519 |
self okPressed |
402
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
520 |
|
ed4a635f43c6
oops - fixed access to non existing enterField (if noEnterField)
Claus Gittinger <cg@exept.de>
parents:
371
diff
changeset
|
521 |
"Modified: 26.2.1996 / 20:05:45 / cg" |
197 | 522 |
! |
523 |
||
132 | 524 |
selectionChanged |
525 |
"selections in list get forwarded to enterfield" |
|
526 |
||
166 | 527 |
enterField notNil ifTrue:[ |
5553 | 528 |
|val| |
529 |
||
530 |
val := selectionList selectionValue. |
|
531 |
(val notEmptyOrNil or:[self clearEntryFieldOnDeselect]) ifTrue:[ |
|
532 |
enterField contents:val |
|
533 |
]. |
|
2261
260a8cd9905d
added a selectionChanged callback
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
534 |
]. |
260a8cd9905d
added a selectionChanged callback
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
535 |
selectionChangeCallback notNil ifTrue:[ |
260a8cd9905d
added a selectionChanged callback
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
536 |
selectionChangeCallback value:selectionList selection |
260a8cd9905d
added a selectionChanged callback
Claus Gittinger <cg@exept.de>
parents:
1281
diff
changeset
|
537 |
]. |
166 | 538 |
|
539 |
"Modified: 26.10.1995 / 17:20:06 / cg" |
|
540 |
! ! |
|
541 |
||
1273 | 542 |
!ListSelectionBox class methodsFor:'documentation'! |
243 | 543 |
|
544 |
version |
|
5553 | 545 |
^ '$Header$' |
4088 | 546 |
! |
547 |
||
548 |
version_CVS |
|
5553 | 549 |
^ '$Header$' |
243 | 550 |
! ! |
5222 | 551 |