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