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