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