1390
|
1 |
ListModelView subclass:#SelectionInListModelView
|
|
2 |
instanceVariableNames:'selection multipleSelectOk actionBlock doubleClickActionBlock
|
|
3 |
clickLine highlightMode useIndex hilightFgColor hilightBgColor
|
|
4 |
hilightLevel hilightFrameColor hilightStyle dragAccessPoint
|
|
5 |
dropTarget dropSource'
|
|
6 |
classVariableNames:'DefaultHilightStyle DefaultHilightBackgroundColor
|
|
7 |
DefaultHilightForegroundColor DefaultHilightLevel
|
|
8 |
DefaultHilightFrameColor'
|
|
9 |
poolDictionaries:''
|
|
10 |
category:'AAA'
|
|
11 |
!
|
|
12 |
|
|
13 |
!SelectionInListModelView class methodsFor:'documentation'!
|
|
14 |
|
|
15 |
documentation
|
|
16 |
"
|
|
17 |
SelectionInListModelView is mostly like SelectionInListView,
|
|
18 |
but derives from the ListModelView and thus the list is kept
|
|
19 |
by the model.
|
|
20 |
|
|
21 |
[Instance variables:]
|
|
22 |
selection <misc> the current selection. nil, a number or collection of numbers
|
|
23 |
multipleSelectOk <Boolean> allow/disallow multiple selections( default:false )
|
|
24 |
actionBlock <Block> action evaluated on single click
|
|
25 |
doubleClickActionBlock <Block> action evaluated on double click
|
|
26 |
clickPosition <Point> internal use
|
|
27 |
highlightMode <Symbol> how to draw the selection
|
|
28 |
useIndex <Boolean> representation of the model selection
|
|
29 |
hilightFgColor <Color>
|
|
30 |
hilightBgColor <Color> how highlighted items are drawn
|
|
31 |
hilightLevel <Integer> level to draw selections (i.e. for 3D effect)
|
|
32 |
hilightFrameColor <Color> rectangle around highlighted items
|
|
33 |
hilightStyle <Boolean> actions on widget are enabled/disabled
|
|
34 |
|
|
35 |
[author:]
|
|
36 |
Claus Atzkern
|
|
37 |
|
|
38 |
[see also:]
|
|
39 |
|
|
40 |
ListModelView
|
|
41 |
HierarchicalListView
|
|
42 |
"
|
|
43 |
|
|
44 |
|
|
45 |
!
|
|
46 |
|
|
47 |
examples
|
|
48 |
"
|
|
49 |
[exBegin]
|
|
50 |
|top list view|
|
|
51 |
|
|
52 |
list := List new.
|
|
53 |
|
|
54 |
1 to:100 do:[:i| list add:('element: ', i printString) ].
|
|
55 |
top := StandardSystemView new; extent:300@300.
|
|
56 |
view := ScrollableView for:SelectionInListModelView miniScroller:true
|
|
57 |
origin:0.0@0.0 corner:1.0@1.0 in:top.
|
|
58 |
view list:list.
|
|
59 |
top open.
|
|
60 |
[exEnd]
|
|
61 |
|
|
62 |
|
|
63 |
[exBegin]
|
|
64 |
|top list view item|
|
|
65 |
|
|
66 |
list := HierarchicalList new.
|
|
67 |
item := HierarchicalItem::Example labeled:'Test'.
|
|
68 |
item expand.
|
|
69 |
list showRoot:false.
|
|
70 |
list root:item.
|
|
71 |
|
|
72 |
top := StandardSystemView new; extent:300@300.
|
|
73 |
view := ScrollableView for:SelectionInListModelView miniScroller:true
|
|
74 |
origin:0.0@0.0 corner:1.0@1.0 in:top.
|
|
75 |
|
|
76 |
view list:list.
|
|
77 |
view doubleClickAction:[:i| (list at:i) toggleExpand ].
|
|
78 |
top open.
|
|
79 |
[exEnd]
|
|
80 |
|
|
81 |
"
|
|
82 |
|
|
83 |
! !
|
|
84 |
|
1409
|
85 |
!SelectionInListModelView class methodsFor:'initialization'!
|
|
86 |
|
|
87 |
initialize
|
|
88 |
"setup the signals
|
|
89 |
"
|
|
90 |
super initialize.
|
|
91 |
|
|
92 |
DefaultHilightLevel isNil ifTrue:[
|
|
93 |
self updateStyleCache
|
|
94 |
].
|
|
95 |
|
|
96 |
|
|
97 |
! !
|
|
98 |
|
1390
|
99 |
!SelectionInListModelView class methodsFor:'defaults'!
|
|
100 |
|
|
101 |
updateStyleCache
|
|
102 |
"extract values from the styleSheet and cache them in class variables"
|
|
103 |
|
|
104 |
<resource: #style (
|
|
105 |
#'selection.hilightForegroundColor' #'selection.hilightBackgroundColor'
|
|
106 |
#'selection.hilightFrameColor' #'selection.hilightLevel'
|
|
107 |
#'selection.foregroundColor' #'selection.backgroundColor'
|
|
108 |
#'selection.shadowColor' #'selection.lightColor'
|
|
109 |
#'selection.font' #'selection.hilightStyle'
|
|
110 |
#'text.foregroundColor'
|
|
111 |
)>
|
|
112 |
|
|
113 |
DefaultHilightForegroundColor := StyleSheet colorAt:'selection.hilightForegroundColor'.
|
|
114 |
DefaultHilightBackgroundColor := StyleSheet colorAt:'selection.hilightBackgroundColor'.
|
|
115 |
DefaultHilightFrameColor := StyleSheet colorAt:'selection.hilightFrameColor'.
|
|
116 |
DefaultHilightLevel := StyleSheet at:'selection.hilightLevel' default:0.
|
|
117 |
DefaultHilightStyle := StyleSheet at:'selection.hilightStyle' default:(StyleSheet name).
|
|
118 |
DefaultForegroundColor := StyleSheet colorAt:'selection.foregroundColor'.
|
|
119 |
DefaultBackgroundColor := StyleSheet colorAt:'selection.backgroundColor'.
|
|
120 |
DefaultShadowColor := StyleSheet colorAt:'selection.shadowColor'.
|
|
121 |
DefaultLightColor := StyleSheet colorAt:'selection.lightColor'.
|
|
122 |
|
|
123 |
DefaultForegroundColor isNil ifTrue:[
|
|
124 |
DefaultForegroundColor := StyleSheet colorAt:'text.foregroundColor' default:Black
|
|
125 |
].
|
|
126 |
"
|
|
127 |
self updateStyleCache
|
|
128 |
"
|
|
129 |
|
|
130 |
|
|
131 |
! !
|
|
132 |
|
|
133 |
!SelectionInListModelView methodsFor:'accessing'!
|
|
134 |
|
|
135 |
list:aList
|
|
136 |
"get the status of <showRoot> from the list
|
|
137 |
"
|
|
138 |
selection notNil ifTrue:[
|
|
139 |
selection := nil.
|
|
140 |
self selectionChanged.
|
|
141 |
].
|
|
142 |
^ super list:aList
|
|
143 |
! !
|
|
144 |
|
|
145 |
!SelectionInListModelView methodsFor:'accessing behavior'!
|
|
146 |
|
|
147 |
highlightMode
|
|
148 |
"get the mode how to draw a selected line:
|
|
149 |
#line draw whole line selected
|
|
150 |
#label draw label selected
|
|
151 |
"
|
|
152 |
^ highlightMode
|
|
153 |
|
|
154 |
|
|
155 |
!
|
|
156 |
|
|
157 |
highlightMode:aMode
|
|
158 |
"set the mode how to draw a selected line:
|
|
159 |
#line draw whole line selected
|
|
160 |
#label draw label selected
|
|
161 |
"
|
|
162 |
(aMode ~~ highlightMode and:[(aMode == #label or:[aMode == #line])]) ifTrue:[
|
|
163 |
highlightMode := aMode.
|
|
164 |
|
|
165 |
shown ifTrue:[
|
|
166 |
self selectionDo:[:i|self redrawSelectionAt:i]
|
|
167 |
]
|
|
168 |
]
|
|
169 |
|
|
170 |
!
|
|
171 |
|
|
172 |
multipleSelectOk
|
|
173 |
"allow/disallow multiple selections; the default is false
|
|
174 |
"
|
|
175 |
^ multipleSelectOk
|
|
176 |
|
|
177 |
|
|
178 |
!
|
|
179 |
|
|
180 |
multipleSelectOk:aState
|
|
181 |
"allow/disallow multiple selections; the default is false
|
|
182 |
"
|
|
183 |
aState == multipleSelectOk ifFalse:[
|
|
184 |
multipleSelectOk := aState.
|
|
185 |
selection notNil ifTrue:[
|
|
186 |
multipleSelectOk ifTrue:[
|
|
187 |
selection := Array with:selection
|
|
188 |
] ifFalse:[
|
|
189 |
selection size ~~ 1 ifTrue:[
|
|
190 |
selection := nil.
|
|
191 |
self invalidate.
|
|
192 |
self selectionChanged
|
|
193 |
] ifFalse:[
|
|
194 |
selection := selection at:1
|
|
195 |
]
|
|
196 |
]
|
|
197 |
]
|
|
198 |
]
|
|
199 |
|
|
200 |
!
|
|
201 |
|
|
202 |
useIndex
|
|
203 |
"set/clear the useIndex flag.
|
|
204 |
the selection writen to the model are the indices into the list
|
|
205 |
or the elements selected.
|
|
206 |
"
|
|
207 |
^ useIndex
|
|
208 |
|
|
209 |
|
|
210 |
!
|
|
211 |
|
|
212 |
useIndex:aBoolean
|
|
213 |
"set/clear the useIndex flag.
|
|
214 |
the selection writen to the model are the indices into the list
|
|
215 |
or the elements selected.
|
|
216 |
"
|
|
217 |
useIndex := aBoolean ? true
|
|
218 |
|
|
219 |
|
|
220 |
! !
|
|
221 |
|
|
222 |
!SelectionInListModelView methodsFor:'actions'!
|
|
223 |
|
|
224 |
action:aOneArgAction
|
|
225 |
"set the action block to be performed on select
|
|
226 |
"
|
|
227 |
actionBlock := aOneArgAction
|
|
228 |
|
|
229 |
|
|
230 |
!
|
|
231 |
|
|
232 |
doubleClickAction:aOneArgAction
|
|
233 |
"set the action block to be performed on doubleclick
|
|
234 |
"
|
|
235 |
doubleClickActionBlock := aOneArgAction
|
|
236 |
|
|
237 |
|
|
238 |
! !
|
|
239 |
|
|
240 |
!SelectionInListModelView methodsFor:'change & update'!
|
|
241 |
|
|
242 |
argForChangeMessage
|
|
243 |
"return the argument for a selectionChange;
|
|
244 |
depending on the setting of useIndex, this is either the numeric
|
|
245 |
index of the selection or the value (i.e. the string)
|
|
246 |
"
|
|
247 |
useIndex ifFalse:[
|
|
248 |
^ self selectionValue
|
|
249 |
].
|
|
250 |
selection isNil ifTrue:[
|
|
251 |
^ multipleSelectOk ifTrue:[#()] ifFalse:[0]
|
|
252 |
].
|
|
253 |
^ multipleSelectOk ifTrue:[selection copy] ifFalse:[selection]
|
|
254 |
!
|
|
255 |
|
|
256 |
getSelectionFromModel
|
|
257 |
"get selection from model; returns a selection or nil
|
|
258 |
"
|
|
259 |
|value newSel|
|
|
260 |
|
|
261 |
( model isNil
|
|
262 |
or:[(value := model value) isNil
|
|
263 |
or:[value == 0]]
|
|
264 |
) ifTrue:[
|
|
265 |
^ nil
|
|
266 |
].
|
|
267 |
|
|
268 |
multipleSelectOk ifFalse:[
|
|
269 |
useIndex ifFalse:[
|
|
270 |
(value := self identityIndexOf:value) == 0 ifTrue:[
|
|
271 |
^ nil
|
|
272 |
]
|
|
273 |
].
|
|
274 |
^ value
|
|
275 |
].
|
|
276 |
|
|
277 |
"/ MULTI SELECT
|
|
278 |
|
|
279 |
value isEmpty ifTrue:[^ nil].
|
|
280 |
useIndex ifTrue:[^ value].
|
|
281 |
|
|
282 |
newSel := OrderedCollection new.
|
|
283 |
|
|
284 |
value do:[:el||index|
|
|
285 |
(index := self identityIndexOf:el) ~~ 0 ifTrue:[
|
|
286 |
newSel add:index
|
|
287 |
]
|
|
288 |
].
|
|
289 |
|
|
290 |
^ newSel notEmpty ifTrue:[newSel] ifFalse:[nil]
|
|
291 |
!
|
|
292 |
|
|
293 |
listSizeChanged:aLnNr nLines:aDeltaLines
|
|
294 |
"update selection
|
|
295 |
"
|
|
296 |
|newSel noChg size changed|
|
|
297 |
|
|
298 |
super listSizeChanged:aLnNr nLines:aDeltaLines.
|
|
299 |
|
|
300 |
selection isNil ifTrue:[^ self].
|
|
301 |
|
|
302 |
list size == 0 ifTrue:[
|
|
303 |
^ self deselectWithoutRedraw
|
|
304 |
].
|
|
305 |
multipleSelectOk ifFalse:[
|
|
306 |
selection >= aLnNr ifTrue:[
|
|
307 |
selection := selection + aDeltaLines.
|
|
308 |
|
|
309 |
(aDeltaLines < 0 and:[selection < aLnNr]) ifTrue:[
|
|
310 |
self deselectWithoutRedraw
|
|
311 |
] ifFalse:[
|
|
312 |
(model notNil and:[useIndex]) ifTrue:[
|
|
313 |
model setValue:selection
|
|
314 |
]
|
|
315 |
]
|
|
316 |
].
|
|
317 |
^ self
|
|
318 |
].
|
|
319 |
|
|
320 |
size := selection size.
|
|
321 |
changed := false.
|
|
322 |
|
|
323 |
aDeltaLines < 0 ifFalse:[
|
|
324 |
1 to:size do:[:anIndex|
|
|
325 |
newSel := selection at:anIndex.
|
|
326 |
|
|
327 |
newSel >= aLnNr ifTrue:[
|
|
328 |
changed := true.
|
|
329 |
selection at:anIndex put:(newSel + aDeltaLines)
|
|
330 |
]
|
|
331 |
].
|
|
332 |
(changed and:[useIndex and:[model notNil]]) ifTrue:[
|
|
333 |
model setValue:(selection copy)
|
|
334 |
].
|
|
335 |
^ self
|
|
336 |
].
|
|
337 |
noChg := 0.
|
|
338 |
|
|
339 |
1 to:size do:[:anIndex|
|
|
340 |
newSel := selection at:anIndex.
|
|
341 |
|
|
342 |
newSel >= aLnNr ifTrue:[
|
|
343 |
newSel := newSel + aDeltaLines.
|
|
344 |
changed := true.
|
|
345 |
|
|
346 |
newSel < aLnNr ifTrue:[
|
|
347 |
noChg := noChg + 1.
|
|
348 |
newSel := 0.
|
|
349 |
].
|
|
350 |
selection at:anIndex put:newSel
|
|
351 |
]
|
|
352 |
].
|
|
353 |
|
|
354 |
noChg ~~ 0 ifTrue:[
|
|
355 |
noChg == size ifTrue:[
|
|
356 |
self deselectWithoutRedraw
|
|
357 |
] ifFalse:[
|
|
358 |
selection := selection select:[:i| i ~~ 0].
|
|
359 |
self selectionChanged
|
|
360 |
]
|
|
361 |
] ifFalse:[
|
|
362 |
(changed and:[useIndex and:[model notNil]]) ifTrue:[
|
|
363 |
model setValue:(selection copy)
|
|
364 |
]
|
|
365 |
]
|
|
366 |
|
|
367 |
!
|
|
368 |
|
|
369 |
selectionChanged
|
|
370 |
"selection has changed. Call actionblock and/or send changeMessage if defined
|
|
371 |
"
|
|
372 |
|value arg|
|
|
373 |
|
|
374 |
(model isNil and:[actionBlock isNil]) ifTrue:[
|
|
375 |
^ self
|
|
376 |
].
|
|
377 |
|
|
378 |
arg := self argForChangeMessage.
|
|
379 |
|
|
380 |
model notNil ifTrue:[
|
|
381 |
model removeDependent:self.
|
|
382 |
self sendChangeMessage:#value: with:arg.
|
|
383 |
model addDependent:self.
|
|
384 |
].
|
|
385 |
|
|
386 |
actionBlock notNil ifTrue:[
|
|
387 |
(actionBlock numArgs) == 1 ifTrue:[
|
|
388 |
actionBlock value:arg
|
|
389 |
] ifFalse:[
|
|
390 |
actionBlock value
|
|
391 |
]
|
|
392 |
].
|
|
393 |
|
|
394 |
!
|
|
395 |
|
|
396 |
update:something with:aParameter from:changedObject
|
|
397 |
"one of my models changed
|
|
398 |
"
|
|
399 |
|newSelection|
|
|
400 |
|
|
401 |
changedObject == model ifTrue:[
|
|
402 |
newSelection := self getSelectionFromModel.
|
|
403 |
|
|
404 |
newSelection ~= selection ifTrue:[
|
|
405 |
self setSelection:newSelection
|
|
406 |
]
|
|
407 |
] ifFalse:[
|
|
408 |
super update:something with:aParameter from:changedObject
|
|
409 |
].
|
|
410 |
! !
|
|
411 |
|
|
412 |
!SelectionInListModelView methodsFor:'drag & drop'!
|
|
413 |
|
|
414 |
canDrag
|
|
415 |
"returns true if dragging is enabled
|
|
416 |
"
|
|
417 |
^ dropSource notNil
|
|
418 |
|
|
419 |
!
|
|
420 |
|
|
421 |
dropSource
|
|
422 |
"returns the dropSource or nil
|
|
423 |
"
|
|
424 |
^ dropSource
|
|
425 |
|
|
426 |
!
|
|
427 |
|
|
428 |
dropSource:aDropSourceOrNil
|
|
429 |
"set the dropSource or nil
|
|
430 |
"
|
|
431 |
dropSource := aDropSourceOrNil.
|
|
432 |
|
|
433 |
!
|
|
434 |
|
|
435 |
dropTarget
|
|
436 |
"returns the dropTarget or nil
|
|
437 |
"
|
|
438 |
^ dropTarget
|
|
439 |
|
|
440 |
|
|
441 |
!
|
|
442 |
|
|
443 |
dropTarget:aDropTragetOrNil
|
|
444 |
"set the dropTarget or nil
|
|
445 |
"
|
|
446 |
dropTarget := aDropTragetOrNil.
|
|
447 |
|
|
448 |
!
|
|
449 |
|
|
450 |
startDragAt:aPoint
|
|
451 |
"start drag at a point
|
|
452 |
"
|
|
453 |
dropSource notNil ifTrue:[
|
|
454 |
dropSource startDragSelector notNil ifTrue:[
|
|
455 |
dropSource startDragIn:self at:aPoint
|
|
456 |
] ifFalse:[
|
|
457 |
DragAndDropManager new startDragFrom:self
|
|
458 |
dropSource:dropSource
|
|
459 |
offset:#center
|
|
460 |
]
|
|
461 |
]
|
|
462 |
|
|
463 |
! !
|
|
464 |
|
|
465 |
!SelectionInListModelView methodsFor:'drawing'!
|
|
466 |
|
1399
|
467 |
drawFrom:start to:stop x:xL y:yT toX:xR
|
1390
|
468 |
"draw the lines between start to stop without clearing the background
|
|
469 |
"
|
|
470 |
|selY selH
|
1399
|
471 |
w "{ Class:SmallInteger }"
|
1390
|
472 |
y0 "{ Class:SmallInteger }"
|
|
473 |
y1 "{ Class:SmallInteger }"
|
|
474 |
hg "{ Class:SmallInteger }"
|
|
475 |
|
|
1399
|
476 |
w := xR - xL.
|
|
477 |
|
1390
|
478 |
(highlightMode == #line and:[selection notNil]) ifTrue:[
|
|
479 |
"/ redraw the background for all selected lines in the invalid range
|
|
480 |
|
|
481 |
self selectionDo:[:lnNr|
|
|
482 |
(lnNr between:start and:stop) ifTrue:[
|
|
483 |
selY isNil ifTrue:[
|
|
484 |
selY := OrderedCollection new.
|
|
485 |
selH := OrderedCollection new.
|
|
486 |
self paint:hilightBgColor.
|
|
487 |
].
|
|
488 |
y0 := self yVisibleOfLine:lnNr.
|
|
489 |
y1 := self yVisibleOfLine:(lnNr + 1).
|
|
490 |
hg := y1 - y0.
|
|
491 |
selY add:y0.
|
|
492 |
selH add:hg.
|
1399
|
493 |
self fillRectangleX:xL y:y0 width:w height:hg.
|
1390
|
494 |
]
|
|
495 |
]
|
|
496 |
].
|
1399
|
497 |
self drawElementsFrom:start to:stop x:xL y:yT toX:xR.
|
1390
|
498 |
|
|
499 |
"/ draw selection frames
|
|
500 |
selY notNil ifTrue:[
|
|
501 |
1 to:selY size do:[:i|
|
1399
|
502 |
self drawSelectionFrameAtX:xL y:(selY at:i) width:w h:(selH at:i)
|
1390
|
503 |
]
|
|
504 |
].
|
|
505 |
|
|
506 |
|
|
507 |
|
|
508 |
!
|
|
509 |
|
1399
|
510 |
drawLabelAt:anIndex x:xL y:yT toX:xR y:yB
|
1390
|
511 |
"draw the label at position x/y without clearing the background
|
|
512 |
"
|
|
513 |
|label item
|
|
514 |
w "{ Class:SmallInteger }"
|
1399
|
515 |
h "{ Class:SmallInteger }"
|
1390
|
516 |
x0 "{ Class:SmallInteger }"
|
|
517 |
|
|
|
518 |
item := list at:anIndex ifAbsent:[^ self].
|
|
519 |
|
|
520 |
(self isInSelection:anIndex) ifTrue:[
|
|
521 |
highlightMode == #label ifTrue:[
|
|
522 |
w := (item widthOn:self) + textStartLeft.
|
1399
|
523 |
h := yB - yT.
|
|
524 |
x0 := xL - (textStartLeft // 2).
|
1390
|
525 |
self paint:hilightBgColor.
|
1399
|
526 |
self fillRectangleX:x0 y:yT width:w height:h.
|
|
527 |
self drawSelectionFrameAtX:x0 y:yT width:w h:h.
|
1390
|
528 |
].
|
|
529 |
self paint:hilightFgColor on:hilightBgColor
|
|
530 |
] ifFalse:[
|
|
531 |
self paint:fgColor on:bgColor.
|
|
532 |
].
|
1399
|
533 |
self displayElement:item x:xL y:yT toX:xR y:yB.
|
1390
|
534 |
|
|
535 |
|
|
536 |
!
|
|
537 |
|
|
538 |
drawSelectionFrameAtX:x0 y:y0 width:w h:h
|
|
539 |
"redraw selection frame for a line
|
|
540 |
"
|
|
541 |
|
|
|
542 |
x1 "{ Class: SmallInteger }"
|
|
543 |
x "{ Class: SmallInteger }"
|
|
544 |
y "{ Class: SmallInteger }"
|
|
545 |
|
|
|
546 |
x1 := x0 + w.
|
|
547 |
|
|
548 |
hilightFrameColor notNil ifTrue:[
|
|
549 |
hilightLevel == 0 ifTrue:[
|
|
550 |
self paint:hilightFrameColor.
|
|
551 |
|
|
552 |
highlightMode == #line ifTrue:[
|
|
553 |
self displayLineFromX:x0 y:y0 toX:x1 y:y0.
|
|
554 |
y := y0 + h - 1.
|
|
555 |
self displayLineFromX:x0 y:y toX:x1 y:y.
|
|
556 |
] ifFalse:[
|
|
557 |
self displayRectangleX:x0 y:y0 width:w height:h
|
|
558 |
].
|
|
559 |
^ self.
|
|
560 |
]
|
|
561 |
] ifFalse:[
|
|
562 |
hilightStyle == #motif ifTrue:[
|
|
563 |
self paint:bgColor.
|
|
564 |
y := y0 + 1.
|
|
565 |
highlightMode == #line ifTrue:[
|
|
566 |
self displayLineFromX:x0 y:y toX:x1 y:y.
|
|
567 |
y := y0 + h - 2.
|
|
568 |
self displayLineFromX:x0 y:y toX:x1 y:y.
|
|
569 |
] ifFalse:[
|
|
570 |
self displayRectangleX:x0 + 1 y:y width:w - 2 height:h - 2
|
|
571 |
]
|
|
572 |
]
|
|
573 |
].
|
|
574 |
|
|
575 |
hilightLevel ~~ 0 ifTrue:[
|
|
576 |
"/ draw edge
|
|
577 |
highlightMode == #line ifTrue:[
|
|
578 |
x := margin.
|
|
579 |
x1 := width - x - x.
|
|
580 |
] ifFalse:[
|
|
581 |
x := x0.
|
|
582 |
x1 := w.
|
|
583 |
].
|
|
584 |
self drawEdgesForX:x y:y0 width:x1 height:h level:hilightLevel.
|
|
585 |
]
|
|
586 |
|
|
587 |
!
|
|
588 |
|
|
589 |
redrawSelectionAt:anIndex
|
|
590 |
"called to redraw a line caused by a change of the selection
|
|
591 |
"
|
|
592 |
|item
|
|
593 |
h "{ Class:SmallInteger }"
|
|
594 |
y0 "{ Class:SmallInteger }"
|
|
595 |
y1 "{ Class:SmallInteger }"
|
|
596 |
|
|
|
597 |
shown ifFalse:[^ self].
|
|
598 |
|
|
599 |
y0 := (self yVisibleOfLine:anIndex) max:margin.
|
|
600 |
y1 := (self yVisibleOfLine:(anIndex + 1)) min:(height - margin).
|
|
601 |
|
|
602 |
(h := y1 - y0) > 0 ifTrue:[
|
|
603 |
( highlightMode == #label
|
|
604 |
and:[(item := list at:anIndex ifAbsent:nil) notNil]
|
|
605 |
) ifTrue:[
|
|
606 |
self redrawLabelFromItem:item atY:y0 h:h
|
|
607 |
] ifFalse:[
|
1399
|
608 |
self redrawX:margin y:y0 width:(self innerWidth) height:h
|
1390
|
609 |
]
|
|
610 |
]
|
|
611 |
! !
|
|
612 |
|
|
613 |
!SelectionInListModelView methodsFor:'event handling'!
|
|
614 |
|
|
615 |
buttonMotion:buttonMask x:x y:y
|
|
616 |
"mouse-move while button was pressed - handle selection changes
|
|
617 |
"
|
|
618 |
|sensor idx p cY oY lnNr h|
|
|
619 |
|
|
620 |
(enabled and:[selection notNil]) ifFalse:[^ self].
|
|
621 |
|
|
622 |
dragAccessPoint notNil ifTrue:[
|
|
623 |
p := x @ y.
|
|
624 |
|
|
625 |
(dragAccessPoint dist:p) > 5.0 ifTrue:[
|
|
626 |
dragAccessPoint := nil.
|
|
627 |
self startDragAt:p
|
|
628 |
].
|
|
629 |
^ self
|
|
630 |
].
|
|
631 |
|
|
632 |
(multipleSelectOk and:[self sensor leftButtonPressed]) ifFalse:[
|
|
633 |
^ self
|
|
634 |
].
|
|
635 |
|
|
636 |
clickLine isNil ifTrue:[
|
|
637 |
^ self
|
|
638 |
].
|
|
639 |
cY := self yVisibleOfLine:clickLine.
|
|
640 |
oY := cY.
|
|
641 |
|
|
642 |
y < cY ifTrue:[
|
|
643 |
(lnNr := clickLine - 1) == 0 ifTrue:[^ self].
|
|
644 |
cY := self yVisibleOfLine:lnNr.
|
|
645 |
h := oY - cY.
|
|
646 |
] ifFalse:[
|
|
647 |
( (lnNr := clickLine + 1) > list size
|
|
648 |
or:[(cY := self yVisibleOfLine:lnNr) > y]
|
|
649 |
) ifTrue:[
|
|
650 |
^ self
|
|
651 |
].
|
|
652 |
h := cY - oY.
|
|
653 |
].
|
|
654 |
selection := selection asOrderedCollection.
|
|
655 |
|
|
656 |
(selection removeIdentical:lnNr ifAbsent:nil) isNil ifTrue:[
|
|
657 |
selection add:lnNr
|
|
658 |
].
|
|
659 |
clickLine := lnNr.
|
|
660 |
|
|
661 |
(cY between:margin and:(height - h)) ifTrue:[
|
|
662 |
self redrawSelectionAt:lnNr
|
|
663 |
] ifFalse:[
|
|
664 |
self scrollToLine:lnNr.
|
|
665 |
].
|
|
666 |
self selectionChanged
|
|
667 |
|
|
668 |
!
|
|
669 |
|
|
670 |
buttonMultiPress:button x:x y:y
|
|
671 |
"button was pressed multiple - handle a doubleClick action
|
|
672 |
"
|
|
673 |
clickLine := nil.
|
|
674 |
dragAccessPoint := nil.
|
|
675 |
|
|
676 |
enabled ifFalse:[^ self].
|
|
677 |
|
|
678 |
((button == 1) or:[button == #select]) ifFalse:[
|
|
679 |
^ super buttonMultiPress:button x:x y:y
|
|
680 |
].
|
|
681 |
self doubleClicked
|
|
682 |
!
|
|
683 |
|
|
684 |
buttonPress:button x:x y:y
|
|
685 |
"a button was pressed - handle selection here
|
|
686 |
"
|
|
687 |
|lnNr sensor start step list changed|
|
|
688 |
|
|
689 |
clickLine := nil.
|
|
690 |
dragAccessPoint := nil.
|
|
691 |
|
|
692 |
enabled ifFalse:[^ self].
|
|
693 |
|
|
694 |
(button == 1 or:[button == #select]) ifFalse:[
|
|
695 |
^ super buttonPress:button x:x y:y
|
|
696 |
].
|
|
697 |
|
|
698 |
(lnNr := self yVisibleToLineNr:y) isNil ifTrue:[
|
|
699 |
^ self
|
|
700 |
].
|
|
701 |
clickLine := lnNr.
|
|
702 |
|
|
703 |
(multipleSelectOk and:[(sensor := self sensor) notNil]) ifTrue:[
|
|
704 |
sensor ctrlDown ifTrue:[
|
|
705 |
(self isInSelection:lnNr) ifTrue:[self removeFromSelection:lnNr]
|
|
706 |
ifFalse:[self addToSelection:lnNr].
|
|
707 |
^ self selectionChanged
|
|
708 |
|
|
709 |
].
|
|
710 |
(selection notNil and:[sensor shiftDown]) ifTrue:[
|
|
711 |
start := selection at:1.
|
|
712 |
step := lnNr < start ifTrue:[-1] ifFalse:[1].
|
|
713 |
list := selection.
|
|
714 |
selection := OrderedCollection new.
|
|
715 |
changed := false.
|
|
716 |
|
|
717 |
start to:lnNr by:step do:[:i|
|
|
718 |
selection add:i.
|
|
719 |
(list identityIndexOf:i) == 0 ifTrue:[
|
|
720 |
changed := true.
|
|
721 |
self redrawSelectionAt:i "/ redraw selected
|
|
722 |
]
|
|
723 |
].
|
|
724 |
list do:[:i|
|
|
725 |
(selection identityIndexOf:i) == 0 ifTrue:[
|
|
726 |
changed := true.
|
|
727 |
self redrawSelectionAt:i "/ redraw unselected
|
|
728 |
].
|
|
729 |
].
|
|
730 |
changed ifTrue:[
|
|
731 |
self selectionChanged
|
|
732 |
].
|
|
733 |
^ self
|
|
734 |
]
|
|
735 |
].
|
|
736 |
|
|
737 |
(self canDrag and:[self isInSelection:lnNr]) ifTrue:[
|
|
738 |
dragAccessPoint := x @ y
|
|
739 |
] ifFalse:[
|
|
740 |
self selectedIndex ~~ lnNr ifTrue:[
|
|
741 |
self selectWithoutScroll:lnNr.
|
|
742 |
self selectionChanged
|
|
743 |
]
|
|
744 |
]
|
|
745 |
!
|
|
746 |
|
|
747 |
buttonRelease:button x:x y:y
|
|
748 |
"a button was released
|
|
749 |
"
|
|
750 |
enabled ifTrue:[
|
|
751 |
(dragAccessPoint notNil and:[clickLine notNil]) ifTrue:[
|
|
752 |
self selectedIndex ~~ clickLine ifTrue:[
|
|
753 |
self selectWithoutScroll:clickLine.
|
|
754 |
self selectionChanged
|
|
755 |
]
|
|
756 |
]
|
|
757 |
].
|
|
758 |
clickLine := nil.
|
|
759 |
dragAccessPoint := nil.
|
|
760 |
|
|
761 |
|
|
762 |
!
|
|
763 |
|
|
764 |
characterPress:aKey x:x y:y
|
|
765 |
" a character is pressed - lookup and change selection
|
|
766 |
"
|
|
767 |
|lnNr size idx sensor stp to1 fr2|
|
|
768 |
|
|
769 |
(enabled and:[(size := self size) > 1]) ifFalse:[
|
|
770 |
^ self
|
|
771 |
].
|
|
772 |
lnNr := self firstInSelection ? 0.
|
|
773 |
|
|
774 |
((sensor := self sensor) notNil and:[sensor shiftDown]) ifTrue:[
|
|
775 |
stp := -1. "/ search backward
|
|
776 |
to1 := 1.
|
|
777 |
fr2 := size.
|
|
778 |
] ifFalse:[
|
|
779 |
stp := 1. "/ search forward
|
|
780 |
to1 := size.
|
|
781 |
fr2 := 1.
|
|
782 |
].
|
|
783 |
|
|
784 |
idx := self findLineFrom:lnNr+stp to:to1 by:stp startingWithCharacter:aKey.
|
|
785 |
|
|
786 |
idx == 0 ifTrue:[
|
|
787 |
idx := self findLineFrom:fr2 to:lnNr-stp by:stp startingWithCharacter:aKey
|
|
788 |
].
|
|
789 |
idx ~~ 0 ifTrue:[^ self selection:idx]
|
|
790 |
!
|
|
791 |
|
|
792 |
doubleClicked
|
|
793 |
"handle a double click
|
|
794 |
"
|
|
795 |
(doubleClickActionBlock notNil and:[self numberOfSelections == 1]) ifTrue:[
|
|
796 |
(doubleClickActionBlock numArgs == 1) ifTrue:[
|
|
797 |
doubleClickActionBlock value:(self selectedIndex)
|
|
798 |
] ifFalse:[
|
|
799 |
doubleClickActionBlock value
|
|
800 |
]
|
|
801 |
]
|
|
802 |
|
|
803 |
!
|
|
804 |
|
|
805 |
findLineFrom:aStart to:aStop by:aStep startingWithCharacter:aCharacter
|
|
806 |
"find a line starting with a character
|
|
807 |
"
|
|
808 |
|item char lbl cmp
|
|
809 |
size "{ Class:SmallInteger }"
|
|
810 |
start "{ Class:SmallInteger }"
|
|
811 |
stop "{ Class:SmallInteger }"
|
|
812 |
|
|
|
813 |
(size := list size) ~~ 0 ifTrue:[
|
|
814 |
aStep > 0 ifTrue:[
|
|
815 |
aStart > aStop ifTrue:[^ 0].
|
|
816 |
] ifFalse:[
|
|
817 |
(aStep == 0 or:[aStop > aStart]) ifTrue:[^ 0]
|
|
818 |
].
|
|
819 |
|
|
820 |
start := aStart < 0 ifTrue:[1] ifFalse:[aStart min:size].
|
|
821 |
stop := aStop < 0 ifTrue:[1] ifFalse:[aStop min:size].
|
|
822 |
char := aCharacter asUppercase.
|
|
823 |
|
|
824 |
start to:stop by:aStep do:[:anIndex|
|
|
825 |
item := list at:anIndex ifAbsent:[^ 0]. "/ list changed
|
|
826 |
lbl := item perform:#string ifNotUnderstood:nil.
|
|
827 |
|
|
828 |
lbl notNil ifTrue:[
|
|
829 |
cmp := lbl string at:1 ifAbsent:nil.
|
|
830 |
|
|
831 |
cmp notNil ifTrue:[
|
|
832 |
(char == cmp or:[char == cmp asUppercase]) ifTrue:[
|
|
833 |
^ anIndex
|
|
834 |
]
|
|
835 |
]
|
|
836 |
]
|
|
837 |
]
|
|
838 |
].
|
|
839 |
^ 0
|
|
840 |
|
|
841 |
|
|
842 |
!
|
|
843 |
|
|
844 |
keyPress:aKey x:x y:y
|
|
845 |
"a key was pressed - handle page-keys here
|
|
846 |
"
|
|
847 |
<resource: #keyboard( #Return #CursorUp #CursorDown )>
|
|
848 |
|
|
849 |
|sensor n size lineNr|
|
|
850 |
|
|
851 |
enabled ifFalse:[
|
|
852 |
^ super keyPress:aKey x:x y:y
|
|
853 |
].
|
|
854 |
aKey == #Return ifTrue:[
|
|
855 |
self numberOfSelections == 1 ifTrue:[self doubleClicked].
|
|
856 |
^ self
|
|
857 |
].
|
|
858 |
|
|
859 |
aKey isCharacter ifTrue:[
|
|
860 |
^ self characterPress:aKey x:x y:y
|
|
861 |
].
|
|
862 |
|
|
863 |
(aKey == #CursorUp or:[aKey == #CursorDown]) ifFalse:[
|
|
864 |
^ super keyPress:aKey x:x y:y
|
|
865 |
].
|
|
866 |
|
|
867 |
(size := self size) == 0 ifTrue:[
|
|
868 |
^ self
|
|
869 |
].
|
|
870 |
|
|
871 |
lineNr := self selectedIndex.
|
|
872 |
sensor := self sensor.
|
|
873 |
|
|
874 |
sensor notNil ifTrue:[
|
|
875 |
n := (1 + (sensor compressKeyPressEventsWithKey:aKey)) \\ size.
|
|
876 |
n == 0 ifTrue:[^ self].
|
|
877 |
] ifFalse:[
|
|
878 |
n := 1
|
|
879 |
].
|
|
880 |
|
|
881 |
aKey == #CursorUp ifTrue:[
|
|
882 |
lineNr == 0 ifTrue:[lineNr := size + 1].
|
|
883 |
(n := lineNr - n) <= 0 ifTrue:[n := size + n]
|
|
884 |
] ifFalse:[
|
|
885 |
(n := lineNr + n) > size ifTrue:[n := n - size]
|
|
886 |
].
|
|
887 |
self selection:n
|
|
888 |
! !
|
|
889 |
|
|
890 |
!SelectionInListModelView methodsFor:'initialize / release'!
|
|
891 |
|
|
892 |
fetchResources
|
|
893 |
"fetch device colors and ..., to avoid reallocation at redraw time;
|
|
894 |
*** called after a create or snapin to fetch all device resources
|
|
895 |
"
|
|
896 |
|
|
897 |
super fetchResources.
|
|
898 |
|
|
899 |
hilightFgColor := self colorOnDevice:hilightFgColor.
|
|
900 |
hilightBgColor := self colorOnDevice:hilightBgColor.
|
|
901 |
hilightFrameColor := self colorOnDevice:hilightFrameColor.
|
|
902 |
!
|
|
903 |
|
|
904 |
initStyle
|
|
905 |
"setup viewStyle specifics
|
|
906 |
"
|
|
907 |
|h|
|
|
908 |
|
|
909 |
super initStyle.
|
|
910 |
|
|
911 |
hilightFrameColor := nil.
|
|
912 |
hilightLevel := 0.
|
|
913 |
hilightStyle := DefaultHilightStyle.
|
|
914 |
highlightMode := #line.
|
|
915 |
textStartLeft := 4.
|
|
916 |
|
|
917 |
device hasGrayscales ifTrue:[
|
|
918 |
"
|
|
919 |
must get rid of these hard codings
|
|
920 |
"
|
|
921 |
(hilightStyle == #next) ifTrue:[
|
|
922 |
hilightFgColor := fgColor.
|
|
923 |
hilightBgColor := White.
|
|
924 |
hilightFrameColor := fgColor
|
|
925 |
] ifFalse:[
|
|
926 |
(hilightStyle == #motif) ifTrue:[
|
|
927 |
fgColor := White.
|
|
928 |
bgColor := Grey.
|
|
929 |
viewBackground := bgColor.
|
|
930 |
hilightFgColor := bgColor.
|
|
931 |
hilightBgColor := fgColor.
|
|
932 |
] ifFalse:[
|
|
933 |
(hilightStyle == #openwin) ifTrue:[
|
|
934 |
hilightFgColor := fgColor.
|
|
935 |
hilightBgColor := Color grey.
|
|
936 |
]
|
|
937 |
]
|
|
938 |
]
|
|
939 |
].
|
|
940 |
|
|
941 |
hilightFgColor isNil ifTrue:[
|
|
942 |
hilightFgColor := bgColor.
|
|
943 |
].
|
|
944 |
hilightBgColor isNil ifTrue:[
|
|
945 |
hilightBgColor := fgColor.
|
|
946 |
].
|
|
947 |
DefaultForegroundColor notNil ifTrue:[
|
|
948 |
fgColor := DefaultForegroundColor
|
|
949 |
].
|
|
950 |
DefaultBackgroundColor notNil ifTrue:[
|
|
951 |
bgColor := viewBackground := DefaultBackgroundColor
|
|
952 |
].
|
|
953 |
|
|
954 |
DefaultHilightForegroundColor notNil ifTrue:[
|
|
955 |
hilightFgColor := DefaultHilightForegroundColor
|
|
956 |
].
|
|
957 |
DefaultHilightBackgroundColor notNil ifTrue:[
|
|
958 |
hilightBgColor := DefaultHilightBackgroundColor
|
|
959 |
].
|
|
960 |
DefaultHilightFrameColor notNil ifTrue:[
|
|
961 |
hilightFrameColor := DefaultHilightFrameColor
|
|
962 |
].
|
|
963 |
DefaultHilightLevel notNil ifTrue:[
|
|
964 |
hilightLevel := DefaultHilightLevel
|
|
965 |
].
|
|
966 |
lineSpacing := 2 * (hilightLevel abs).
|
|
967 |
|
|
968 |
(hilightStyle == #motif) ifTrue:[
|
|
969 |
lineSpacing := lineSpacing max:6.
|
|
970 |
] ifFalse:[
|
|
971 |
lineSpacing := lineSpacing max:4.
|
|
972 |
].
|
|
973 |
hilightFgColor isNil ifTrue:[
|
|
974 |
hilightFgColor := bgColor.
|
|
975 |
hilightBgColor := fgColor
|
|
976 |
].
|
|
977 |
!
|
|
978 |
|
|
979 |
initialize
|
|
980 |
"setup default attributes/behavior
|
|
981 |
"
|
|
982 |
super initialize.
|
|
983 |
|
|
984 |
multipleSelectOk := false.
|
|
985 |
useIndex := true.
|
|
986 |
|
|
987 |
!
|
|
988 |
|
|
989 |
realize
|
|
990 |
"get selection from model; scroll to selection
|
|
991 |
"
|
|
992 |
selection := self getSelectionFromModel.
|
|
993 |
|
|
994 |
super realize.
|
|
995 |
|
|
996 |
selection notNil ifTrue:[
|
|
997 |
useIndex ifTrue:[selection := selection copy].
|
|
998 |
self makeSelectionVisible.
|
|
999 |
]
|
|
1000 |
! !
|
|
1001 |
|
|
1002 |
!SelectionInListModelView methodsFor:'protocol'!
|
|
1003 |
|
1399
|
1004 |
drawElementsFrom:start to:stop x:xL y:yT toX:xR
|
1390
|
1005 |
"draw the items between start to stop without clearing the background
|
|
1006 |
"
|
|
1007 |
|y0 "{ Class:SmallInteger }"
|
|
1008 |
y1 "{ Class:SmallInteger }"
|
|
1009 |
x0 "{ Class:SmallInteger }"
|
|
1010 |
|
|
|
1011 |
x0 := textStartLeft - viewOrigin x.
|
1399
|
1012 |
y1 := yT.
|
1390
|
1013 |
|
|
1014 |
start to:stop do:[:i|
|
|
1015 |
y0 := y1.
|
|
1016 |
y1 := self yVisibleOfLine:(i + 1).
|
1399
|
1017 |
self drawLabelAt:i x:x0 y:y0 toX:xR y:y1
|
1390
|
1018 |
].
|
|
1019 |
|
|
1020 |
|
|
1021 |
!
|
|
1022 |
|
|
1023 |
redrawLabelFromItem:anItem atY:y h:h
|
|
1024 |
"called to redraw a label caused by a selection changed
|
|
1025 |
"
|
|
1026 |
|
|
|
1027 |
x0 "{ Class:SmallInteger }"
|
|
1028 |
x1 "{ Class:SmallInteger }"
|
|
1029 |
|
|
|
1030 |
x0 := textStartLeft // 2 - viewOrigin x.
|
|
1031 |
x1 := x0 + textStartLeft + (anItem widthOn:self).
|
|
1032 |
x0 := x0 max:margin.
|
|
1033 |
x1 := x1 min:(self innerWidth).
|
|
1034 |
|
|
1035 |
x1 > x0 ifTrue:[
|
1399
|
1036 |
self redrawX:x0 y:y width:(x1 - x0) height:h.
|
1390
|
1037 |
]
|
|
1038 |
! !
|
|
1039 |
|
|
1040 |
!SelectionInListModelView methodsFor:'selection'!
|
|
1041 |
|
|
1042 |
deselect
|
|
1043 |
"clear selection
|
|
1044 |
"
|
|
1045 |
self selection:nil
|
|
1046 |
|
|
1047 |
!
|
|
1048 |
|
|
1049 |
firstInSelection
|
|
1050 |
"returns line number of first element selected or nil
|
|
1051 |
"
|
|
1052 |
|lineNr|
|
|
1053 |
|
|
1054 |
selection notNil ifTrue:[
|
|
1055 |
^ multipleSelectOk ifTrue:[selection at:1] ifFalse:[selection]
|
|
1056 |
].
|
|
1057 |
^ nil
|
|
1058 |
|
|
1059 |
|
|
1060 |
!
|
|
1061 |
|
|
1062 |
hasSelection
|
|
1063 |
"returns true if a selection exists
|
|
1064 |
"
|
|
1065 |
^ selection notNil
|
|
1066 |
|
|
1067 |
!
|
|
1068 |
|
|
1069 |
isInSelection:aNumber
|
|
1070 |
"return true, if line, aNumber is in the selection
|
|
1071 |
"
|
|
1072 |
selection isNil ifTrue:[^ false].
|
|
1073 |
|
|
1074 |
^ multipleSelectOk ifFalse:[aNumber == selection]
|
|
1075 |
ifTrue:[selection includes:aNumber]
|
|
1076 |
!
|
|
1077 |
|
|
1078 |
lastInSelection
|
|
1079 |
"returns line number of last element selected or nil
|
|
1080 |
"
|
|
1081 |
|lineNr|
|
|
1082 |
|
|
1083 |
selection notNil ifTrue:[
|
|
1084 |
^ multipleSelectOk ifTrue:[selection last] ifFalse:[selection]
|
|
1085 |
].
|
|
1086 |
^ nil
|
|
1087 |
|
|
1088 |
|
|
1089 |
!
|
|
1090 |
|
|
1091 |
numberOfSelections
|
|
1092 |
"return the number of selected items
|
|
1093 |
"
|
|
1094 |
selection isNil ifTrue:[^ 0].
|
|
1095 |
^ multipleSelectOk ifFalse:[1] ifTrue:[selection size]
|
|
1096 |
|
|
1097 |
|
|
1098 |
!
|
|
1099 |
|
|
1100 |
selectElement:anElement
|
|
1101 |
"select the element. Scroll to make the new selection visible.
|
|
1102 |
Model and/or actionBlock notification IS done.
|
|
1103 |
"
|
|
1104 |
|index|
|
|
1105 |
|
|
1106 |
(index := self identityIndexOf:anElement) ~~ 0 ifTrue:[
|
|
1107 |
self selection:index
|
|
1108 |
]
|
|
1109 |
|
|
1110 |
!
|
|
1111 |
|
|
1112 |
selectedElement
|
|
1113 |
"return the single selected item or nil
|
|
1114 |
"
|
|
1115 |
|index|
|
|
1116 |
|
|
1117 |
index := self selectedIndex.
|
|
1118 |
^ index ~~ 0 ifTrue:[self at:index ifAbsent:nil] ifFalse:[nil]
|
|
1119 |
|
|
1120 |
!
|
|
1121 |
|
|
1122 |
selectedIndex
|
|
1123 |
"returns the index of the selected line or 0. If more
|
|
1124 |
lines are selected, 0 is returned
|
|
1125 |
"
|
|
1126 |
selection notNil ifTrue:[
|
|
1127 |
multipleSelectOk ifFalse:[^ selection].
|
|
1128 |
selection size == 1 ifTrue:[^ selection at:1]
|
|
1129 |
].
|
|
1130 |
^ 0
|
|
1131 |
!
|
|
1132 |
|
|
1133 |
selection
|
|
1134 |
"return the selection index or collection of indices
|
|
1135 |
in case of multiple selection enabled
|
|
1136 |
"
|
|
1137 |
^ selection
|
|
1138 |
|
|
1139 |
!
|
|
1140 |
|
|
1141 |
selection:aNumberOrNil
|
|
1142 |
"select line, aNumber or deselect if argument is nil;
|
|
1143 |
scroll to make the selected line visible.
|
|
1144 |
The model and/or actionBlock IS notified.
|
|
1145 |
"
|
|
1146 |
|oldSelection|
|
|
1147 |
|
|
1148 |
oldSelection := selection.
|
|
1149 |
self setSelection:aNumberOrNil.
|
|
1150 |
|
|
1151 |
selection ~= oldSelection ifTrue:[
|
|
1152 |
self selectionChanged
|
|
1153 |
]
|
|
1154 |
|
|
1155 |
|
|
1156 |
!
|
|
1157 |
|
|
1158 |
selectionDo:aBlock
|
|
1159 |
"perform aBlock for each nr in the selection.
|
|
1160 |
For single selection, it is called once for the items nr.
|
|
1161 |
For multiple selections, it is called for each.
|
|
1162 |
"
|
|
1163 |
selection notNil ifTrue:[
|
|
1164 |
multipleSelectOk ifTrue:[
|
|
1165 |
selection do:aBlock
|
|
1166 |
] ifFalse:[
|
|
1167 |
aBlock value:selection
|
|
1168 |
].
|
|
1169 |
].
|
|
1170 |
|
|
1171 |
|
|
1172 |
!
|
|
1173 |
|
|
1174 |
selectionValue
|
|
1175 |
"return the selection value. For multiple selections a collection
|
|
1176 |
containing the elements is returned. Otherwise the selected element
|
|
1177 |
"
|
|
1178 |
selection isNil ifTrue:[
|
|
1179 |
^ multipleSelectOk ifTrue:[#()] ifFalse:[nil]
|
|
1180 |
].
|
|
1181 |
multipleSelectOk ifTrue:[
|
|
1182 |
^ selection collect:[:nr | list at:nr ifAbsent:nil ]
|
|
1183 |
].
|
|
1184 |
^ list at:selection ifAbsent:nil
|
|
1185 |
!
|
|
1186 |
|
|
1187 |
setSelection:aNumberOrNilOrCollection
|
|
1188 |
"select line, aNumber or deselect if argument is nil;
|
|
1189 |
scroll to make the selected line visible.
|
|
1190 |
*** No model and/or actionBlock notification is done here.
|
|
1191 |
"
|
|
1192 |
self selectWithoutScroll:aNumberOrNilOrCollection.
|
|
1193 |
|
|
1194 |
selection notNil ifTrue:[
|
|
1195 |
self makeSelectionVisible
|
|
1196 |
]
|
|
1197 |
|
|
1198 |
!
|
|
1199 |
|
|
1200 |
toggleSelection:aNumber
|
|
1201 |
"toggle selection-state of entry, aNumber.
|
|
1202 |
*** No model and/or actionBlock notification is done here.
|
|
1203 |
"
|
|
1204 |
aNumber notNil ifTrue:[
|
|
1205 |
(self isInSelection:aNumber) ifTrue:[
|
|
1206 |
self removeFromSelection:aNumber
|
|
1207 |
] ifFalse:[
|
|
1208 |
self addToSelection:aNumber
|
|
1209 |
]
|
|
1210 |
]
|
|
1211 |
! !
|
|
1212 |
|
|
1213 |
!SelectionInListModelView methodsFor:'selection private'!
|
|
1214 |
|
|
1215 |
addToSelection:aNumber
|
|
1216 |
"add a number to the selection. No scrolling is done.
|
|
1217 |
*** No model and/or actionBlock notification is done here.
|
|
1218 |
"
|
|
1219 |
|newSelect oldSelect|
|
|
1220 |
|
|
1221 |
(aNumber notNil and:[aNumber between:1 and:(self size)]) ifFalse:[
|
|
1222 |
^ self
|
|
1223 |
].
|
|
1224 |
multipleSelectOk ifFalse:[
|
|
1225 |
oldSelect == selection ifTrue:[^ self].
|
|
1226 |
oldSelect := selection.
|
|
1227 |
selection := aNumber.
|
|
1228 |
oldSelect notNil ifTrue:[self redrawSelectionAt:oldSelect].
|
|
1229 |
] ifTrue:[
|
|
1230 |
selection isNil ifTrue:[
|
|
1231 |
selection := Array with:aNumber.
|
|
1232 |
] ifFalse:[
|
|
1233 |
(selection includes:aNumber) ifTrue:[^ self].
|
|
1234 |
selection := selection copyWith:aNumber.
|
|
1235 |
].
|
|
1236 |
].
|
|
1237 |
self redrawSelectionAt:aNumber.
|
|
1238 |
!
|
|
1239 |
|
|
1240 |
deselectWithoutRedraw
|
|
1241 |
"set selection without redraw, scrolling.
|
|
1242 |
The model and/or actionBlock IS notified.
|
|
1243 |
"
|
|
1244 |
selection notNil ifTrue:[
|
|
1245 |
selection := nil.
|
|
1246 |
self selectionChanged
|
|
1247 |
]
|
|
1248 |
!
|
|
1249 |
|
|
1250 |
makeSelectionVisible
|
|
1251 |
"scroll to make the selection line visible
|
|
1252 |
"
|
|
1253 |
|lineNr|
|
|
1254 |
|
|
1255 |
(lineNr := self firstInSelection) notNil ifTrue:[
|
|
1256 |
self scrollToLine:lineNr
|
|
1257 |
]
|
|
1258 |
|
|
1259 |
|
|
1260 |
!
|
|
1261 |
|
|
1262 |
removeFromSelection:aNumber
|
|
1263 |
"remove aNumber from the selection and redraw line;
|
|
1264 |
*** No model and/or actionBlock notification is done here.
|
|
1265 |
"
|
|
1266 |
selection notNil ifTrue:[
|
|
1267 |
multipleSelectOk ifTrue:[
|
|
1268 |
(selection includes:aNumber) ifTrue:[
|
|
1269 |
selection size == 1 ifTrue:[
|
|
1270 |
selection := nil
|
|
1271 |
] ifFalse:[
|
|
1272 |
selection := selection copyWithout:aNumber
|
|
1273 |
].
|
|
1274 |
self redrawSelectionAt:aNumber
|
|
1275 |
]
|
|
1276 |
] ifFalse:[
|
|
1277 |
aNumber == selection ifFalse:[
|
|
1278 |
selection := nil.
|
|
1279 |
self redrawSelectionAt:aNumber
|
|
1280 |
]
|
|
1281 |
]
|
|
1282 |
]
|
|
1283 |
|
|
1284 |
!
|
|
1285 |
|
|
1286 |
selectWithoutScroll:aNumberOrNilOrCollection
|
|
1287 |
"select line, aNumber or deselect if argument is nil;
|
|
1288 |
scroll to make the selected line visible.
|
|
1289 |
*** No model and/or actionBlock notification is done here.
|
|
1290 |
"
|
|
1291 |
|oldSelect|
|
|
1292 |
|
|
1293 |
oldSelect := selection.
|
|
1294 |
selection := self validateSelection:aNumberOrNilOrCollection.
|
|
1295 |
|
|
1296 |
(shown and:[selection ~= oldSelect]) ifFalse:[
|
|
1297 |
^ self
|
|
1298 |
].
|
|
1299 |
|
|
1300 |
multipleSelectOk ifFalse:[
|
|
1301 |
oldSelect notNil ifTrue:[self redrawSelectionAt:oldSelect].
|
|
1302 |
selection notNil ifTrue:[self redrawSelectionAt:selection].
|
|
1303 |
] ifTrue:[
|
|
1304 |
selection isNil ifTrue:[
|
|
1305 |
oldSelect do:[:i|self redrawSelectionAt:i].
|
|
1306 |
] ifFalse:[
|
|
1307 |
oldSelect isNil ifTrue:[
|
|
1308 |
selection do:[:i|self redrawSelectionAt:i].
|
|
1309 |
] ifFalse:[
|
|
1310 |
selection do:[:i|
|
|
1311 |
(oldSelect includes:i) ifFalse:[self redrawSelectionAt:i]
|
|
1312 |
].
|
|
1313 |
oldSelect do:[:i|
|
|
1314 |
(selection includes:i) ifFalse:[self redrawSelectionAt:i]
|
|
1315 |
].
|
|
1316 |
]
|
|
1317 |
]
|
|
1318 |
].
|
|
1319 |
|
|
1320 |
|
|
1321 |
|
|
1322 |
!
|
|
1323 |
|
|
1324 |
selectionWithoutRedraw:aSelection
|
|
1325 |
"set selection without redraw, scrolling.
|
|
1326 |
The model and/or actionBlock IS notified.
|
|
1327 |
"
|
|
1328 |
selection ~= aSelection ifTrue:[
|
|
1329 |
selection := aSelection.
|
|
1330 |
self selectionChanged
|
|
1331 |
]
|
|
1332 |
!
|
|
1333 |
|
|
1334 |
validateSelection:aNumberOrCollection
|
|
1335 |
"validate the selection; returns a valid selection or nil
|
|
1336 |
"
|
|
1337 |
|sz newSelection|
|
|
1338 |
|
|
1339 |
(aNumberOrCollection notNil and:[aNumberOrCollection ~~ 0]) ifTrue:[
|
|
1340 |
sz := self size.
|
|
1341 |
|
|
1342 |
aNumberOrCollection isCollection ifFalse:[
|
|
1343 |
(aNumberOrCollection between:1 and:sz) ifTrue:[
|
|
1344 |
^ multipleSelectOk ifFalse:[aNumberOrCollection ]
|
|
1345 |
ifTrue:[Array with:aNumberOrCollection]
|
|
1346 |
]
|
|
1347 |
] ifTrue:[
|
|
1348 |
(aNumberOrCollection notNil and:[multipleSelectOk]) ifTrue:[
|
|
1349 |
newSelection := OrderedCollection new.
|
|
1350 |
|
|
1351 |
aNumberOrCollection do:[:anIndex|
|
|
1352 |
(anIndex between:1 and:sz) ifFalse:[^ nil].
|
|
1353 |
newSelection add:anIndex.
|
|
1354 |
].
|
|
1355 |
^ newSelection
|
|
1356 |
]
|
|
1357 |
]
|
|
1358 |
].
|
|
1359 |
^ nil
|
|
1360 |
|
|
1361 |
|
|
1362 |
! !
|
|
1363 |
|
|
1364 |
!SelectionInListModelView class methodsFor:'documentation'!
|
|
1365 |
|
|
1366 |
version
|
1409
|
1367 |
^ '$Header: /cvs/stx/stx/libwidg2/SelectionInListModelView.st,v 1.5 1999-06-12 14:37:31 cg Exp $'
|
1390
|
1368 |
! !
|
1409
|
1369 |
SelectionInListModelView initialize!
|