author | ca |
Mon, 09 Dec 2002 10:51:41 +0100 | |
changeset 2401 | c0c3b44afb43 |
parent 2399 | 949ec827ab3a |
child 2404 | 2b7591c982ac |
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 |
2228 | 17 |
instanceVariableNames:'selection multipleSelectOk selectOnButtomMenu actionBlock |
2401 | 18 |
doubleClickActionBlock selectConditionBlock buttonMotionAction |
19 |
buttonReleaseAction highlightMode useIndex ignoreReselect |
|
20 |
toggleSelect hilightFgColor hilightBgColor hilightLevel |
|
21 |
hilightFrameColor hilightStyle dropTarget dropSource editorView |
|
22 |
openEditorAction closeEditorAction highlightEnterItem enterItem |
|
23 |
cursorItem lineMask' |
|
1390 | 24 |
classVariableNames:'DefaultHilightStyle DefaultHilightBackgroundColor |
25 |
DefaultHilightForegroundColor DefaultHilightLevel |
|
26 |
DefaultHilightFrameColor' |
|
27 |
poolDictionaries:'' |
|
1430 | 28 |
category:'Views-Lists' |
1390 | 29 |
! |
30 |
||
31 |
!SelectionInListModelView class methodsFor:'documentation'! |
|
32 |
||
1431 | 33 |
copyright |
34 |
" |
|
35 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
36 |
All Rights Reserved |
|
37 |
||
38 |
This software is furnished under a license and may be used |
|
39 |
only in accordance with the terms of that license and with the |
|
40 |
inclusion of the above copyright notice. This software may not |
|
41 |
be provided or otherwise made available to, or used by, any |
|
42 |
other person. No title to or ownership of the software is |
|
43 |
hereby transferred. |
|
44 |
" |
|
45 |
||
46 |
! |
|
47 |
||
1390 | 48 |
documentation |
49 |
" |
|
50 |
SelectionInListModelView is mostly like SelectionInListView, |
|
51 |
but derives from the ListModelView and thus the list is kept |
|
52 |
by the model. |
|
53 |
||
54 |
[Instance variables:] |
|
2228 | 55 |
|
56 |
selection <misc> the current selection. nil, a number or collection of numbers |
|
57 |
multipleSelectOk <Boolean> allow/disallow multiple selections( default:false ) |
|
58 |
selectOnButtomMenu <Boolean> enable/disable selection will change on menu pressed |
|
59 |
||
2401 | 60 |
buttonReleaseAction <Action> called if the mouse button is released |
61 |
buttonMotionAction <Action> called during mouse motion with one argument the point |
|
62 |
under the mouse. |
|
63 |
||
2228 | 64 |
actionBlock <Block> action evaluated on single click |
65 |
doubleClickActionBlock <Block> action evaluated on double click |
|
66 |
selectConditionBlock |
|
67 |
||
68 |
useIndex <Boolean> representation of the model selection |
|
69 |
||
70 |
ignoreReselect <Boolean> if set, a click on an already selected entry is ignored |
|
71 |
toggleSelect <Boolean> a click on an entry unselects it and vice versa |
|
72 |
||
73 |
highlightMode <Symbol> how to draw the selection |
|
74 |
hilightFgColor <Color> foregroundColor of highlighted items |
|
75 |
hilightBgColor <Color> backgroundColor of highlighted items |
|
76 |
hilightLevel <Integer> level to draw selections (i.e. for 3D effect) |
|
77 |
hilightFrameColor <Color> rectangle around highlighted items |
|
78 |
hilightStyle <Boolean> actions on widget are enabled/disabled |
|
79 |
||
80 |
dropTarget <DropTarget> keeps information about the drop operation |
|
81 |
dropSource <DropSource> keeps information about the drag operation |
|
82 |
||
83 |
editorView <View> editor on current selected item |
|
84 |
openEditorAction <Action> action to get an editor on the current selection from user |
|
2250
e95303644fac
add an closeEditor action to allow the user to accept the contents
james
parents:
2245
diff
changeset
|
85 |
closeEditorAction <Action> action invoked before the editor is closed. |
1390 | 86 |
|
2323 | 87 |
enterItem <Item/nil> item over which the mouse pointer is located |
88 |
or nil |
|
89 |
highlightEnterItem <Boolean> enable or disable highlight of enterItem |
|
90 |
||
1390 | 91 |
[author:] |
92 |
Claus Atzkern |
|
93 |
||
94 |
[see also:] |
|
95 |
||
96 |
ListModelView |
|
97 |
HierarchicalListView |
|
98 |
" |
|
99 |
! |
|
100 |
||
101 |
examples |
|
102 |
" |
|
103 |
[exBegin] |
|
104 |
|top list view| |
|
105 |
||
106 |
list := List new. |
|
107 |
||
108 |
1 to:100 do:[:i| list add:('element: ', i printString) ]. |
|
109 |
top := StandardSystemView new; extent:300@300. |
|
110 |
view := ScrollableView for:SelectionInListModelView miniScroller:true |
|
111 |
origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
112 |
view list:list. |
|
113 |
top open. |
|
114 |
[exEnd] |
|
115 |
||
116 |
||
117 |
[exBegin] |
|
1915 | 118 |
|top list view| |
119 |
||
120 |
list := List new. |
|
121 |
||
122 |
1 to:100 do:[:i| list add:('element: ', i printString) ]. |
|
123 |
top := StandardSystemView new; extent:300@300. |
|
124 |
view := ScrollableView for:SelectionInListModelView miniScroller:true |
|
125 |
origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
126 |
view list:list. |
|
127 |
||
128 |
view openEditorAction:[:ln :aGC| |field| |
|
129 |
field := EditField new. |
|
130 |
field level:0. |
|
131 |
field acceptOnLostFocus:true. |
|
132 |
field acceptAction:[:x| list at:ln put:(field contents) ]. |
|
133 |
field font:(aGC font). |
|
134 |
field contents:(list at:ln). |
|
135 |
field |
|
136 |
]. |
|
137 |
top open. |
|
138 |
[exEnd] |
|
139 |
||
140 |
[exBegin] |
|
1390 | 141 |
|top list view item| |
142 |
||
143 |
list := HierarchicalList new. |
|
144 |
item := HierarchicalItem::Example labeled:'Test'. |
|
145 |
item expand. |
|
146 |
list showRoot:false. |
|
147 |
list root:item. |
|
148 |
||
149 |
top := StandardSystemView new; extent:300@300. |
|
150 |
view := ScrollableView for:SelectionInListModelView miniScroller:true |
|
151 |
origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
152 |
||
153 |
view list:list. |
|
154 |
view doubleClickAction:[:i| (list at:i) toggleExpand ]. |
|
155 |
top open. |
|
156 |
[exEnd] |
|
157 |
||
158 |
" |
|
159 |
! ! |
|
160 |
||
161 |
!SelectionInListModelView class methodsFor:'defaults'! |
|
162 |
||
163 |
updateStyleCache |
|
164 |
"extract values from the styleSheet and cache them in class variables" |
|
165 |
||
166 |
<resource: #style ( |
|
167 |
#'selection.hilightForegroundColor' #'selection.hilightBackgroundColor' |
|
168 |
#'selection.hilightFrameColor' #'selection.hilightLevel' |
|
169 |
#'selection.foregroundColor' #'selection.backgroundColor' |
|
170 |
#'selection.shadowColor' #'selection.lightColor' |
|
171 |
#'selection.font' #'selection.hilightStyle' |
|
172 |
#'text.foregroundColor' |
|
173 |
)> |
|
174 |
||
175 |
DefaultHilightForegroundColor := StyleSheet colorAt:'selection.hilightForegroundColor'. |
|
176 |
DefaultHilightBackgroundColor := StyleSheet colorAt:'selection.hilightBackgroundColor'. |
|
177 |
DefaultHilightFrameColor := StyleSheet colorAt:'selection.hilightFrameColor'. |
|
178 |
DefaultHilightLevel := StyleSheet at:'selection.hilightLevel' default:0. |
|
179 |
DefaultHilightStyle := StyleSheet at:'selection.hilightStyle' default:(StyleSheet name). |
|
180 |
DefaultForegroundColor := StyleSheet colorAt:'selection.foregroundColor'. |
|
181 |
DefaultBackgroundColor := StyleSheet colorAt:'selection.backgroundColor'. |
|
182 |
DefaultShadowColor := StyleSheet colorAt:'selection.shadowColor'. |
|
183 |
DefaultLightColor := StyleSheet colorAt:'selection.lightColor'. |
|
184 |
||
185 |
DefaultForegroundColor isNil ifTrue:[ |
|
186 |
DefaultForegroundColor := StyleSheet colorAt:'text.foregroundColor' default:Black |
|
187 |
]. |
|
188 |
" |
|
189 |
self updateStyleCache |
|
190 |
" |
|
191 |
||
192 |
||
193 |
! ! |
|
194 |
||
195 |
!SelectionInListModelView methodsFor:'accessing'! |
|
196 |
||
2377 | 197 |
cursorLine |
198 |
"returns the index of the cursor line or 0 |
|
199 |
" |
|
200 |
|index| |
|
201 |
||
202 |
cursorItem isNil ifTrue:[^ 0 ]. |
|
203 |
||
204 |
index := list identityIndexOf:cursorItem. |
|
205 |
index == 0 ifTrue:[ cursorItem := nil ]. |
|
206 |
^ index |
|
207 |
! |
|
208 |
||
1390 | 209 |
list:aList |
210 |
"get the status of <showRoot> from the list |
|
211 |
" |
|
1547 | 212 |
self deselectWithoutRedraw. |
1390 | 213 |
^ super list:aList |
214 |
! ! |
|
215 |
||
2225 | 216 |
!SelectionInListModelView methodsFor:'accessing editor'! |
217 |
||
218 |
closeEditor |
|
219 |
"close the current editor |
|
220 |
" |
|
221 |
|editor| |
|
222 |
||
223 |
(editor := editorView) notNil ifTrue:[ |
|
224 |
editorView := nil. |
|
2308 | 225 |
closeEditorAction notNil ifTrue:[ |
2250
e95303644fac
add an closeEditor action to allow the user to accept the contents
james
parents:
2245
diff
changeset
|
226 |
closeEditorAction value:editor. |
e95303644fac
add an closeEditor action to allow the user to accept the contents
james
parents:
2245
diff
changeset
|
227 |
]. |
2225 | 228 |
editor destroy. |
229 |
]. |
|
2250
e95303644fac
add an closeEditor action to allow the user to accept the contents
james
parents:
2245
diff
changeset
|
230 |
! |
2225 | 231 |
|
2250
e95303644fac
add an closeEditor action to allow the user to accept the contents
james
parents:
2245
diff
changeset
|
232 |
closeEditorAction |
e95303644fac
add an closeEditor action to allow the user to accept the contents
james
parents:
2245
diff
changeset
|
233 |
"get the block which is evaluated before the editor is closed; the argument |
e95303644fac
add an closeEditor action to allow the user to accept the contents
james
parents:
2245
diff
changeset
|
234 |
to the action is the editor. |
e95303644fac
add an closeEditor action to allow the user to accept the contents
james
parents:
2245
diff
changeset
|
235 |
" |
e95303644fac
add an closeEditor action to allow the user to accept the contents
james
parents:
2245
diff
changeset
|
236 |
^ closeEditorAction |
e95303644fac
add an closeEditor action to allow the user to accept the contents
james
parents:
2245
diff
changeset
|
237 |
! |
2225 | 238 |
|
2250
e95303644fac
add an closeEditor action to allow the user to accept the contents
james
parents:
2245
diff
changeset
|
239 |
closeEditorAction:anOneArgAction |
e95303644fac
add an closeEditor action to allow the user to accept the contents
james
parents:
2245
diff
changeset
|
240 |
"get the block which is evaluated before the editor is closed; the argument |
e95303644fac
add an closeEditor action to allow the user to accept the contents
james
parents:
2245
diff
changeset
|
241 |
to the action is the editor. |
e95303644fac
add an closeEditor action to allow the user to accept the contents
james
parents:
2245
diff
changeset
|
242 |
" |
e95303644fac
add an closeEditor action to allow the user to accept the contents
james
parents:
2245
diff
changeset
|
243 |
closeEditorAction := anOneArgAction. |
2225 | 244 |
! |
245 |
||
246 |
openEditor |
|
247 |
"opens the editor on the current selection; |
|
248 |
returns the editorView or nil if no openEditorAction is defined |
|
249 |
or no single selection exists ... |
|
250 |
" |
|
251 |
|numArgs lnNr| |
|
252 |
||
253 |
self closeEditor. |
|
254 |
shown ifFalse:[^ nil]. |
|
2308 | 255 |
openEditorAction isNil ifTrue:[^ nil]. |
2225 | 256 |
lnNr := self selectedIndex. |
257 |
lnNr == 0 ifTrue:[^ nil]. |
|
258 |
||
259 |
self makeSelectionVisible. |
|
260 |
||
261 |
numArgs := openEditorAction numArgs. |
|
262 |
||
263 |
numArgs == 0 ifTrue:[ |
|
264 |
editorView := openEditorAction value |
|
265 |
] ifFalse:[ |
|
266 |
numArgs == 1 ifTrue:[editorView := openEditorAction value:lnNr] |
|
267 |
ifFalse:[editorView := openEditorAction value:lnNr value:self] |
|
268 |
]. |
|
2308 | 269 |
editorView isNil ifTrue:[^ nil]. |
2225 | 270 |
|
2308 | 271 |
editorView superView isNil ifTrue:[ |
2225 | 272 |
self addSubView:editorView |
273 |
]. |
|
274 |
self computeEditorLayout. |
|
275 |
editorView realize. |
|
276 |
self windowGroup focusView:editorView. |
|
277 |
^ editorView |
|
278 |
! |
|
279 |
||
280 |
openEditorAction |
|
281 |
"get the block which is evaluated to get the editor which is set for the |
|
282 |
line; the arguments to the block is the line number and the widget itself |
|
283 |
" |
|
284 |
^ openEditorAction |
|
285 |
||
286 |
! |
|
287 |
||
288 |
openEditorAction:aTwoArgAction |
|
289 |
"set the block which is evaluated to get the editor which is set for the |
|
290 |
line; the arguments to the block is the line number and the widget itself |
|
291 |
" |
|
292 |
openEditorAction := aTwoArgAction. |
|
293 |
! ! |
|
294 |
||
1818 | 295 |
!SelectionInListModelView methodsFor:'accessing-actions'! |
1641 | 296 |
|
297 |
action |
|
298 |
"get the action block to be performed on select |
|
299 |
" |
|
300 |
^ actionBlock |
|
301 |
! |
|
302 |
||
303 |
action:aOneArgAction |
|
304 |
"set the action block to be performed on select |
|
305 |
" |
|
306 |
actionBlock := aOneArgAction |
|
307 |
||
308 |
||
309 |
! |
|
310 |
||
311 |
doubleClickAction |
|
312 |
"get the action block to be performed on doubleclick |
|
313 |
" |
|
314 |
^ doubleClickActionBlock |
|
315 |
||
316 |
! |
|
317 |
||
318 |
doubleClickAction:aOneArgAction |
|
319 |
"set the action block to be performed on doubleclick |
|
320 |
" |
|
321 |
doubleClickActionBlock := aOneArgAction |
|
322 |
||
323 |
! |
|
324 |
||
325 |
selectConditionBlock |
|
326 |
"set the conditionBlock; this block is evaluated before a selection |
|
327 |
change is performed; the change will not be done, if the evaluation |
|
328 |
returns false |
|
329 |
" |
|
330 |
^ selectConditionBlock |
|
331 |
||
332 |
! |
|
333 |
||
334 |
selectConditionBlock:aOneArgBlock |
|
335 |
"set the conditionBlock; this block is evaluated before a selection |
|
336 |
change is performed; the change will not be done, if the evaluation |
|
337 |
returns false |
|
338 |
" |
|
339 |
selectConditionBlock := aOneArgBlock. |
|
340 |
||
341 |
||
342 |
||
343 |
! ! |
|
344 |
||
1818 | 345 |
!SelectionInListModelView methodsFor:'accessing-behavior'! |
1390 | 346 |
|
2323 | 347 |
highlightEnterItem |
348 |
"enable or disable to highlight the item over which the mouse pointer is located |
|
349 |
" |
|
350 |
^ highlightEnterItem |
|
351 |
! |
|
352 |
||
353 |
highlightEnterItem:aBool |
|
354 |
"enable or disable to highlight the item over which the mouse pointer is located |
|
355 |
" |
|
356 |
highlightEnterItem ~~ aBool ifTrue:[ |
|
357 |
highlightEnterItem := aBool. |
|
358 |
self pointerEntersItem:nil. |
|
359 |
]. |
|
360 |
! |
|
361 |
||
1390 | 362 |
highlightMode |
363 |
"get the mode how to draw a selected line: |
|
364 |
#line draw whole line selected |
|
365 |
#label draw label selected |
|
366 |
" |
|
367 |
^ highlightMode |
|
368 |
||
369 |
||
370 |
! |
|
371 |
||
372 |
highlightMode:aMode |
|
373 |
"set the mode how to draw a selected line: |
|
374 |
#line draw whole line selected |
|
375 |
#label draw label selected |
|
376 |
" |
|
1561 | 377 |
highlightMode := aMode. |
1390 | 378 |
! |
379 |
||
1741
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
380 |
ignoreReselect |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
381 |
"get the ignoreReselect flag - see method #ignoreReselect: for more details |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
382 |
" |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
383 |
^ ignoreReselect |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
384 |
! |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
385 |
|
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
386 |
ignoreReselect:aBoolean |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
387 |
"set/clear the ignoreReselect flag - |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
388 |
if set, a click on an already selected entry is ignored. |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
389 |
Otherwise the notification is done, even if no |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
390 |
change in the selection occurs. |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
391 |
(for example, in browser to update a method). |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
392 |
Setting ignoreReselect to false makes sense if data is shown |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
393 |
which may change by itself (i.e. without the user doing anything) |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
394 |
For example, the inspector uses this, and redisplays the value, |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
395 |
if the selection is the same. |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
396 |
The default is true, meaning that a click on an already selected |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
397 |
does not lead to a notification via the actionBlock/change mechanism. |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
398 |
" |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
399 |
ignoreReselect := aBoolean |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
400 |
|
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
401 |
! |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
402 |
|
1390 | 403 |
multipleSelectOk |
404 |
"allow/disallow multiple selections; the default is false |
|
405 |
" |
|
406 |
^ multipleSelectOk |
|
407 |
||
408 |
||
409 |
! |
|
410 |
||
411 |
multipleSelectOk:aState |
|
2381 | 412 |
"allow/disallow multiple selections. If enabled, the |
413 |
user may select multiple entries in the list, and the program |
|
414 |
always gets a collection of selected items (indexes if useIndex is true, |
|
415 |
values otherwise). The default is false, for single selections. |
|
1390 | 416 |
" |
2381 | 417 |
|state| |
418 |
||
419 |
state := aState ? false. |
|
420 |
||
421 |
multipleSelectOk == state ifTrue:[ ^ self ]. |
|
422 |
||
423 |
selection isNil ifTrue:[ |
|
424 |
multipleSelectOk := state. |
|
425 |
^ self. |
|
426 |
]. |
|
427 |
||
428 |
multipleSelectOk ifFalse:[ |
|
429 |
selection := Array with:selection. |
|
430 |
multipleSelectOk := true. |
|
431 |
^ self |
|
432 |
]. |
|
433 |
||
434 |
selection size == 1 ifTrue:[ |
|
435 |
selection := selection first. |
|
436 |
] ifFalse:[ |
|
437 |
self selection:nil |
|
438 |
]. |
|
439 |
multipleSelectOk := false. |
|
1390 | 440 |
! |
441 |
||
2228 | 442 |
selectOnButtomMenu |
443 |
"define the button-menu-press behavior; if true the line under the mouse |
|
444 |
will be selected before the menu is opened. Otherwise the menu is opened |
|
445 |
on the current selection. |
|
446 |
" |
|
447 |
^ selectOnButtomMenu |
|
448 |
! |
|
449 |
||
450 |
selectOnButtomMenu:aBoolean |
|
451 |
"define the button-menu-press behavior; if true the line under the mouse |
|
452 |
will be selected before the menu is opened. Otherwise the menu is opened |
|
453 |
on the current selection. |
|
454 |
" |
|
455 |
selectOnButtomMenu := aBoolean. |
|
456 |
! |
|
457 |
||
1741
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
458 |
toggleSelect |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
459 |
"get the toggleSelect flag - see method #toggleSelect: for more details |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
460 |
" |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
461 |
^ toggleSelect |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
462 |
! |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
463 |
|
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
464 |
toggleSelect:aBoolean |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
465 |
"turn on/off toggle select. If true, clicking on a selected entry |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
466 |
unselects it and vice versa. The default is false, which means |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
467 |
that clicking on an already selected entry does not change its |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
468 |
select status (see also ignoreReselect:). |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
469 |
" |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
470 |
toggleSelect := aBoolean. |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
471 |
|
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
472 |
|
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
473 |
! |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
474 |
|
1390 | 475 |
useIndex |
476 |
"set/clear the useIndex flag. |
|
477 |
the selection writen to the model are the indices into the list |
|
478 |
or the elements selected. |
|
479 |
" |
|
480 |
^ useIndex |
|
481 |
||
482 |
||
483 |
! |
|
484 |
||
485 |
useIndex:aBoolean |
|
486 |
"set/clear the useIndex flag. |
|
487 |
the selection writen to the model are the indices into the list |
|
488 |
or the elements selected. |
|
489 |
" |
|
490 |
useIndex := aBoolean ? true |
|
491 |
||
492 |
||
493 |
! ! |
|
494 |
||
495 |
!SelectionInListModelView methodsFor:'change & update'! |
|
496 |
||
497 |
argForChangeMessage |
|
498 |
"return the argument for a selectionChange; |
|
499 |
depending on the setting of useIndex, this is either the numeric |
|
500 |
index of the selection or the value (i.e. the string) |
|
501 |
" |
|
1554 | 502 |
selection isNil ifTrue:[ |
503 |
multipleSelectOk ifTrue:[^ #()]. |
|
504 |
^ useIndex ifTrue:[0] ifFalse:[nil] |
|
1390 | 505 |
]. |
1564 | 506 |
useIndex ifTrue:[^ selection]. |
1554 | 507 |
|
508 |
multipleSelectOk ifFalse:[ |
|
509 |
^ list at:selection ifAbsent:nil |
|
1390 | 510 |
]. |
1554 | 511 |
^ selection collect:[:nr| list at:nr ifAbsent:nil ] |
1390 | 512 |
! |
513 |
||
1755 | 514 |
contentsChanged |
515 |
super contentsChanged. |
|
516 |
self computeEditorLayout. |
|
517 |
! |
|
518 |
||
519 |
lineChangedAt:aLnNr with:arg |
|
520 |
super lineChangedAt:aLnNr with:arg. |
|
521 |
||
522 |
(editorView notNil and:[aLnNr == self selectedIndex]) ifTrue:[ |
|
523 |
self computeEditorLayout. |
|
524 |
] |
|
525 |
! |
|
526 |
||
1390 | 527 |
listSizeChanged:aLnNr nLines:aDeltaLines |
528 |
"update selection |
|
529 |
" |
|
1563 | 530 |
|changed cnts| |
1390 | 531 |
|
532 |
super listSizeChanged:aLnNr nLines:aDeltaLines. |
|
533 |
||
534 |
selection isNil ifTrue:[^ self]. |
|
535 |
||
536 |
list size == 0 ifTrue:[ |
|
1563 | 537 |
selection := nil. |
538 |
^ self selectionChanged |
|
1390 | 539 |
]. |
540 |
||
1563 | 541 |
multipleSelectOk ifFalse:[ |
542 |
selection < aLnNr ifTrue:[^ self]. |
|
543 |
||
544 |
selection := selection + aDeltaLines. |
|
1390 | 545 |
|
1563 | 546 |
(aDeltaLines < 0 and:[selection < aLnNr]) ifTrue:[ |
547 |
selection := nil. |
|
548 |
^ self selectionChanged |
|
549 |
] |
|
550 |
] ifTrue:[ |
|
551 |
changed := false. |
|
1390 | 552 |
|
1563 | 553 |
aDeltaLines < 0 ifFalse:[ |
554 |
selection keysAndValuesDo:[:i :ln| |
|
555 |
ln >= aLnNr ifTrue:[ |
|
556 |
changed := true. |
|
557 |
selection at:i put:(ln + aDeltaLines) |
|
558 |
] |
|
1390 | 559 |
] |
1563 | 560 |
] ifTrue:[ |
561 |
cnts := 0. |
|
562 |
||
563 |
selection keysAndValuesDo:[:i :ln||new| |
|
564 |
ln >= aLnNr ifTrue:[ |
|
565 |
changed := true. |
|
566 |
||
567 |
(new := ln + aDeltaLines) < aLnNr ifTrue:[ |
|
568 |
cnts := cnts + 1. |
|
569 |
new := nil |
|
570 |
]. |
|
571 |
selection at:i put:new |
|
572 |
] |
|
573 |
]. |
|
574 |
cnts ~~ 0 ifTrue:[ |
|
575 |
cnts == selection size ifTrue:[ |
|
576 |
selection := nil |
|
577 |
] ifFalse:[ |
|
578 |
selection := selection select:[:ln| ln notNil] |
|
579 |
]. |
|
580 |
^ self selectionChanged. |
|
581 |
]. |
|
1390 | 582 |
]. |
1563 | 583 |
changed ifFalse:[^ self]. |
1390 | 584 |
]. |
585 |
||
1563 | 586 |
(useIndex and:[model notNil]) ifTrue:[ |
587 |
model setValue:(self argForChangeMessage) |
|
588 |
]. |
|
589 |
||
1390 | 590 |
|
591 |
! |
|
592 |
||
1755 | 593 |
originChanged:delta |
594 |
"setup the origin of the editing view |
|
595 |
" |
|
596 |
self computeEditorLayout. |
|
597 |
super originChanged:delta. |
|
598 |
||
599 |
||
600 |
! |
|
601 |
||
1390 | 602 |
selectionChanged |
603 |
"selection has changed. Call actionblock and/or send changeMessage if defined |
|
604 |
" |
|
1554 | 605 |
|arg| |
1390 | 606 |
|
1755 | 607 |
self closeEditor. |
608 |
||
1390 | 609 |
(model isNil and:[actionBlock isNil]) ifTrue:[ |
610 |
^ self |
|
611 |
]. |
|
612 |
||
613 |
arg := self argForChangeMessage. |
|
614 |
||
615 |
model notNil ifTrue:[ |
|
616 |
model removeDependent:self. |
|
1741
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
617 |
"/ 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
|
618 |
arg = model value ifTrue:[ |
d8d45bbbd3ba
check whether model value differs from current selection.
ca
parents:
1755
diff
changeset
|
619 |
model setValue:(arg isNil ifTrue:[0] ifFalse:[nil]). |
d8d45bbbd3ba
check whether model value differs from current selection.
ca
parents:
1755
diff
changeset
|
620 |
]. |
1390 | 621 |
self sendChangeMessage:#value: with:arg. |
2225 | 622 |
model notNil ifTrue:[ "/ argggh could be nilled |
623 |
model addDependent:self. |
|
624 |
] |
|
1390 | 625 |
]. |
626 |
||
627 |
actionBlock notNil ifTrue:[ |
|
2070
cb8b952f7214
use new #valueWithOptionalArg
Claus Gittinger <cg@exept.de>
parents:
2055
diff
changeset
|
628 |
actionBlock valueWithOptionalArgument:arg |
1390 | 629 |
]. |
630 |
! |
|
631 |
||
1554 | 632 |
updateFromModel |
2302
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
633 |
"update selection from the model |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
634 |
" |
2401 | 635 |
|value nsel| |
2302
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
636 |
|
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
637 |
model isNil ifTrue:[ |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
638 |
^ self |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
639 |
]. |
2401 | 640 |
|
641 |
buttonMotionAction notNil ifTrue:[ |
|
2302
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
642 |
"running in button motion; discard change notification |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
643 |
" |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
644 |
^ self |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
645 |
]. |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
646 |
|
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
647 |
value := model value. |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
648 |
|
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
649 |
(useIndex or:[value isNil or:[value isNumber]]) ifFalse:[ |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
650 |
multipleSelectOk ifFalse:[ |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
651 |
value := list identityIndexOf:value |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
652 |
] ifTrue:[ |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
653 |
value isEmpty ifTrue:[ |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
654 |
value := nil |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
655 |
] ifFalse:[ |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
656 |
nsel := OrderedCollection new. |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
657 |
value do:[:e||i|(i := list identityIndexOf:e) ~~ 0 ifTrue:[nsel add:i]]. |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
658 |
value := nsel notEmpty ifTrue:[nsel] ifFalse:[nil] |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
659 |
] |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
660 |
]. |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
661 |
]. |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
662 |
self setSelection:value. |
1390 | 663 |
! ! |
664 |
||
665 |
!SelectionInListModelView methodsFor:'drag & drop'! |
|
666 |
||
667 |
canDrag |
|
668 |
"returns true if dragging is enabled |
|
669 |
" |
|
670 |
^ dropSource notNil |
|
671 |
||
672 |
! |
|
673 |
||
674 |
dropSource |
|
675 |
"returns the dropSource or nil |
|
676 |
" |
|
677 |
^ dropSource |
|
678 |
||
679 |
! |
|
680 |
||
681 |
dropSource:aDropSourceOrNil |
|
682 |
"set the dropSource or nil |
|
683 |
" |
|
684 |
dropSource := aDropSourceOrNil. |
|
685 |
||
686 |
! |
|
687 |
||
688 |
dropTarget |
|
689 |
"returns the dropTarget or nil |
|
690 |
" |
|
691 |
^ dropTarget |
|
692 |
||
693 |
||
694 |
! |
|
695 |
||
696 |
dropTarget:aDropTragetOrNil |
|
697 |
"set the dropTarget or nil |
|
698 |
" |
|
699 |
dropTarget := aDropTragetOrNil. |
|
700 |
||
701 |
! |
|
702 |
||
703 |
startDragAt:aPoint |
|
704 |
"start drag at a point |
|
705 |
" |
|
706 |
dropSource notNil ifTrue:[ |
|
707 |
dropSource startDragSelector notNil ifTrue:[ |
|
708 |
dropSource startDragIn:self at:aPoint |
|
709 |
] ifFalse:[ |
|
710 |
DragAndDropManager new startDragFrom:self |
|
711 |
dropSource:dropSource |
|
712 |
offset:#center |
|
713 |
] |
|
714 |
] |
|
715 |
||
716 |
! ! |
|
717 |
||
718 |
!SelectionInListModelView methodsFor:'drawing'! |
|
719 |
||
1533 | 720 |
drawFrom:start to:stop x:x y:y w:w |
1390 | 721 |
"draw the lines between start to stop without clearing the background |
722 |
" |
|
1557 | 723 |
highlightMode notNil ifTrue:[ |
724 |
self selectionDo:[:lnNr| |
|
725 |
(lnNr between:start and:stop) ifTrue:[ |
|
726 |
self drawSelectionFrameAt:lnNr x:x w:w |
|
727 |
] |
|
1390 | 728 |
] |
729 |
]. |
|
1533 | 730 |
self drawElementsFrom:start to:stop x:x y:y w:w. |
1390 | 731 |
|
732 |
||
733 |
! |
|
734 |
||
2377 | 735 |
drawLabelAt:anIndex x:xI y:y h:h |
1390 | 736 |
"draw the label at position x/y without clearing the background |
737 |
" |
|
2377 | 738 |
|item y0 x1 x w| |
1554 | 739 |
|
2377 | 740 |
x := xI + 1. |
1755 | 741 |
editorView notNil ifTrue:[ |
742 |
"/ there is an open editor for the line; thus no redraw for the label (hidden by editor) |
|
743 |
self selectedIndex == anIndex ifTrue:[^ self]. |
|
744 |
]. |
|
745 |
||
1508
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1468
diff
changeset
|
746 |
item := list at:anIndex ifAbsent:nil. |
2377 | 747 |
item isNil ifTrue:[^ self]. |
1390 | 748 |
|
2377 | 749 |
(highlightMode notNil and:[self isInSelection:anIndex]) ifTrue:[ |
750 |
self paint:hilightFgColor on:hilightBgColor |
|
751 |
] ifFalse:[ |
|
752 |
enterItem == item ifTrue:[ |
|
753 |
self paint:hilightBgColor on:bgColor. |
|
1557 | 754 |
] ifFalse:[ |
2377 | 755 |
self paint:fgColor on:bgColor. |
1557 | 756 |
]. |
2377 | 757 |
]. |
758 |
renderer display:item atX:x y:y lineHeight:h. |
|
1390 | 759 |
|
2377 | 760 |
cursorItem == item ifFalse:[ |
2323 | 761 |
enterItem == item ifTrue:[ |
762 |
y0 := y + h - 2. |
|
2352 | 763 |
x1 := x + (renderer widthFor:item). |
1390 | 764 |
|
2323 | 765 |
self displayLineFromX:x y:y0 toX:x1 y:y0. |
766 |
]. |
|
2377 | 767 |
^ self |
768 |
]. |
|
769 |
"/ textStartLeft |
|
770 |
self setMaskOrigin:(self viewOrigin + (0 @ 1) \\ (lineMask extent)). |
|
771 |
self mask:lineMask. |
|
772 |
w := renderer widthFor:item. |
|
773 |
self displayRectangleX:x -1 y:(y+2) width:w+2 height:(h - 4). |
|
774 |
self mask:nil. |
|
775 |
||
776 |
||
777 |
" |
|
778 |
" |
|
1390 | 779 |
! |
780 |
||
1554 | 781 |
drawSelectionFrameAt:lnNr x:x w:w |
782 |
"draw the background and foreground of the selection frame |
|
783 |
at a lineNr. |
|
1390 | 784 |
" |
1554 | 785 |
|item |
786 |
x0 "{ Class:SmallInteger }" |
|
1390 | 787 |
x1 "{ Class: SmallInteger }" |
1554 | 788 |
y0 "{ Class:SmallInteger }" |
789 |
y1 "{ Class:SmallInteger }" |
|
790 |
hL "{ Class:SmallInteger }" |
|
791 |
wL "{ Class:SmallInteger }" |
|
1390 | 792 |
| |
1755 | 793 |
editorView notNil ifTrue:[ |
794 |
"/ there is an open editor; do not redraw selected |
|
795 |
^ self |
|
796 |
]. |
|
797 |
||
1554 | 798 |
(item := list at:lnNr ifAbsent:nil) isNil ifTrue:[ |
1755 | 799 |
"/ list might change during drawing; item no longer visible |
1554 | 800 |
^ self |
801 |
]. |
|
802 |
||
803 |
"/ CLEAR THE BACKGROUND |
|
804 |
||
805 |
y0 := self yVisibleOfLine:lnNr. |
|
806 |
y1 := self yVisibleOfLine:(lnNr + 1). |
|
807 |
hL := y1 - y0. |
|
808 |
||
809 |
highlightMode == #line ifTrue:[ |
|
810 |
x0 := x. |
|
811 |
x1 := x0 + w. |
|
812 |
] ifFalse:[ |
|
813 |
highlightMode == #label ifFalse:[^ self]. |
|
814 |
x0 := (self xVisibleOfItem:item) - (textStartLeft // 2). |
|
2377 | 815 |
x1 := x0 + (renderer widthFor:item) + textStartLeft + 1. |
1554 | 816 |
]. |
817 |
wL := x1 - x0. |
|
818 |
||
819 |
wL > 0 ifFalse:[^ self]. |
|
820 |
||
821 |
self paint:hilightBgColor. |
|
822 |
self fillRectangleX:x0 y:y0 width:wL height:hL. |
|
823 |
||
824 |
"/ DRAW THE FRAME |
|
1390 | 825 |
|
826 |
hilightFrameColor notNil ifTrue:[ |
|
827 |
hilightLevel == 0 ifTrue:[ |
|
828 |
self paint:hilightFrameColor. |
|
829 |
||
830 |
highlightMode == #line ifTrue:[ |
|
831 |
self displayLineFromX:x0 y:y0 toX:x1 y:y0. |
|
1554 | 832 |
y1 := y0 + hL - 1. |
833 |
self displayLineFromX:x0 y:y1 toX:x1 y:y1. |
|
1390 | 834 |
] ifFalse:[ |
1554 | 835 |
self displayRectangleX:x0 y:y0 width:wL height:hL |
1390 | 836 |
]. |
837 |
^ self. |
|
838 |
] |
|
839 |
] ifFalse:[ |
|
840 |
hilightStyle == #motif ifTrue:[ |
|
841 |
self paint:bgColor. |
|
1554 | 842 |
y1 := y0 + 1. |
1390 | 843 |
highlightMode == #line ifTrue:[ |
1554 | 844 |
self displayLineFromX:x0 y:y1 toX:x1 y:y1. |
845 |
y1 := y0 + hL - 2. |
|
846 |
self displayLineFromX:x0 y:y1 toX:x1 y:y1. |
|
1390 | 847 |
] ifFalse:[ |
1554 | 848 |
self displayRectangleX:x0 + 1 y:y1 width:wL - 2 height:hL - 2 |
1390 | 849 |
] |
850 |
] |
|
851 |
]. |
|
852 |
||
853 |
hilightLevel ~~ 0 ifTrue:[ |
|
854 |
"/ draw edge |
|
855 |
highlightMode == #line ifTrue:[ |
|
1554 | 856 |
x0 := margin. |
857 |
wL := width - x0 - x0. |
|
1390 | 858 |
]. |
1554 | 859 |
self drawEdgesForX:x0 y:y0 width:wL height:hL level:hilightLevel. |
1390 | 860 |
] |
861 |
! |
|
862 |
||
2245
546c6e5d0951
change #redrawSelectionAt: to #invalidateSelectionAt: (because is a invalidate)
ca
parents:
2228
diff
changeset
|
863 |
invalidateSelectionAt:aLineNr |
1569 | 864 |
"redraw a line which changed its selection status. |
865 |
optimized when drawing only the label. |
|
1390 | 866 |
" |
2323 | 867 |
|item x| |
1569 | 868 |
|
1755 | 869 |
editorView notNil ifTrue:[ |
870 |
"/ there is an open editor; do not redraw selected |
|
871 |
^ self |
|
872 |
]. |
|
873 |
||
1569 | 874 |
(shown and:[aLineNr notNil and:[highlightMode notNil]]) ifFalse:[ |
875 |
^ self |
|
1557 | 876 |
]. |
877 |
||
2323 | 878 |
highlightMode == #label ifTrue:[ |
879 |
item := list at:aLineNr ifAbsent:nil. |
|
1569 | 880 |
|
2323 | 881 |
item isNil ifTrue:[ |
882 |
^ self |
|
883 |
]. |
|
884 |
x := (self xVisibleOfItem:item) - (textStartLeft // 2) |
|
1569 | 885 |
] ifFalse:[ |
2323 | 886 |
x := 0. |
1569 | 887 |
]. |
2323 | 888 |
self invalidateLineAt:aLineNr fromX:x |
1390 | 889 |
! ! |
890 |
||
891 |
!SelectionInListModelView methodsFor:'event handling'! |
|
892 |
||
2401 | 893 |
buttonControlPressAtLine:lineNr x:x y:y |
894 |
"handle a button control press |
|
1390 | 895 |
" |
2401 | 896 |
|isInSelection prvLine chgSet doAdd| |
1747
f46c5941c028
better alghorithm for button motion in multipleSelection mode
ca
parents:
1745
diff
changeset
|
897 |
|
2401 | 898 |
isInSelection := self isInSelection:lineNr. |
1390 | 899 |
|
2401 | 900 |
multipleSelectOk ifFalse:[ |
901 |
isInSelection ifTrue:[ |
|
902 |
self deselect |
|
903 |
]ifFalse:[ |
|
904 |
(self canSelectIndex:lineNr forAdd:false) ifTrue:[ |
|
905 |
self buttonPressOrReleaseAtLine:lineNr x:x y:y. |
|
906 |
]. |
|
1390 | 907 |
]. |
908 |
^ self |
|
909 |
]. |
|
910 |
||
2401 | 911 |
(isInSelection or:[self canSelectIndex:lineNr forAdd:true]) ifFalse:[ |
1390 | 912 |
^ self |
913 |
]. |
|
914 |
||
2401 | 915 |
self toggleSelection:lineNr. |
916 |
self selectionChanged. |
|
917 |
||
918 |
prvLine := lineNr. |
|
919 |
chgSet := IdentitySet new. |
|
920 |
doAdd := isInSelection not. |
|
921 |
||
922 |
buttonMotionAction := [:p| |rowNr mustRestore step f| |
|
923 |
rowNr := self yVisibleToLineNr:(p y). |
|
1747
f46c5941c028
better alghorithm for button motion in multipleSelection mode
ca
parents:
1745
diff
changeset
|
924 |
|
2401 | 925 |
(rowNr notNil and:[rowNr ~~ prvLine]) ifTrue:[ |
926 |
rowNr == lineNr ifTrue:[ |
|
927 |
mustRestore := true |
|
928 |
] ifFalse:[ |
|
929 |
rowNr > lineNr ifTrue:[ mustRestore := (rowNr < prvLine) ] |
|
930 |
ifFalse:[ mustRestore := (rowNr > prvLine) ]. |
|
931 |
]. |
|
932 |
prvLine > rowNr ifTrue:[ step := -1 ] |
|
933 |
ifFalse:[ step := 1 ]. |
|
934 |
mustRestore ifTrue:[ |
|
935 |
[ prvLine ~~ rowNr ] whileTrue:[ |
|
936 |
(chgSet removeIdentical:prvLine ifAbsent:nil) notNil ifTrue:[ |
|
937 |
doAdd ifFalse:[ self addToSelection:prvLine ] |
|
938 |
ifTrue:[ self removeFromSelection:prvLine ]. |
|
939 |
]. |
|
940 |
prvLine := prvLine + step. |
|
941 |
]. |
|
942 |
] ifFalse:[ |
|
943 |
[ prvLine ~~ rowNr ] whileTrue:[ |
|
944 |
prvLine := prvLine + step. |
|
945 |
||
946 |
doAdd ~~ (self isInSelection:rowNr) ifTrue:[ |
|
947 |
chgSet add:prvLine. |
|
948 |
||
949 |
doAdd ifTrue:[ self addToSelection:prvLine ] |
|
950 |
ifFalse:[ self removeFromSelection:prvLine ]. |
|
951 |
] |
|
952 |
]. |
|
953 |
]. |
|
1748 | 954 |
]. |
955 |
]. |
|
2401 | 956 |
! |
1748 | 957 |
|
2401 | 958 |
buttonMotion:buttonMask x:x y:y |
959 |
"mouse-move while button was pressed - handle selection changes |
|
960 |
" |
|
961 |
|lnNr item| |
|
962 |
||
1748 | 963 |
self stopAutoScroll. |
964 |
||
2401 | 965 |
buttonMotionAction notNil ifTrue:[ |
966 |
buttonMotionAction value:(x@y). |
|
1747
f46c5941c028
better alghorithm for button motion in multipleSelection mode
ca
parents:
1745
diff
changeset
|
967 |
|
2401 | 968 |
(autoScroll and:[buttonMotionAction notNil]) ifTrue:[ |
969 |
"/ if moved outside of view, start autoscroll |
|
970 |
(y between:0 and:height) ifFalse:[ |
|
971 |
y < 0 ifTrue:[ self startAutoScroll:[self scrollUp] distance:y ] |
|
972 |
ifFalse:[ self startAutoScroll:[self scrollDown] distance:(y - height) ]. |
|
973 |
]. |
|
1390 | 974 |
]. |
2401 | 975 |
^ self |
1390 | 976 |
]. |
2401 | 977 |
|
978 |
(enabled and:[highlightEnterItem]) ifTrue:[ |
|
979 |
self sensor anyButtonPressed ifFalse:[ |
|
980 |
lnNr := self yVisibleToLineNr:y. |
|
981 |
||
982 |
lnNr notNil ifTrue:[ item := list at:lnNr ifAbsent:nil ] |
|
983 |
ifFalse:[ item := nil ]. |
|
984 |
||
985 |
self pointerEntersItem:item. |
|
986 |
] |
|
987 |
]. |
|
1390 | 988 |
! |
989 |
||
990 |
buttonMultiPress:button x:x y:y |
|
991 |
"button was pressed multiple - handle a doubleClick action |
|
992 |
" |
|
2401 | 993 |
buttonMotionAction := buttonReleaseAction := nil. |
1390 | 994 |
|
995 |
enabled ifFalse:[^ self]. |
|
996 |
||
997 |
((button == 1) or:[button == #select]) ifFalse:[ |
|
998 |
^ super buttonMultiPress:button x:x y:y |
|
999 |
]. |
|
1000 |
self doubleClicked |
|
1001 |
! |
|
1002 |
||
1003 |
buttonPress:button x:x y:y |
|
1004 |
"a button was pressed - handle selection here |
|
1005 |
" |
|
2401 | 1006 |
|sensor item menu appl isSelected lineNr startLine| |
1390 | 1007 |
|
2401 | 1008 |
buttonMotionAction := buttonReleaseAction := nil. |
1390 | 1009 |
|
2323 | 1010 |
self pointerEntersItem:nil. |
2377 | 1011 |
self cursorEntersItem:nil. |
2361 | 1012 |
self closeEditor. |
2323 | 1013 |
|
1390 | 1014 |
enabled ifFalse:[^ self]. |
1015 |
||
2228 | 1016 |
sensor := self sensor. |
2399 | 1017 |
sensor isNil ifTrue:[^ self]. |
1018 |
||
1019 |
lineNr := self yVisibleToLineNr:y. |
|
2228 | 1020 |
|
1578 | 1021 |
((button == 2) or:[button == #menu]) ifTrue:[ |
2228 | 1022 |
selectOnButtomMenu ifTrue:[ |
1023 |
( lineNr notNil |
|
1024 |
and:[lineNr ~~ self selectedIndex |
|
1025 |
and:[self canSelectIndex:lineNr forAdd:false ]] |
|
1026 |
) ifTrue:[ |
|
1027 |
(self selectWithoutScroll:lineNr redraw:true) ifTrue:[ |
|
1028 |
self selectionChanged |
|
1029 |
]. |
|
1030 |
item := self selectedElement. |
|
1031 |
] ifFalse:[ |
|
1032 |
item := nil |
|
1033 |
] |
|
1034 |
] ifFalse:[ |
|
1035 |
item := self selectedElement. |
|
1036 |
]. |
|
1578 | 1037 |
|
2308 | 1038 |
item notNil ifTrue:[ |
1039 |
self makeSelectionVisible. |
|
2228 | 1040 |
|
1041 |
menu := item perform:#middleButtonMenu ifNotUnderstood:nil. |
|
1042 |
||
2308 | 1043 |
menu notNil ifTrue:[ |
2228 | 1044 |
menu isCollection ifTrue:[ |
1045 |
menu := Menu new fromLiteralArrayEncoding:menu. |
|
1046 |
appl := self application. |
|
1047 |
||
1048 |
appl notNil ifTrue:[ |
|
1049 |
menu findGuiResourcesIn:appl. |
|
1050 |
"/ menu receiver:appl -- now done in findGuiResources ... |
|
1051 |
] ifFalse:[ |
|
1052 |
menu receiver:item |
|
1053 |
] |
|
1054 |
]. |
|
2333 | 1055 |
self startUpMenu:menu. |
2361 | 1056 |
^ self |
2228 | 1057 |
] |
1578 | 1058 |
]. |
2228 | 1059 |
super buttonPress:button x:x y:y. |
2361 | 1060 |
^ self |
1390 | 1061 |
]. |
2399 | 1062 |
lineNr isNil ifTrue:[ ^ self ]. |
1578 | 1063 |
|
2401 | 1064 |
sensor ctrlDown ifTrue:[ |
1065 |
self buttonControlPressAtLine:lineNr x:x y:y. |
|
1066 |
^ self |
|
1067 |
]. |
|
1068 |
||
1069 |
isSelected := self isInSelection:lineNr. |
|
2228 | 1070 |
|
2401 | 1071 |
(isSelected and:[sensor shiftDown not and:[self canDrag]]) ifTrue:[ |
1072 |
buttonMotionAction := [:p| |
|
1073 |
((x@y) dist:p) > 5.0 ifTrue:[ |
|
1074 |
buttonMotionAction := buttonReleaseAction := nil. |
|
1075 |
self startDragAt:p. |
|
1076 |
] |
|
2399 | 1077 |
]. |
2401 | 1078 |
buttonReleaseAction := [ self buttonPressOrReleaseAtLine:lineNr x:x y:y ]. |
1079 |
^ self |
|
1080 |
]. |
|
1390 | 1081 |
|
2401 | 1082 |
multipleSelectOk ifFalse:[ |
1083 |
(isSelected or:[self canSelectIndex:lineNr forAdd:false]) ifTrue:[ |
|
2399 | 1084 |
self buttonPressOrReleaseAtLine:lineNr x:x y:y. |
1085 |
]. |
|
1086 |
^ self |
|
1087 |
]. |
|
2401 | 1088 |
startLine := lineNr. |
2399 | 1089 |
|
2401 | 1090 |
sensor shiftDown ifTrue:[ |min max| |
1091 |
(isSelected or:[self canSelectIndex:lineNr forAdd:true]) ifFalse:[ |
|
1644 | 1092 |
^ self |
1390 | 1093 |
]. |
1920 | 1094 |
|
2401 | 1095 |
multipleSelectOk ifTrue:[ |
1096 |
startLine := self firstInSelection. |
|
1097 |
startLine isNil ifTrue:[ startLine := lineNr ]. |
|
1098 |
||
1099 |
startLine <= lineNr ifTrue:[ |
|
1100 |
self selectFrom:startLine to:lineNr. |
|
1101 |
] ifFalse:[ |
|
1102 |
startLine := self lastInSelection. |
|
1103 |
self selectFrom:lineNr to:startLine. |
|
1104 |
]. |
|
1105 |
] |
|
1106 |
] ifFalse:[ |
|
1107 |
(isSelected or:[self canSelectIndex:lineNr forAdd:false]) ifFalse:[ |
|
1390 | 1108 |
^ self |
2401 | 1109 |
]. |
1110 |
self buttonPressOrReleaseAtLine:lineNr x:x y:y. |
|
1390 | 1111 |
]. |
1112 |
||
2401 | 1113 |
multipleSelectOk ifTrue:[ |
1114 |
buttonMotionAction := [:p| |ln| |
|
1115 |
(p y between:0 and:height) ifTrue:[ |
|
1116 |
ln := self yVisibleToLineNr:p y. |
|
1117 |
ln isNil ifTrue:[ln := list size]. |
|
1118 |
self selectFrom:startLine to:ln. |
|
1119 |
]. |
|
1120 |
]. |
|
1915 | 1121 |
]. |
1122 |
! |
|
1123 |
||
1124 |
buttonPressOrReleaseAtLine:aLnNr x:x y:y |
|
1125 |
"handle a button press or release at a line |
|
1126 |
" |
|
1127 |
aLnNr == self selectedIndex ifTrue:[ |
|
1128 |
editorView notNil ifTrue:[^ self]. |
|
1129 |
||
1130 |
openEditorAction notNil ifTrue:[ |
|
1131 |
self openEditorAtX:x y:y. |
|
1132 |
editorView notNil ifTrue:[^ self]. |
|
1741
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
1133 |
]. |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
1134 |
|
1915 | 1135 |
ignoreReselect ifFalse:[ |
1136 |
(toggleSelect and:[self sensor ctrlDown]) ifTrue:[ |
|
1137 |
self selection:nil |
|
1138 |
] ifFalse:[ |
|
1139 |
self selectionChanged |
|
1741
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
1140 |
]. |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
1141 |
]. |
1915 | 1142 |
] ifFalse:[ |
1143 |
(self selectWithoutScroll:aLnNr redraw:true) ifTrue:[ |
|
1144 |
self selectionChanged |
|
1145 |
] |
|
1741
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
1146 |
]. |
1390 | 1147 |
! |
1148 |
||
1149 |
buttonRelease:button x:x y:y |
|
1150 |
"a button was released |
|
1151 |
" |
|
2401 | 1152 |
buttonMotionAction := nil. |
1915 | 1153 |
|
2401 | 1154 |
buttonReleaseAction notNil ifTrue:[ |
1155 |
buttonReleaseAction value. |
|
1156 |
buttonReleaseAction := nil. |
|
1157 |
]. |
|
1915 | 1158 |
|
2377 | 1159 |
self cursorEntersItem:nil. |
1748 | 1160 |
self stopAutoScroll. |
1390 | 1161 |
! |
1162 |
||
1163 |
characterPress:aKey x:x y:y |
|
1164 |
" a character is pressed - lookup and change selection |
|
1165 |
" |
|
1166 |
|lnNr size idx sensor stp to1 fr2| |
|
1167 |
||
1168 |
(enabled and:[(size := self size) > 1]) ifFalse:[ |
|
1169 |
^ self |
|
1170 |
]. |
|
1171 |
lnNr := self firstInSelection ? 0. |
|
1172 |
||
1173 |
((sensor := self sensor) notNil and:[sensor shiftDown]) ifTrue:[ |
|
1174 |
stp := -1. "/ search backward |
|
1175 |
to1 := 1. |
|
1176 |
fr2 := size. |
|
1177 |
] ifFalse:[ |
|
1178 |
stp := 1. "/ search forward |
|
1179 |
to1 := size. |
|
1180 |
fr2 := 1. |
|
1181 |
]. |
|
1182 |
||
1183 |
idx := self findLineFrom:lnNr+stp to:to1 by:stp startingWithCharacter:aKey. |
|
1184 |
||
1185 |
idx == 0 ifTrue:[ |
|
1186 |
idx := self findLineFrom:fr2 to:lnNr-stp by:stp startingWithCharacter:aKey |
|
1187 |
]. |
|
1188 |
idx ~~ 0 ifTrue:[^ self selection:idx] |
|
1189 |
! |
|
1190 |
||
1768
04b330a75f75
allow for subclasses to redefine character search
Claus Gittinger <cg@exept.de>
parents:
1758
diff
changeset
|
1191 |
characterSearchItemStringAt:anIndex |
04b330a75f75
allow for subclasses to redefine character search
Claus Gittinger <cg@exept.de>
parents:
1758
diff
changeset
|
1192 |
|item| |
04b330a75f75
allow for subclasses to redefine character search
Claus Gittinger <cg@exept.de>
parents:
1758
diff
changeset
|
1193 |
|
04b330a75f75
allow for subclasses to redefine character search
Claus Gittinger <cg@exept.de>
parents:
1758
diff
changeset
|
1194 |
item := list at:anIndex ifAbsent:nil. |
04b330a75f75
allow for subclasses to redefine character search
Claus Gittinger <cg@exept.de>
parents:
1758
diff
changeset
|
1195 |
item isNil ifTrue:[^ item]. |
04b330a75f75
allow for subclasses to redefine character search
Claus Gittinger <cg@exept.de>
parents:
1758
diff
changeset
|
1196 |
|
04b330a75f75
allow for subclasses to redefine character search
Claus Gittinger <cg@exept.de>
parents:
1758
diff
changeset
|
1197 |
^ item perform:#string ifNotUnderstood:nil. |
04b330a75f75
allow for subclasses to redefine character search
Claus Gittinger <cg@exept.de>
parents:
1758
diff
changeset
|
1198 |
|
04b330a75f75
allow for subclasses to redefine character search
Claus Gittinger <cg@exept.de>
parents:
1758
diff
changeset
|
1199 |
! |
04b330a75f75
allow for subclasses to redefine character search
Claus Gittinger <cg@exept.de>
parents:
1758
diff
changeset
|
1200 |
|
1917
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1201 |
containerChangedSize |
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1202 |
"/ stupid kludge for motif-style (which draws a frame at the right-edge) |
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1203 |
"/ cg: I think it should not (see normal SelectionInListView, which does only |
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1204 |
"/ draw the frame at the top and bottom, but NOT at the left and right |
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1205 |
|
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1206 |
selection notNil ifTrue:[ |
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1207 |
(hilightFrameColor notNil |
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1208 |
or:[hilightStyle == #motif |
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1209 |
or:[hilightLevel ~~ 0]]) ifTrue:[ |
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1210 |
"/ invalidate the right-edge |
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1211 |
self invalidate:(((width-3) @ 0) corner:((width-1) @ (height-1))). |
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1212 |
] |
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1213 |
]. |
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1214 |
|
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1215 |
super containerChangedSize. |
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1216 |
! |
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1217 |
|
2377 | 1218 |
cursorEntersItem:anItemOrNil |
1219 |
"the cursor enters an item or nil |
|
1220 |
" |
|
1221 |
|lnNr x| |
|
1222 |
||
1223 |
(shown and:[list size ~~ 0]) ifFalse:[ |
|
1224 |
cursorItem := nil. |
|
1225 |
^ self. |
|
1226 |
]. |
|
1227 |
||
1228 |
anItemOrNil == cursorItem ifTrue:[ ^ self ]. |
|
1229 |
||
1230 |
2 timesRepeat:[ |
|
1231 |
cursorItem notNil ifTrue:[ |
|
1232 |
lnNr := list identityIndexOf:cursorItem. |
|
1233 |
lnNr notNil ifTrue:[ |
|
1234 |
x := self xVisibleOfItem:cursorItem. |
|
1235 |
self invalidateLineAt:lnNr fromX:x |
|
1236 |
]. |
|
1237 |
]. |
|
1238 |
"/ set the new item |
|
1239 |
cursorItem := anItemOrNil. |
|
1240 |
]. |
|
1241 |
cursorItem notNil ifTrue:[ |
|
1242 |
self makeLineVisible:lnNr |
|
1243 |
]. |
|
1244 |
! |
|
1245 |
||
1390 | 1246 |
doubleClicked |
1247 |
"handle a double click |
|
1248 |
" |
|
1249 |
(doubleClickActionBlock notNil and:[self numberOfSelections == 1]) ifTrue:[ |
|
1250 |
(doubleClickActionBlock numArgs == 1) ifTrue:[ |
|
1251 |
doubleClickActionBlock value:(self selectedIndex) |
|
1252 |
] ifFalse:[ |
|
1253 |
doubleClickActionBlock value |
|
1254 |
] |
|
1255 |
] |
|
1256 |
||
1257 |
! |
|
1258 |
||
1259 |
findLineFrom:aStart to:aStop by:aStep startingWithCharacter:aCharacter |
|
1260 |
"find a line starting with a character |
|
1261 |
" |
|
1262 |
|item char lbl cmp |
|
1263 |
size "{ Class:SmallInteger }" |
|
1264 |
start "{ Class:SmallInteger }" |
|
1265 |
stop "{ Class:SmallInteger }" |
|
1266 |
| |
|
1267 |
(size := list size) ~~ 0 ifTrue:[ |
|
1268 |
aStep > 0 ifTrue:[ |
|
1269 |
aStart > aStop ifTrue:[^ 0]. |
|
1270 |
] ifFalse:[ |
|
1271 |
(aStep == 0 or:[aStop > aStart]) ifTrue:[^ 0] |
|
1272 |
]. |
|
1273 |
||
1274 |
start := aStart < 0 ifTrue:[1] ifFalse:[aStart min:size]. |
|
1275 |
stop := aStop < 0 ifTrue:[1] ifFalse:[aStop min:size]. |
|
1276 |
char := aCharacter asUppercase. |
|
1277 |
||
1278 |
start to:stop by:aStep do:[:anIndex| |
|
1920 | 1279 |
(self canSelectIndex:anIndex forAdd:false) ifTrue:[ |
1772 | 1280 |
lbl := self characterSearchItemStringAt:anIndex. |
1281 |
lbl notNil ifTrue:[ |
|
1282 |
cmp := lbl string at:1 ifAbsent:nil. |
|
1390 | 1283 |
|
1772 | 1284 |
cmp notNil ifTrue:[ |
1285 |
(char == cmp or:[char == cmp asUppercase]) ifTrue:[ |
|
1286 |
^ anIndex |
|
1287 |
] |
|
1390 | 1288 |
] |
1289 |
] |
|
1290 |
] |
|
1291 |
] |
|
1292 |
]. |
|
1293 |
^ 0 |
|
1294 |
! |
|
1295 |
||
1296 |
keyPress:aKey x:x y:y |
|
1297 |
"a key was pressed - handle page-keys here |
|
1298 |
" |
|
2365
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1299 |
<resource: #keyboard( #CursorUp #CursorDown #EndOfText #EndOfLine |
2377 | 1300 |
#BeginOfText #BeginOfLine #Return |
1301 |
#CmdReturn #CmdCursorUp #CmdCursorDown )> |
|
1390 | 1302 |
|
2377 | 1303 |
|lineNr listSize sensor shifted newSel step start| |
1390 | 1304 |
|
2377 | 1305 |
enabled ifFalse:[ ^ self ]. |
1306 |
||
1307 |
listSize := list size. |
|
1308 |
listSize == 0 ifTrue:[^ self]. |
|
1309 |
||
2365
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1310 |
aKey isCharacter ifTrue:[ |
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1311 |
self characterPress:aKey x:x y:y. |
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1312 |
^ self |
1390 | 1313 |
]. |
1314 |
||
2377 | 1315 |
aKey == #Escape ifTrue:[ |
1316 |
cursorItem notNil ifTrue:[ |
|
1317 |
self cursorEntersItem:nil. |
|
1318 |
self makeSelectionVisible. |
|
1319 |
]. |
|
1320 |
super keyPress:aKey x:x y:y. |
|
2365
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1321 |
^ self |
1390 | 1322 |
]. |
1323 |
||
2365
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1324 |
((aKey == #BeginOfText) or:[aKey == #BeginOfLine]) ifTrue:[ |
2377 | 1325 |
self cursorEntersItem:nil. |
1326 |
||
2368 | 1327 |
1 to:listSize do:[:i| |
2377 | 1328 |
(self canSelectIndex:i forAdd:false) ifTrue:[ |
1329 |
self selection:i. |
|
1330 |
^ self |
|
1331 |
]. |
|
2368 | 1332 |
]. |
1390 | 1333 |
^ self |
1334 |
]. |
|
1335 |
||
2365
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1336 |
((aKey == #EndOfText) or:[aKey == #EndOfLine]) ifTrue:[ |
2377 | 1337 |
self cursorEntersItem:nil. |
1338 |
||
2368 | 1339 |
listSize to:1 by:-1 do:[:i| |
2377 | 1340 |
(self canSelectIndex:i forAdd:false) ifTrue:[ |
1341 |
self selection:i. |
|
1342 |
^ self |
|
1343 |
]. |
|
1344 |
]. |
|
1345 |
^ self |
|
1346 |
]. |
|
1347 |
lineNr := self cursorLine. |
|
1348 |
||
1349 |
aKey == #CmdReturn ifTrue:[ |
|
1350 |
"/ toggle item under selection |
|
1351 |
lineNr == 0 ifTrue:[ |
|
1352 |
lineNr := self selectedIndex. |
|
1353 |
lineNr == 0 ifTrue:[^ self]. |
|
1354 |
]. |
|
1355 |
( (self isInSelection:lineNr) |
|
1356 |
or:[(self canSelectIndex:lineNr forAdd:true)] |
|
1357 |
) ifTrue:[ |
|
1358 |
self toggleSelection:lineNr. |
|
1359 |
self selectionChanged. |
|
2368 | 1360 |
]. |
2365
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1361 |
^ self |
1390 | 1362 |
]. |
1363 |
||
2377 | 1364 |
aKey == #Return ifTrue:[ |
1365 |
lineNr ~~ 0 ifTrue:[ |
|
1366 |
self cursorEntersItem:nil. |
|
1367 |
||
1368 |
(self canSelectIndex:lineNr forAdd:false) ifTrue:[ |
|
1369 |
self selection:lineNr |
|
1370 |
]. |
|
1371 |
]. |
|
1372 |
self numberOfSelections == 1 ifTrue:[ self doubleClicked ]. |
|
1373 |
^ self |
|
1374 |
]. |
|
1375 |
||
1376 |
(aKey == #CursorUp or:[aKey == #CursorDown or:[aKey == #CmdCursorDown or:[aKey == #CmdCursorUp]]] |
|
1377 |
) ifFalse:[ |
|
2365
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1378 |
super keyPress:aKey x:x y:y. |
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1379 |
^ self |
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1380 |
]. |
1909 | 1381 |
|
2368 | 1382 |
multipleSelectOk ifFalse:[ |
2377 | 1383 |
shifted := false. |
1384 |
lineNr == 0 ifTrue:[ lineNr := selection ? 0 ]. |
|
2368 | 1385 |
] ifTrue:[ |
1386 |
sensor := self sensor. |
|
1387 |
shifted := sensor notNil and:[sensor shiftDown]. |
|
1772 | 1388 |
|
2377 | 1389 |
lineNr == 0 ifTrue:[ |
1390 |
selection size ~~ 0 ifTrue:[ lineNr := selection last ]. |
|
2368 | 1391 |
] |
1392 |
]. |
|
2365
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1393 |
|
2377 | 1394 |
aKey == #CmdCursorDown ifTrue:[ |
1395 |
lineNr := lineNr + 1. |
|
1396 |
lineNr > listSize ifTrue:[ lineNr := 1]. |
|
1397 |
self cursorEntersItem:(list at:lineNr). |
|
1398 |
^ self |
|
1399 |
]. |
|
1400 |
||
1401 |
aKey == #CmdCursorUp ifTrue:[ |
|
1402 |
lineNr := lineNr - 1. |
|
1403 |
lineNr < 1 ifTrue:[ lineNr := listSize]. |
|
1404 |
self cursorEntersItem:(list at:lineNr). |
|
2368 | 1405 |
^ self |
1390 | 1406 |
]. |
2377 | 1407 |
self cursorEntersItem:nil. |
1408 |
||
1409 |
aKey == #CursorDown ifTrue:[ step := 1 ] |
|
1410 |
ifFalse:[ step := -1 ]. |
|
1411 |
start := lineNr. |
|
1412 |
lineNr := lineNr + step. |
|
2368 | 1413 |
|
2377 | 1414 |
[ lineNr ~~ start ] whileTrue:[ |
1415 |
(lineNr between:1 and:listSize) ifFalse:[ |
|
1416 |
lineNr < 1 ifTrue:[ lineNr := listSize ] |
|
1417 |
ifFalse:[ lineNr := 1 ]. |
|
1418 |
] ifTrue:[ |
|
1419 |
(self canSelectIndex:lineNr forAdd:shifted) ifTrue:[ |
|
1420 |
shifted ifFalse:[ |
|
1421 |
self selection:lineNr. |
|
1422 |
^ self |
|
1423 |
]. |
|
1424 |
(self isInSelection:lineNr) ifFalse:[ |
|
1425 |
selection isNil ifTrue:[ newSel := Array with:lineNr ] |
|
1426 |
ifFalse:[ newSel := selection copyWith:lineNr ]. |
|
1427 |
] ifTrue:[ |
|
1428 |
(start ~~ 0 and:[selection size > 1]) ifFalse:[ |
|
1429 |
^ self |
|
1430 |
]. |
|
1431 |
newSel := selection copyWithout:start. |
|
1432 |
]. |
|
1433 |
self selectWithoutScroll:newSel redraw:true. |
|
1434 |
self makeLineVisible:lineNr. |
|
1435 |
self selectionChanged. |
|
1436 |
^ self |
|
1437 |
]. |
|
1438 |
lineNr := lineNr + step. |
|
1439 |
] |
|
1440 |
]. |
|
1917
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1441 |
! |
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1442 |
|
2323 | 1443 |
pointerEntersItem:anItemOrNil |
1444 |
"the pointer moves over an item or nil |
|
1445 |
" |
|
1446 |
|lnNr x newItem| |
|
1447 |
||
1448 |
(shown and:[list size ~~ 0]) ifFalse:[ |
|
1449 |
enterItem := nil. |
|
1450 |
^ self. |
|
1451 |
]. |
|
1452 |
||
1453 |
highlightEnterItem ifTrue:[ newItem := anItemOrNil ] |
|
1454 |
ifFalse:[ newItem := nil ]. |
|
1455 |
||
1456 |
anItemOrNil == enterItem ifTrue:[ ^ self ]. |
|
1457 |
||
1458 |
2 timesRepeat:[ |
|
1459 |
enterItem notNil ifTrue:[ |
|
1460 |
lnNr := list identityIndexOf:enterItem. |
|
1461 |
lnNr notNil ifTrue:[ |
|
1462 |
x := self xVisibleOfItem:enterItem. |
|
1463 |
self invalidateLineAt:lnNr fromX:x |
|
1464 |
]. |
|
1465 |
]. |
|
1466 |
"/ set the new item |
|
1467 |
enterItem := anItemOrNil. |
|
1468 |
]. |
|
1469 |
! |
|
1470 |
||
1471 |
pointerLeave:state |
|
1472 |
self pointerEntersItem:nil. |
|
1473 |
super pointerLeave:state. |
|
1474 |
! |
|
1475 |
||
1917
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1476 |
sizeChanged:how |
2274
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2250
diff
changeset
|
1477 |
|selectionWasVisible| |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2250
diff
changeset
|
1478 |
|
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2250
diff
changeset
|
1479 |
selectionWasVisible := false. |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2250
diff
changeset
|
1480 |
|
1917
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1481 |
"/ stupid kludge for motif-style (which draws a frame at the right-edge) |
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1482 |
"/ cg: I think it should not (see normal SelectionInListView, which does only |
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1483 |
"/ draw the frame at the top and bottom, but NOT at the left and right |
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1484 |
selection notNil ifTrue:[ |
2275 | 1485 |
selectionWasVisible := self isSelectionVisibleIn:(previousExtent ? self extent). |
2274
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2250
diff
changeset
|
1486 |
|
1917
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1487 |
(hilightFrameColor notNil |
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1488 |
or:[hilightStyle == #motif |
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1489 |
or:[hilightLevel ~~ 0]]) ifTrue:[ |
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1490 |
"/ invalidate the right-edge |
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1491 |
self invalidate:(((width-3) @ 0) corner:((width-1) @ (height-1))). |
2225 | 1492 |
]. |
1917
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1493 |
]. |
21964f5b1cc1
fixed selection redraw when resizing (larger) in motif mode
Claus Gittinger <cg@exept.de>
parents:
1915
diff
changeset
|
1494 |
super sizeChanged:how. |
2274
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2250
diff
changeset
|
1495 |
|
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2250
diff
changeset
|
1496 |
selectionWasVisible ifTrue:[ |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2250
diff
changeset
|
1497 |
self makeSelectionVisible |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2250
diff
changeset
|
1498 |
]. |
1390 | 1499 |
! ! |
1500 |
||
1421 | 1501 |
!SelectionInListModelView methodsFor:'focus handling'! |
1502 |
||
1503 |
wantsFocusWithPointerEnter |
|
1504 |
"return true, if I want the focus when |
|
1505 |
the mouse pointer enters" |
|
1506 |
||
1507 |
|pref| |
|
1508 |
||
1509 |
pref := UserPreferences current focusFollowsMouse. |
|
1510 |
(pref ~~ false |
|
1511 |
and:[(styleSheet at:#'selection.requestFocusOnPointerEnter' default:true) |
|
1512 |
]) ifTrue:[ |
|
2055
964a2cac4e55
take focus on pointer enter only if the list is not empty.
Claus Gittinger <cg@exept.de>
parents:
1920
diff
changeset
|
1513 |
list size > 0 ifTrue:[ |
964a2cac4e55
take focus on pointer enter only if the list is not empty.
Claus Gittinger <cg@exept.de>
parents:
1920
diff
changeset
|
1514 |
^ true |
964a2cac4e55
take focus on pointer enter only if the list is not empty.
Claus Gittinger <cg@exept.de>
parents:
1920
diff
changeset
|
1515 |
] |
1421 | 1516 |
]. |
1517 |
^ false |
|
1518 |
! ! |
|
1519 |
||
1390 | 1520 |
!SelectionInListModelView methodsFor:'initialize / release'! |
1521 |
||
1522 |
fetchResources |
|
1523 |
"fetch device colors and ..., to avoid reallocation at redraw time; |
|
1524 |
*** called after a create or snapin to fetch all device resources |
|
1525 |
" |
|
1526 |
||
1527 |
super fetchResources. |
|
1528 |
||
1529 |
hilightFgColor := self colorOnDevice:hilightFgColor. |
|
1530 |
hilightBgColor := self colorOnDevice:hilightBgColor. |
|
1531 |
hilightFrameColor := self colorOnDevice:hilightFrameColor. |
|
2377 | 1532 |
lineMask := lineMask onDevice:device. |
1390 | 1533 |
! |
1534 |
||
1535 |
initStyle |
|
1536 |
"setup viewStyle specifics |
|
1537 |
" |
|
1538 |
super initStyle. |
|
1539 |
||
2377 | 1540 |
lineMask isNil ifTrue:[ |
1541 |
lineMask := Form width:2 height:2 fromArray:#[16rAA 16r55]. |
|
1542 |
]. |
|
1543 |
||
2228 | 1544 |
hilightFrameColor := nil. |
1545 |
hilightStyle := DefaultHilightStyle. |
|
1546 |
highlightMode := #label. |
|
1547 |
textStartLeft := 4. |
|
2309 | 1548 |
selectOnButtomMenu := styleSheet at:#'selection.selectOnButtomMenu' default:false. |
1390 | 1549 |
|
1741
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
1550 |
super font:(styleSheet fontAt:#'selection.font'). |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
1551 |
|
1390 | 1552 |
device hasGrayscales ifTrue:[ |
1553 |
" |
|
1554 |
must get rid of these hard codings |
|
1555 |
" |
|
1556 |
(hilightStyle == #next) ifTrue:[ |
|
1557 |
hilightFgColor := fgColor. |
|
1558 |
hilightBgColor := White. |
|
1559 |
hilightFrameColor := fgColor |
|
1560 |
] ifFalse:[ |
|
1561 |
(hilightStyle == #motif) ifTrue:[ |
|
1562 |
fgColor := White. |
|
1563 |
bgColor := Grey. |
|
1564 |
viewBackground := bgColor. |
|
1565 |
hilightFgColor := bgColor. |
|
1566 |
hilightBgColor := fgColor. |
|
1567 |
] ifFalse:[ |
|
1568 |
(hilightStyle == #openwin) ifTrue:[ |
|
1569 |
hilightFgColor := fgColor. |
|
1570 |
hilightBgColor := Color grey. |
|
1571 |
] |
|
1572 |
] |
|
1573 |
] |
|
1574 |
]. |
|
1575 |
||
1576 |
hilightFgColor isNil ifTrue:[ |
|
1577 |
hilightFgColor := bgColor. |
|
1578 |
]. |
|
1579 |
hilightBgColor isNil ifTrue:[ |
|
1580 |
hilightBgColor := fgColor. |
|
1581 |
]. |
|
1582 |
DefaultForegroundColor notNil ifTrue:[ |
|
1583 |
fgColor := DefaultForegroundColor |
|
1584 |
]. |
|
1585 |
DefaultBackgroundColor notNil ifTrue:[ |
|
1586 |
bgColor := viewBackground := DefaultBackgroundColor |
|
1587 |
]. |
|
1588 |
||
1589 |
DefaultHilightForegroundColor notNil ifTrue:[ |
|
1590 |
hilightFgColor := DefaultHilightForegroundColor |
|
1591 |
]. |
|
1592 |
DefaultHilightBackgroundColor notNil ifTrue:[ |
|
1593 |
hilightBgColor := DefaultHilightBackgroundColor |
|
1594 |
]. |
|
1595 |
DefaultHilightFrameColor notNil ifTrue:[ |
|
1596 |
hilightFrameColor := DefaultHilightFrameColor |
|
1597 |
]. |
|
1598 |
||
1741
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
1599 |
hilightLevel := DefaultHilightLevel ? 0. |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
1600 |
lineSpacing := (hilightLevel abs > 0) ifTrue:[3] ifFalse:[2]. |
d928cdc5f4e5
add #ignoreReselect #toggleSelect; behaviour like SelectionInListView
ca
parents:
1739
diff
changeset
|
1601 |
|
1390 | 1602 |
hilightFgColor isNil ifTrue:[ |
1603 |
hilightFgColor := bgColor. |
|
1604 |
hilightBgColor := fgColor |
|
1605 |
]. |
|
1606 |
! |
|
1607 |
||
1608 |
initialize |
|
1609 |
"setup default attributes/behavior |
|
1610 |
" |
|
2323 | 1611 |
multipleSelectOk := false. |
1612 |
useIndex := true. |
|
1613 |
ignoreReselect := true. |
|
1614 |
toggleSelect := false. |
|
1615 |
highlightEnterItem := false. |
|
2324 | 1616 |
|
1617 |
super initialize. |
|
1390 | 1618 |
! |
1619 |
||
1745 | 1620 |
mapped |
1621 |
"get selection from model; scroll to selection |
|
1622 |
" |
|
1623 |
super mapped. |
|
1624 |
self makeSelectionVisible. |
|
1625 |
! |
|
1626 |
||
1390 | 1627 |
realize |
1628 |
"get selection from model; scroll to selection |
|
1629 |
" |
|
2302
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2275
diff
changeset
|
1630 |
self updateFromModel. |
1390 | 1631 |
super realize. |
1632 |
! ! |
|
1633 |
||
1755 | 1634 |
!SelectionInListModelView methodsFor:'private editor'! |
1635 |
||
1636 |
computeEditorLayout |
|
1637 |
"update the layout of the editor |
|
1638 |
" |
|
1639 |
|lnNr item y x h| |
|
1640 |
||
1641 |
editorView isNil ifTrue:[ |
|
1642 |
^ self |
|
1643 |
]. |
|
1644 |
||
1645 |
( (lnNr := self selectedIndex) == 0 |
|
1646 |
or:[(item := list at:lnNr ifAbsent:nil) isNil] |
|
1647 |
) ifTrue:[ |
|
1648 |
"/ there is no more single selection; thus close the editor |
|
1649 |
^ self closeEditor |
|
1650 |
]. |
|
1651 |
||
1652 |
y := self yVisibleOfLine:lnNr. |
|
1653 |
x := (self xVisibleOfItem:item) - (textStartLeft // 2). |
|
1654 |
h := self yVisibleOfLine:(lnNr + 1). |
|
1655 |
||
1656 |
editorView layout:( Rectangle left:x top:y right:(width - 1 - margin) bottom:(h - 1) ). |
|
1657 |
! |
|
1658 |
||
1659 |
openEditorAtX:x y:y |
|
1660 |
"opens an editor on the current single selection |
|
1661 |
" |
|
2225 | 1662 |
|item lnNr x0 y0 editor| |
1755 | 1663 |
|
1664 |
self closeEditor. |
|
2308 | 1665 |
shown ifFalse:[^ self ]. |
1666 |
openEditorAction isNil ifTrue:[^ self]. |
|
1755 | 1667 |
|
2225 | 1668 |
lnNr := self selectedIndex. |
1669 |
lnNr == 0 ifTrue:[^ self]. |
|
1670 |
||
1671 |
item := list at:lnNr ifAbsent:nil. |
|
2308 | 1672 |
item isNil ifTrue:[^ self]. |
1755 | 1673 |
|
1915 | 1674 |
x < (self xVisibleOfItem:item) ifTrue:[ |
1675 |
"/ not part of the selection frame; ignorre |
|
1676 |
^ self |
|
1755 | 1677 |
]. |
2225 | 1678 |
editor := self openEditor. |
2308 | 1679 |
editor isNil ifTrue:[^ self]. |
1755 | 1680 |
|
2225 | 1681 |
y0 := (y - editor origin y) max:0. |
1682 |
x0 := (x - editor origin x) max:0. |
|
1755 | 1683 |
|
2125 | 1684 |
"/ simulate clicking into the editor |
2225 | 1685 |
self sensor pushEvent:(WindowEvent buttonPress:#select x:x0 y:y0 view:editor). |
1686 |
self sensor pushEvent:(WindowEvent buttonRelease:#select x:x0 y:y0 view:editor). |
|
1755 | 1687 |
|
1688 |
"/ to clear the selection |
|
2245
546c6e5d0951
change #redrawSelectionAt: to #invalidateSelectionAt: (because is a invalidate)
ca
parents:
2228
diff
changeset
|
1689 |
self invalidateLineAt:lnNr. |
1755 | 1690 |
! ! |
1691 |
||
1390 | 1692 |
!SelectionInListModelView methodsFor:'protocol'! |
1693 |
||
1533 | 1694 |
drawElementsFrom:start to:stop x:x y:y w:w |
1390 | 1695 |
"draw the items between start to stop without clearing the background |
1696 |
" |
|
1697 |
|y0 "{ Class:SmallInteger }" |
|
1698 |
y1 "{ Class:SmallInteger }" |
|
1699 |
x0 "{ Class:SmallInteger }" |
|
1700 |
| |
|
1701 |
x0 := textStartLeft - viewOrigin x. |
|
1533 | 1702 |
y1 := y. |
1390 | 1703 |
|
1704 |
start to:stop do:[:i| |
|
1705 |
y0 := y1. |
|
1706 |
y1 := self yVisibleOfLine:(i + 1). |
|
1533 | 1707 |
self drawLabelAt:i x:x0 y:y0 h:(y1 - y0) |
1390 | 1708 |
]. |
1709 |
||
1710 |
||
1711 |
! |
|
1712 |
||
1458 | 1713 |
lostSynchronisation |
1714 |
"called when the changes derived from the model are faster than the handling |
|
1715 |
" |
|
1547 | 1716 |
self deselectWithoutRedraw. |
1458 | 1717 |
super lostSynchronisation. |
1554 | 1718 |
! |
1719 |
||
1720 |
xVisibleOfItem:anItem |
|
1721 |
"returns the visible x of the labeled text |
|
1722 |
" |
|
1723 |
^ textStartLeft - viewOrigin x |
|
1724 |
||
1725 |
||
1390 | 1726 |
! ! |
1727 |
||
2330 | 1728 |
!SelectionInListModelView methodsFor:'queries'! |
1729 |
||
1730 |
isCursorKeyConsumer |
|
1731 |
"return true, if the receiver can be controlled by cursor keys; |
|
1732 |
i.e. it can handle some keyboard input, |
|
1733 |
isCursorKeyConsumer are potential candidates for getting the keyboard |
|
1734 |
focus initially within dialogBoxes, or when the focus-follows-pointer |
|
1735 |
mode is off. |
|
1736 |
Return false here, this is redefined in SelectionInListView." |
|
1737 |
||
1738 |
^ true |
|
1739 |
! ! |
|
1740 |
||
1390 | 1741 |
!SelectionInListModelView methodsFor:'selection'! |
1742 |
||
2401 | 1743 |
addToSelection:lineNr |
1744 |
||
1745 |
(self isInSelection:lineNr) ifTrue:[ |
|
1746 |
^ self |
|
1747 |
]. |
|
1748 |
self closeEditor. |
|
1749 |
||
1750 |
multipleSelectOk ifFalse:[ |
|
1751 |
(self canSelectIndex:lineNr forAdd:false) ifTrue:[ |
|
1752 |
self selection:lineNr. |
|
1753 |
]. |
|
1754 |
^ self |
|
1755 |
]. |
|
1756 |
||
1757 |
self numberOfSelections == 0 ifTrue:[ |
|
1758 |
(self canSelectIndex:lineNr forAdd:true) ifTrue:[ |
|
1759 |
self selection:lineNr. |
|
1760 |
]. |
|
1761 |
^ self |
|
1762 |
]. |
|
1763 |
||
1764 |
selection := selection copyWith:lineNr. |
|
1765 |
self invalidateSelectionAt:lineNr. |
|
1766 |
self selectionChanged. |
|
1767 |
! |
|
1768 |
||
1390 | 1769 |
deselect |
1770 |
"clear selection |
|
1771 |
" |
|
1772 |
self selection:nil |
|
1773 |
||
1774 |
! |
|
1775 |
||
1776 |
firstInSelection |
|
2399 | 1777 |
"returns the minimum index of selected indices or nil if nothing is selected |
1390 | 1778 |
" |
2365
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1779 |
|size min| |
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1780 |
|
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1781 |
selection isNil ifTrue:[^ nil]. |
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1782 |
|
1545 | 1783 |
multipleSelectOk ifFalse:[ |
1784 |
^ selection |
|
1390 | 1785 |
]. |
2365
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1786 |
size := selection size. |
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1787 |
size == 0 ifTrue:[ ^ nil ]. |
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1788 |
|
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1789 |
min := selection at:1. |
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1790 |
|
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1791 |
size > 1 ifTrue:[ |
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1792 |
selection do:[:aNumber| min := min min:aNumber ]. |
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1793 |
]. |
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1794 |
^ min |
1390 | 1795 |
! |
1796 |
||
1797 |
hasSelection |
|
1798 |
"returns true if a selection exists |
|
1799 |
" |
|
1800 |
^ selection notNil |
|
1801 |
||
1802 |
! |
|
1803 |
||
1804 |
isInSelection:aNumber |
|
1805 |
"return true, if line, aNumber is in the selection |
|
1806 |
" |
|
1545 | 1807 |
multipleSelectOk ifFalse:[ |
1808 |
^ aNumber == selection |
|
1809 |
]. |
|
1810 |
^ selection isNil ifTrue:[false] |
|
1811 |
ifFalse:[selection includesIdentical:aNumber] |
|
1390 | 1812 |
! |
1813 |
||
2274
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2250
diff
changeset
|
1814 |
isSelectionVisible |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2250
diff
changeset
|
1815 |
"returns true if any selected element is visible" |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2250
diff
changeset
|
1816 |
|
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2250
diff
changeset
|
1817 |
^ self isSelectionVisibleIn:self extent |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2250
diff
changeset
|
1818 |
! |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2250
diff
changeset
|
1819 |
|
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2250
diff
changeset
|
1820 |
isSelectionVisibleIn:anExtentPoint |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2250
diff
changeset
|
1821 |
"returns true if any selected element is visible" |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2250
diff
changeset
|
1822 |
|
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2250
diff
changeset
|
1823 |
self selectionDo:[:aLineNr| |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2250
diff
changeset
|
1824 |
(self isLineVisible:aLineNr in:anExtentPoint) ifTrue:[^ true]. |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2250
diff
changeset
|
1825 |
]. |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2250
diff
changeset
|
1826 |
^ false |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2250
diff
changeset
|
1827 |
! |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2250
diff
changeset
|
1828 |
|
2330 | 1829 |
lastInSelection |
2399 | 1830 |
"returns the maximum index of selected indices or nil if nothing is selected |
2330 | 1831 |
" |
2365
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1832 |
|size max| |
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1833 |
|
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1834 |
selection isNil ifTrue:[^ nil]. |
2330 | 1835 |
|
1836 |
multipleSelectOk ifFalse:[ |
|
1837 |
^ selection |
|
1838 |
]. |
|
1839 |
size := selection size. |
|
2365
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1840 |
size == 0 ifTrue:[ ^ nil ]. |
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1841 |
size == 1 ifTrue:[ ^ selection at:1 ]. |
2330 | 1842 |
|
2365
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1843 |
max := 1. |
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1844 |
selection do:[:aNumber| max := max max:aNumber ]. |
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1845 |
^ max |
2330 | 1846 |
! |
1847 |
||
1848 |
makeSelectionVisible |
|
1849 |
"scroll to make the selection line visible |
|
1850 |
" |
|
2368 | 1851 |
self makeLineVisible:(self firstInSelection). |
2365
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1852 |
! |
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1853 |
|
1390 | 1854 |
numberOfSelections |
1855 |
"return the number of selected items |
|
1856 |
" |
|
2330 | 1857 |
selection isNil ifTrue:[ ^ 0 ]. |
1858 |
multipleSelectOk ifFalse:[ ^ 1 ]. |
|
1859 |
^ selection size |
|
1390 | 1860 |
! |
1861 |
||
2401 | 1862 |
removeFromSelection:lineNr |
1863 |
||
1864 |
(self isInSelection:lineNr) ifFalse:[ |
|
1865 |
^ self |
|
1866 |
]. |
|
1867 |
self closeEditor. |
|
1868 |
||
1869 |
(multipleSelectOk and:[self numberOfSelections ~~ 1]) ifTrue:[ |
|
1870 |
selection := selection copyWithout:lineNr. |
|
1871 |
self invalidateSelectionAt:lineNr. |
|
1872 |
self selectionChanged. |
|
1873 |
] ifFalse:[ |
|
1874 |
self deselect |
|
1875 |
]. |
|
1876 |
! |
|
1877 |
||
1390 | 1878 |
selectElement:anElement |
1879 |
"select the element. Scroll to make the new selection visible. |
|
1880 |
Model and/or actionBlock notification IS done. |
|
1881 |
" |
|
2178 | 1882 |
self selectElement:anElement ifAbsent:[self deselect] |
1883 |
! |
|
1884 |
||
1885 |
selectElement:anElement ifAbsent:exceptionalValue |
|
1886 |
|idx| |
|
1887 |
||
1888 |
idx := list identityIndexOf:anElement. |
|
1889 |
idx == 0 ifTrue:[ |
|
1890 |
^ exceptionalValue value |
|
1891 |
]. |
|
1892 |
self selection:idx |
|
1390 | 1893 |
! |
1894 |
||
2399 | 1895 |
selectFrom:aStart to:aStop |
1896 |
"select lines between start and stop |
|
1897 |
" |
|
1898 |
|start stop step nsel| |
|
1899 |
||
1900 |
multipleSelectOk ifFalse:[^ self]. |
|
1901 |
||
1902 |
start := aStart. |
|
1903 |
stop := aStop. |
|
1904 |
||
1905 |
aStart < aStop ifTrue:[ |
|
1906 |
start := aStart max:1. |
|
1907 |
stop := aStop min:(list size). |
|
1908 |
step := 1. |
|
1909 |
start > stop ifTrue:[^ self]. |
|
1910 |
||
1911 |
] ifFalse:[ |
|
1912 |
start := aStart min:(list size). |
|
1913 |
stop := aStop max:1. |
|
1914 |
step := -1. |
|
1915 |
start < stop ifTrue:[^ self]. |
|
1916 |
]. |
|
1917 |
nsel := OrderedCollection new. |
|
1918 |
||
1919 |
start to:stop by:step do:[:i| |
|
1920 |
(self canSelectIndex:i forAdd:true) ifTrue:[ |
|
1921 |
nsel add:i. |
|
1922 |
]. |
|
1923 |
]. |
|
1924 |
||
1925 |
(self selectWithoutScroll:nsel redraw:true) ifTrue:[ |
|
1926 |
self selectionChanged |
|
1927 |
]. |
|
1928 |
! |
|
1929 |
||
1390 | 1930 |
selectedElement |
1931 |
"return the single selected item or nil |
|
1932 |
" |
|
1545 | 1933 |
|index| |
1390 | 1934 |
|
1545 | 1935 |
(index := self selectedIndex) ~~ 0 ifTrue:[ |
1936 |
^ list at:index ifAbsent:nil |
|
1937 |
]. |
|
1938 |
^ nil |
|
1390 | 1939 |
! |
1940 |
||
1941 |
selectedIndex |
|
1942 |
"returns the index of the selected line or 0. If more |
|
1943 |
lines are selected, 0 is returned |
|
1944 |
" |
|
2365
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1945 |
selection notNil ifTrue:[ |
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1946 |
multipleSelectOk ifFalse:[ ^ selection ]. |
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1947 |
|
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1948 |
selection size == 1 ifTrue:[ |
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1949 |
^ selection at:1 |
bdf6954a0358
key handling: EndOfText EndOfLine BeginOfText BeginOfLine
ca
parents:
2361
diff
changeset
|
1950 |
] |
1545 | 1951 |
]. |
1952 |
^ 0 |
|
1390 | 1953 |
! |
1954 |
||
1955 |
selection |
|
1956 |
"return the selection index or collection of indices |
|
1957 |
in case of multiple selection enabled |
|
1958 |
" |
|
1959 |
^ selection |
|
1960 |
||
1961 |
! |
|
1962 |
||
1545 | 1963 |
selection:something |
1964 |
"select something or deselect if the argument is nil; |
|
1390 | 1965 |
scroll to make the selected line visible. |
1966 |
The model and/or actionBlock IS notified. |
|
1967 |
" |
|
1545 | 1968 |
(self selectWithoutScroll:something redraw:true) ifTrue:[ |
1969 |
self makeSelectionVisible. |
|
1390 | 1970 |
self selectionChanged |
1545 | 1971 |
]. |
1390 | 1972 |
|
1973 |
! |
|
1974 |
||
2330 | 1975 |
selectionAsCollection |
1976 |
"return the selection as a collection of line numbers. |
|
1977 |
This allows users of this class to enumerate independent of |
|
1978 |
the multipleSelect style. |
|
1979 |
" |
|
1980 |
selection isNil ifTrue:[ ^ #() ]. |
|
1981 |
multipleSelectOk ifTrue:[ ^ selection ]. |
|
1982 |
||
1983 |
^ OrderedCollection with:selection |
|
1984 |
! |
|
1985 |
||
1390 | 1986 |
selectionDo:aBlock |
1987 |
"perform aBlock for each nr in the selection. |
|
1988 |
For single selection, it is called once for the items nr. |
|
1989 |
For multiple selections, it is called for each. |
|
1990 |
" |
|
1991 |
selection notNil ifTrue:[ |
|
1992 |
multipleSelectOk ifTrue:[ |
|
1993 |
selection do:aBlock |
|
1994 |
] ifFalse:[ |
|
1995 |
aBlock value:selection |
|
1996 |
]. |
|
1997 |
]. |
|
1998 |
||
1999 |
||
2000 |
! |
|
2001 |
||
2330 | 2002 |
selectionValue |
2003 |
"return the selection value i.e. the text in the selected line. |
|
2004 |
For multiple selections a collection containing the entries is returned. |
|
2005 |
" |
|
2006 |
multipleSelectOk ifTrue:[ |
|
2007 |
selection isNil ifTrue:[^ #()]. |
|
2008 |
^ selection collect:[:nr| list at:nr ] |
|
2009 |
]. |
|
2010 |
selection isNil ifTrue:[^ nil]. |
|
2011 |
^ list at:selection ifAbsent:nil. |
|
2012 |
! |
|
2013 |
||
2346 | 2014 |
selectionValueAsCollection |
2015 |
"return the selection values as a collection - allows selectionValues to |
|
2016 |
be enumerated independent of the multiSelect settings |
|
2017 |
" |
|
2018 |
|value| |
|
2019 |
||
2020 |
value := self selectionValue. |
|
2021 |
multipleSelectOk ifTrue:[^ value]. |
|
2022 |
||
2023 |
value notNil ifTrue:[^ Array with:value ]. |
|
2024 |
^ #() |
|
2025 |
! |
|
2026 |
||
1542
8607d072c319
accessing selection through to selector
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
2027 |
setSelection:something |
1545 | 2028 |
"select something or deselect if the argument is nil; |
1390 | 2029 |
scroll to make the selected line visible. |
2030 |
*** No model and/or actionBlock notification is done here. |
|
2031 |
" |
|
1545 | 2032 |
(self selectWithoutScroll:something redraw:true) ifTrue:[ |
1390 | 2033 |
self makeSelectionVisible |
2034 |
] |
|
2035 |
||
2036 |
! ! |
|
2037 |
||
2038 |
!SelectionInListModelView methodsFor:'selection private'! |
|
2039 |
||
1641 | 2040 |
canSelectIndex:anIndex |
2041 |
"return true, if the object identified by its index is selectable |
|
2042 |
" |
|
1920 | 2043 |
^ self canSelectIndex:anIndex forAdd:false |
2044 |
! |
|
2045 |
||
2046 |
canSelectIndex:anIndex forAdd:isForAdd |
|
2047 |
"return true, if the object identified by its index is selectable |
|
2048 |
" |
|
2049 |
|item isOk| |
|
1649 | 2050 |
|
2051 |
selectConditionBlock notNil ifTrue:[ |
|
1920 | 2052 |
selectConditionBlock numArgs == 2 ifTrue:[ |
2053 |
isOk := selectConditionBlock value:anIndex value:isForAdd. |
|
2054 |
] ifFalse:[ |
|
2055 |
isOk := selectConditionBlock value:anIndex. |
|
2056 |
]. |
|
2057 |
isOk ifFalse:[ |
|
1649 | 2058 |
^ false |
2059 |
] |
|
1641 | 2060 |
]. |
2061 |
||
1752 | 2062 |
item := list at:anIndex ifAbsent:nil. |
2063 |
item isNil ifTrue:[^ false]. |
|
2064 |
item isHierarchicalItem ifTrue:[ |
|
1649 | 2065 |
^ item isSelectable |
2066 |
]. |
|
2067 |
^ true |
|
1641 | 2068 |
! |
2069 |
||
1547 | 2070 |
deselectWithoutRedraw |
2071 |
"clear the selection without redraw and scrolling; |
|
2072 |
the model and/or actionBlock is notified |
|
2073 |
" |
|
2074 |
(self selectWithoutScroll:nil redraw:false) ifTrue:[ |
|
2075 |
self selectionChanged |
|
2076 |
] |
|
2077 |
! |
|
2078 |
||
1545 | 2079 |
selectWithoutScroll:something redraw:doRedraw |
2080 |
"change selection to something; returns true if selection changed |
|
1390 | 2081 |
" |
2082 |
|oldSelect| |
|
2083 |
||
1554 | 2084 |
selection = something ifTrue:[^ false]. |
2085 |
||
1390 | 2086 |
oldSelect := selection. |
2087 |
||
1545 | 2088 |
(something isNil or:[something == 0]) ifTrue:[ |
2089 |
selection := nil |
|
2090 |
] ifFalse:[ |
|
2091 |
something isNumber ifTrue:[ |
|
1564 | 2092 |
selection := multipleSelectOk ifTrue:[Array with:something] |
2093 |
ifFalse:[something] |
|
1545 | 2094 |
] ifFalse:[ |
2095 |
something size == 0 ifTrue:[ |
|
2096 |
selection := nil |
|
2097 |
] ifFalse:[ |
|
2098 |
selection := multipleSelectOk ifTrue:[something] |
|
2099 |
ifFalse:[something at:1] |
|
2100 |
] |
|
2101 |
] |
|
2102 |
]. |
|
2103 |
selection = oldSelect ifTrue:[^ false]. |
|
1755 | 2104 |
self closeEditor. |
2377 | 2105 |
self cursorEntersItem:nil. |
1545 | 2106 |
|
2107 |
(doRedraw and:[shown]) ifFalse:[ |
|
2108 |
^ true |
|
1390 | 2109 |
]. |
2110 |
||
2111 |
multipleSelectOk ifFalse:[ |
|
2245
546c6e5d0951
change #redrawSelectionAt: to #invalidateSelectionAt: (because is a invalidate)
ca
parents:
2228
diff
changeset
|
2112 |
oldSelect notNil ifTrue:[self invalidateSelectionAt:oldSelect]. |
546c6e5d0951
change #redrawSelectionAt: to #invalidateSelectionAt: (because is a invalidate)
ca
parents:
2228
diff
changeset
|
2113 |
selection notNil ifTrue:[self invalidateSelectionAt:selection]. |
1390 | 2114 |
] ifTrue:[ |
1545 | 2115 |
(selection notNil and:[oldSelect notNil]) ifTrue:[ |
2245
546c6e5d0951
change #redrawSelectionAt: to #invalidateSelectionAt: (because is a invalidate)
ca
parents:
2228
diff
changeset
|
2116 |
selection do:[:i|(oldSelect includesIdentical:i) ifFalse:[self invalidateSelectionAt:i]]. |
546c6e5d0951
change #redrawSelectionAt: to #invalidateSelectionAt: (because is a invalidate)
ca
parents:
2228
diff
changeset
|
2117 |
oldSelect do:[:i|(selection includesIdentical:i) ifFalse:[self invalidateSelectionAt:i]]. |
1390 | 2118 |
] ifFalse:[ |
1545 | 2119 |
oldSelect isNil ifTrue:[oldSelect := selection]. |
2245
546c6e5d0951
change #redrawSelectionAt: to #invalidateSelectionAt: (because is a invalidate)
ca
parents:
2228
diff
changeset
|
2120 |
oldSelect do:[:i|self invalidateSelectionAt:i] |
1390 | 2121 |
] |
2122 |
]. |
|
1545 | 2123 |
^ true |
1561 | 2124 |
! |
2125 |
||
2126 |
toggleSelection:aNumber |
|
2127 |
"add a number to the selection. No scrolling is done. |
|
2128 |
*** No model and/or actionBlock notification is done here. |
|
2129 |
" |
|
2245
546c6e5d0951
change #redrawSelectionAt: to #invalidateSelectionAt: (because is a invalidate)
ca
parents:
2228
diff
changeset
|
2130 |
|oldSelect doRemove| |
1561 | 2131 |
|
2132 |
multipleSelectOk ifFalse:[ |
|
2133 |
aNumber == selection ifTrue:[ "/ remove from selection |
|
2134 |
selection := nil. |
|
2135 |
] ifFalse:[ "/ add to selection |
|
2136 |
oldSelect := selection. |
|
2137 |
selection := aNumber. |
|
2138 |
||
2139 |
oldSelect notNil ifTrue:[ |
|
2245
546c6e5d0951
change #redrawSelectionAt: to #invalidateSelectionAt: (because is a invalidate)
ca
parents:
2228
diff
changeset
|
2140 |
self invalidateSelectionAt:oldSelect |
1561 | 2141 |
] |
2142 |
]. |
|
2245
546c6e5d0951
change #redrawSelectionAt: to #invalidateSelectionAt: (because is a invalidate)
ca
parents:
2228
diff
changeset
|
2143 |
self invalidateSelectionAt:aNumber. |
1561 | 2144 |
^ self |
2145 |
]. |
|
2146 |
||
2147 |
selection isNil ifTrue:[ "/ add to empty selection |
|
2148 |
selection := OrderedCollection with:aNumber. |
|
2245
546c6e5d0951
change #redrawSelectionAt: to #invalidateSelectionAt: (because is a invalidate)
ca
parents:
2228
diff
changeset
|
2149 |
self invalidateSelectionAt:aNumber. |
1561 | 2150 |
^ self |
2151 |
]. |
|
2152 |
||
2153 |
doRemove := selection includesIdentical:aNumber. |
|
2154 |
||
2155 |
(doRemove and:[selection size == 1]) ifTrue:[ "/ remove selection |
|
2156 |
selection := nil. |
|
2245
546c6e5d0951
change #redrawSelectionAt: to #invalidateSelectionAt: (because is a invalidate)
ca
parents:
2228
diff
changeset
|
2157 |
self invalidateSelectionAt:aNumber. |
1561 | 2158 |
^ self |
2159 |
]. |
|
2160 |
||
2161 |
selection := selection asOrderedCollection. |
|
2162 |
||
2163 |
doRemove ifTrue:[ |
|
2164 |
selection removeIdentical:aNumber. |
|
2165 |
] ifFalse:[ |
|
2166 |
selection add:aNumber. |
|
2167 |
]. |
|
2245
546c6e5d0951
change #redrawSelectionAt: to #invalidateSelectionAt: (because is a invalidate)
ca
parents:
2228
diff
changeset
|
2168 |
self invalidateSelectionAt:aNumber. |
1390 | 2169 |
! ! |
2170 |
||
2171 |
!SelectionInListModelView class methodsFor:'documentation'! |
|
2172 |
||
2173 |
version |
|
2401 | 2174 |
^ '$Header: /cvs/stx/stx/libwidg2/SelectionInListModelView.st,v 1.72 2002-12-09 09:51:41 ca Exp $' |
1390 | 2175 |
! ! |