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