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