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