author | Claus Gittinger <cg@exept.de> |
Mon, 23 Oct 1995 21:07:01 +0100 | |
changeset 164 | 5ab02ff0d9ae |
parent 155 | d6f3836d2b51 |
child 166 | ad76f0f28698 |
permissions | -rw-r--r-- |
0 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
59 | 3 |
All Rights Reserved |
0 | 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 |
||
125 | 13 |
'From Smalltalk/X, Version:2.10.5 on 8-may-1995 at 11:59:03 am'! |
105 | 14 |
|
0 | 15 |
ListView subclass:#SelectionInListView |
105 | 16 |
instanceVariableNames:'selection actionBlock enabled hilightFgColor hilightBgColor |
128 | 17 |
halfIntensityFgColor doubleClickActionBlock selectConditionBlock |
18 |
listAttributes multipleSelectOk clickLine initialSelectionMsg |
|
19 |
printItems oneItem useIndex hilightLevel hilightFrameColor |
|
20 |
ignoreReselect arrowLevel smallArrow keyActionStyle |
|
21 |
returnKeyActionStyle toggleSelect strikeOut iSearchString items |
|
22 |
doubleClickMsg' |
|
59 | 23 |
classVariableNames:'RightArrowShadowForm RightArrowLightForm RightArrowForm |
128 | 24 |
SmallRightArrowShadowForm SmallRightArrowLightForm |
25 |
DefaultForegroundColor DefaultBackgroundColor |
|
26 |
DefaultHilightForegroundColor DefaultHilightBackgroundColor |
|
27 |
DefaultHilightFrameColor DefaultHilightLevel DefaultFont |
|
28 |
DefaultRightArrowStyle DefaultRightArrowLevel |
|
29 |
DefaultDisabledForegroundColor DefaultShadowColor |
|
30 |
DefaultLightColor' |
|
105 | 31 |
poolDictionaries:'' |
32 |
category:'Views-Text' |
|
0 | 33 |
! |
34 |
||
35 |
SelectionInListView comment:' |
|
5 | 36 |
COPYRIGHT (c) 1989 by Claus Gittinger |
59 | 37 |
All Rights Reserved |
38 | 38 |
|
164 | 39 |
$Header: /cvs/stx/stx/libwidg/Attic/SelListV.st,v 1.41 1995-10-23 20:06:47 cg Exp $ |
7 | 40 |
'! |
0 | 41 |
|
7 | 42 |
!SelectionInListView class methodsFor:'documentation'! |
43 |
||
38 | 44 |
copyright |
45 |
" |
|
46 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
59 | 47 |
All Rights Reserved |
38 | 48 |
|
49 |
This software is furnished under a license and may be used |
|
50 |
only in accordance with the terms of that license and with the |
|
51 |
inclusion of the above copyright notice. This software may not |
|
52 |
be provided or otherwise made available to, or used by, any |
|
53 |
other person. No title to or ownership of the software is |
|
54 |
hereby transferred. |
|
55 |
" |
|
56 |
! |
|
57 |
||
58 |
version |
|
59 |
" |
|
164 | 60 |
$Header: /cvs/stx/stx/libwidg/Attic/SelListV.st,v 1.41 1995-10-23 20:06:47 cg Exp $ |
38 | 61 |
" |
62 |
! |
|
63 |
||
7 | 64 |
documentation |
65 |
" |
|
31 | 66 |
this one is a ListView with a selected line (which is shown highlighted) |
38 | 67 |
If multipleSelectionsOk is true, it is also allowed to shift-click multiple |
68 |
entries. |
|
63 | 69 |
If toggleSelect is true, clicking toggles (i.e. click on a seleted item |
70 |
will deselect). |
|
31 | 71 |
|
38 | 72 |
Whenever the selection changes, an action-block is evaluated, passing the |
73 |
current selection as argument. |
|
74 |
Currently, the selection can be nil, aNumber or a collection of numbers; |
|
75 |
this will change to be either nil or a collection, making selection handling |
|
70 | 76 |
easier in the future. (this stupid behavior is due to the multiple |
77 |
select feature being added later - the first implementation used to support |
|
78 |
only single selections). |
|
79 |
||
59 | 80 |
The actionBlock is called with the current selection (single number or |
81 |
collection of numbers) as argument. |
|
82 |
||
83 |
Also, to support ST-80 MVC-style use, the model (if nonNil) is notified |
|
155 | 84 |
by the change mechanism (performs changeMsg) and vice versa, the view |
85 |
updates if the model changes (with aspect of either #list or #selectionIndex). |
|
59 | 86 |
|
60 | 87 |
Before actually adding entries to the the selection, a checkBlock (if non-nil) is evaluated |
88 |
passing the number of the entry whch is about to be selected as argument. |
|
89 |
The select change operation is only done if this returns true. This allows |
|
59 | 90 |
interception of select, for example to query the user if he/she wants to save |
60 | 91 |
the old contents before (see uses in SystemBrowser and FileBrowser), or to |
92 |
disable individual entries. |
|
31 | 93 |
|
38 | 94 |
It is also possible to select entries with the keyboard; use the cursor up/ |
95 |
down keys to select prev/next, Home- and End-keys to select first/last. |
|
96 |
Use the return key to apply the double-click-action to the current selection. |
|
97 |
Also, alphabetic keys will select the next entry starting with that key. |
|
98 |
||
99 |
The keyboard behavior can be further controlled with the keyActionStyle |
|
100 |
instance variable (see SelectionInListView>>keyActionStyle:). |
|
101 |
||
59 | 102 |
Finally, ignoreReselect controls if pressing on an already selected item |
103 |
triggers the action or not. For some applications it is useful to allow |
|
104 |
reselects (for example, the SystemBrowsers method-list updates the |
|
105 |
source code in this case). |
|
38 | 106 |
|
60 | 107 |
Currently, some limited form of line attributes are supported. These |
108 |
are kept in the instance variable lineAttributes. |
|
109 |
This may change (using mechanisms similar to MultiColListEntry), so |
|
63 | 110 |
be prepared. (dont use the listAttributes instvar directly; if possible, |
111 |
use MultiColListEntry or subclasses of it. |
|
120 | 112 |
|
63 | 113 |
Although currently based on the listAttributes instVar, the implementation of |
120 | 114 |
text attributes will be changed in the near future (when Text/DisplayText are |
115 |
available). |
|
116 |
However, the protocol will probably be kept for backward compatibility |
|
117 |
(i.e. use #attributeAt: / #attributeAt:put etc. - at least, these are easy to find |
|
118 |
when migrating to the new attributed text handling). |
|
60 | 119 |
|
31 | 120 |
InstanceVariables: |
59 | 121 |
selection <misc> the current selection. nil, a number or collection of numbers |
31 | 122 |
|
59 | 123 |
actionBlock <Block> block to be evaluated on selection changes |
31 | 124 |
|
59 | 125 |
enabled <Boolean> true: selection changes allowed; false: ignore clicks |
31 | 126 |
|
59 | 127 |
hilightFgColor |
128 |
hilightBgColor <Color> how highlighted items are drawn |
|
31 | 129 |
|
59 | 130 |
halfIntensityColor <Color> foreground for disabled items |
31 | 131 |
|
59 | 132 |
selectConditionBlock <Block> if non-nil, this nlock can decide if selection is ok |
0 | 133 |
|
59 | 134 |
doubleClickActionBlock <Block> action to perform on double-click |
31 | 135 |
|
59 | 136 |
listAttributes dont use - will vanish |
31 | 137 |
|
59 | 138 |
hilightLevel <Integer> level to draw selections (i.e. for 3D effect) |
139 |
hilightFrameColor <Color> rectangle around highlighted items |
|
31 | 140 |
|
63 | 141 |
multipleSelectOk <Boolean> if true, multiple selections (with shift) are ok. |
142 |
default: false |
|
143 |
||
59 | 144 |
ignoreReselect <Boolean> if true, selecting same again does not trigger action; |
63 | 145 |
if false, every select triggers it. |
146 |
default: true |
|
147 |
||
148 |
toggleSelect <Boolean> if true, click toggles; |
|
149 |
if false, click selects. |
|
150 |
default: false |
|
0 | 151 |
|
59 | 152 |
arrowLevel <Integer> level to draw right-arrows (for submenus etc.) |
153 |
smallArrow <Boolean> if true, uses a small arrow bitmap |
|
31 | 154 |
|
119 | 155 |
listMsg if non-nil, use ST-80 style (model-access) |
156 |
initialSelectionMsg |
|
59 | 157 |
printItems |
158 |
oneItem |
|
31 | 159 |
|
59 | 160 |
keyActionStyle <Symbol> controls how to respond to keyboard selects |
31 | 161 |
|
125 | 162 |
returnKeyActionStyle <Symbol> controls how to respond to return key |
163 |
||
31 | 164 |
written spring/summer 89 by claus |
165 |
3D Jan 90 by claus |
|
38 | 166 |
multiselect Jun 92 by claus |
167 |
keyboard-select jun 94 by claus |
|
7 | 168 |
" |
119 | 169 |
! |
170 |
||
171 |
examples |
|
172 |
" |
|
173 |
SelectionInListView can be used both in the ST/X way, using action blocks |
|
174 |
or in the traditional mvc way. |
|
175 |
with actions: |
|
176 |
||
125 | 177 |
basic interface: |
178 |
||
128 | 179 |
|top slv| |
180 |
||
181 |
top := StandardSystemView new |
|
182 |
label:'select'; |
|
183 |
minExtent:100@100; |
|
184 |
maxExtent:300@400; |
|
185 |
extent:200@200. |
|
186 |
||
187 |
slv := SelectionInListView new. |
|
188 |
slv list:#('one' 'two' 'three'). |
|
189 |
slv action:[:index | Transcript showCr:'selected ' , index printString]. |
|
190 |
||
191 |
top add:slv in:(0.0@0.0 corner:1.0@1.0). |
|
192 |
top open |
|
125 | 193 |
|
194 |
||
195 |
get element instead of index: |
|
196 |
||
128 | 197 |
|top slv| |
198 |
||
199 |
top := StandardSystemView new |
|
200 |
label:'select'; |
|
201 |
minExtent:100@100; |
|
202 |
maxExtent:300@400; |
|
203 |
extent:200@200. |
|
204 |
||
205 |
slv := SelectionInListView new. |
|
206 |
slv list:#('one' 'two' 'three'). |
|
207 |
slv action:[:element | Transcript showCr:'selected ' , element printString]. |
|
208 |
slv useIndex:false. |
|
209 |
||
210 |
top add:slv in:(0.0@0.0 corner:1.0@1.0). |
|
211 |
top open |
|
125 | 212 |
|
213 |
||
214 |
concrete example; show filenames: |
|
215 |
(notice: normally, you would use a FileSelectionList) |
|
216 |
||
128 | 217 |
|top slv| |
218 |
||
219 |
top := StandardSystemView new |
|
220 |
label:'select'; |
|
221 |
minExtent:100@100; |
|
222 |
maxExtent:300@400; |
|
223 |
extent:200@200. |
|
224 |
||
225 |
slv := SelectionInListView new. |
|
226 |
slv list:(Filename currentDirectory directoryContents). |
|
227 |
slv action:[:index | |
|
228 |
Transcript showCr:'selected ' , index printString. |
|
229 |
Transcript showCr:' the value is: ', slv selectionValue]. |
|
230 |
||
231 |
top add:slv in:(0.0@0.0 corner:1.0@1.0). |
|
232 |
top open |
|
125 | 233 |
|
119 | 234 |
|
124
7abd3a234296
last version before changing to collection in multipleSelect mode
claus
parents:
120
diff
changeset
|
235 |
add a scrollbar: |
119 | 236 |
|
128 | 237 |
|top slv| |
238 |
||
239 |
top := StandardSystemView new |
|
240 |
label:'select'; |
|
241 |
minExtent:100@100; |
|
242 |
maxExtent:300@400; |
|
243 |
extent:200@200. |
|
244 |
||
245 |
slv := SelectionInListView new. |
|
246 |
slv list:(Filename currentDirectory directoryContents). |
|
247 |
slv action:[:index | Transcript showCr:'selected ' , index printString]. |
|
248 |
||
249 |
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0). |
|
250 |
top open |
|
125 | 251 |
|
119 | 252 |
|
124
7abd3a234296
last version before changing to collection in multipleSelect mode
claus
parents:
120
diff
changeset
|
253 |
allow reselect (clicking on already selected entry): |
119 | 254 |
|
128 | 255 |
|top slv| |
256 |
||
257 |
top := StandardSystemView new |
|
258 |
label:'select'; |
|
259 |
minExtent:100@100; |
|
260 |
maxExtent:300@400; |
|
261 |
extent:200@200. |
|
262 |
||
263 |
slv := SelectionInListView new. |
|
264 |
slv list:(Filename currentDirectory directoryContents). |
|
265 |
slv action:[:index | Transcript showCr:'selected ' , index printString]. |
|
266 |
slv ignoreReselect:false. |
|
267 |
||
268 |
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0). |
|
269 |
top open |
|
125 | 270 |
|
119 | 271 |
|
124
7abd3a234296
last version before changing to collection in multipleSelect mode
claus
parents:
120
diff
changeset
|
272 |
allow multiple selections: |
119 | 273 |
|
128 | 274 |
|top slv| |
275 |
||
276 |
top := StandardSystemView new |
|
277 |
label:'select'; |
|
278 |
minExtent:100@100; |
|
279 |
maxExtent:300@400; |
|
280 |
extent:200@200. |
|
281 |
||
282 |
slv := SelectionInListView new. |
|
283 |
slv list:(Filename currentDirectory directoryContents). |
|
284 |
slv action:[:indexList | Transcript showCr:'selected ' , indexList printString]. |
|
285 |
slv multipleSelectOk:true. |
|
286 |
||
287 |
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0). |
|
288 |
top open |
|
125 | 289 |
|
290 |
||
291 |
same, not using index: |
|
292 |
||
128 | 293 |
|top slv| |
294 |
||
295 |
top := StandardSystemView new |
|
296 |
label:'select'; |
|
297 |
minExtent:100@100; |
|
298 |
maxExtent:300@400; |
|
299 |
extent:200@200. |
|
300 |
||
301 |
slv := SelectionInListView new. |
|
302 |
slv list:(Filename currentDirectory directoryContents). |
|
303 |
slv action:[:indexList | Transcript showCr:'selected ' , indexList printString]. |
|
304 |
slv multipleSelectOk:true; useIndex:false. |
|
305 |
||
306 |
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0). |
|
307 |
top open |
|
125 | 308 |
|
119 | 309 |
|
124
7abd3a234296
last version before changing to collection in multipleSelect mode
claus
parents:
120
diff
changeset
|
310 |
strikeout mode (single): |
119 | 311 |
|
128 | 312 |
|top slv| |
313 |
||
314 |
top := StandardSystemView new |
|
315 |
label:'select'; |
|
316 |
minExtent:100@100; |
|
317 |
maxExtent:300@400; |
|
318 |
extent:200@200. |
|
319 |
||
320 |
slv := SelectionInListView new. |
|
321 |
slv list:(Filename currentDirectory directoryContents). |
|
322 |
slv action:[:index | Transcript showCr:'selected ' , index printString]. |
|
323 |
slv strikeOut:true. |
|
324 |
||
325 |
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0). |
|
326 |
top open |
|
125 | 327 |
|
119 | 328 |
|
124
7abd3a234296
last version before changing to collection in multipleSelect mode
claus
parents:
120
diff
changeset
|
329 |
strikeout mode (multiple): |
119 | 330 |
|
128 | 331 |
|top slv| |
332 |
||
333 |
top := StandardSystemView new |
|
334 |
label:'select'; |
|
335 |
minExtent:100@100; |
|
336 |
maxExtent:300@400; |
|
337 |
extent:200@200. |
|
338 |
||
339 |
slv := SelectionInListView new. |
|
340 |
slv list:(Filename currentDirectory directoryContents). |
|
341 |
slv action:[:index | Transcript showCr:'selected ' , index printString]. |
|
342 |
slv strikeOut:true; multipleSelectOk:true. |
|
343 |
||
344 |
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0). |
|
345 |
top open |
|
125 | 346 |
|
119 | 347 |
|
124
7abd3a234296
last version before changing to collection in multipleSelect mode
claus
parents:
120
diff
changeset
|
348 |
define what to do on double-click: |
119 | 349 |
|
128 | 350 |
|top slv| |
351 |
||
352 |
top := StandardSystemView new |
|
353 |
label:'select'; |
|
354 |
minExtent:100@100; |
|
355 |
maxExtent:300@400; |
|
356 |
extent:200@200. |
|
357 |
||
358 |
slv := SelectionInListView new. |
|
359 |
slv list:(Filename currentDirectory directoryContents). |
|
360 |
slv action:[:index | Transcript showCr:'selected ' , index printString]. |
|
361 |
slv doubleClickAction:[:index | Transcript showCr:'doubleclick on ' , index printString]. |
|
362 |
||
363 |
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0). |
|
364 |
top open |
|
119 | 365 |
|
124
7abd3a234296
last version before changing to collection in multipleSelect mode
claus
parents:
120
diff
changeset
|
366 |
|
119 | 367 |
using a Model: |
368 |
||
128 | 369 |
|top slv model| |
370 |
||
371 |
model := Plug new. |
|
372 |
model respondTo:#getList with:[#('foo' 'bar' 'baz' 'hello')]. |
|
373 |
model respondTo:#initial with:[1]. |
|
374 |
model respondTo:#setSelection: with:[:arg | Transcript showCr:'model selected:', arg printString]. |
|
375 |
||
376 |
top := StandardSystemView new |
|
377 |
label:'select'; |
|
378 |
minExtent:100@100; |
|
379 |
maxExtent:300@400; |
|
380 |
extent:200@200. |
|
381 |
||
382 |
slv := SelectionInListView |
|
383 |
on:model |
|
384 |
aspect:#someAspect |
|
385 |
change:#setSelection: |
|
386 |
list:#getList |
|
387 |
initialSelection:#initial. |
|
388 |
||
389 |
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0). |
|
390 |
top open |
|
119 | 391 |
|
392 |
notice, that the ST-80 behavaior on reselect is to send a selection change |
|
393 |
with an index of 0. |
|
394 |
||
395 |
||
125 | 396 |
same, with useIndex false: |
397 |
||
128 | 398 |
|top slv model| |
399 |
||
400 |
model := Plug new. |
|
401 |
model respondTo:#getList with:[#('foo' 'bar' 'baz' 'hello')]. |
|
402 |
model respondTo:#initial with:['bar']. |
|
403 |
model respondTo:#setSelection: with:[:arg | Transcript showCr:'model selected:', arg printString]. |
|
404 |
||
405 |
top := StandardSystemView new |
|
406 |
label:'select'; |
|
407 |
minExtent:100@100; |
|
408 |
maxExtent:300@400; |
|
409 |
extent:200@200. |
|
410 |
||
411 |
slv := SelectionInListView |
|
412 |
on:model |
|
413 |
aspect:#someAspect |
|
414 |
change:#setSelection: |
|
415 |
list:#getList |
|
416 |
initialSelection:#initial. |
|
417 |
slv useIndex:false. |
|
418 |
||
419 |
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0). |
|
420 |
top open |
|
125 | 421 |
|
422 |
||
155 | 423 |
self changing list: |
424 |
(selectionInListView updates itself when button changes initial selection): |
|
425 |
||
426 |
|top slv model sel changeButton| |
|
427 |
||
428 |
sel := 'bar'. |
|
429 |
model := Plug new. |
|
430 |
model respondTo:#getList with:['getList' printNL. #('foo' 'bar' 'baz' 'hello')]. |
|
431 |
model respondTo:#initial with:['initial' printNL. sel]. |
|
432 |
model respondTo:#setSelection: with:[:arg | ('model selected:', arg) printNL. sel := arg]. |
|
433 |
||
434 |
changeButton := Button label:'change selection'. |
|
435 |
changeButton action:[sel := 'foo'. model changed:#initial]. |
|
436 |
changeButton open. |
|
437 |
||
438 |
top := StandardSystemView new |
|
439 |
label:'select'; |
|
440 |
minExtent:100@100; |
|
441 |
maxExtent:300@400; |
|
442 |
extent:200@200. |
|
443 |
||
444 |
slv := SelectionInListView |
|
445 |
on:model |
|
446 |
aspect:#someAspect |
|
447 |
change:#setSelection: |
|
448 |
list:#getList |
|
449 |
initialSelection:#initial. |
|
450 |
slv useIndex:false. |
|
451 |
||
452 |
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0). |
|
453 |
top open |
|
454 |
||
455 |
||
119 | 456 |
using a SelectionInList-Model: |
457 |
(see how changes in the model (via list:...) are reflected in the view) |
|
458 |
||
128 | 459 |
|top slv model| |
460 |
||
461 |
model := SelectionInList with:#('foo' 'bar' 'baz' 'hello'). |
|
462 |
model selection:'bar'. |
|
463 |
||
464 |
top := StandardSystemView new |
|
465 |
label:'select'; |
|
466 |
minExtent:100@100; |
|
467 |
maxExtent:300@400; |
|
468 |
extent:200@200. |
|
469 |
||
470 |
slv := SelectionInListView on:model. |
|
471 |
||
472 |
top add:(ScrollableView forView:slv) in:(0.0@0.0 corner:1.0@1.0). |
|
473 |
top open. |
|
474 |
||
475 |
model inspect |
|
125 | 476 |
|
477 |
||
478 |
two selectionInListViews on the same selectionInList model: |
|
479 |
||
128 | 480 |
|top1 slv1 top2 slv2 model| |
481 |
||
482 |
model := SelectionInList with:#('foo' 'bar' 'baz' 'hello'). |
|
483 |
||
484 |
top1 := StandardSystemView new |
|
485 |
label:'select'; |
|
486 |
minExtent:100@100; |
|
487 |
maxExtent:300@400; |
|
488 |
extent:200@200. |
|
489 |
||
490 |
slv1 := SelectionInListView on:model. |
|
491 |
||
492 |
top1 add:(ScrollableView forView:slv1) in:(0.0@0.0 corner:1.0@1.0). |
|
493 |
top1 open. |
|
494 |
||
495 |
top2 := StandardSystemView new |
|
496 |
label:'select'; |
|
497 |
minExtent:100@100; |
|
498 |
maxExtent:300@400; |
|
499 |
extent:200@200. |
|
500 |
||
501 |
slv2 := SelectionInListView on:model. |
|
502 |
||
503 |
top2 add:(ScrollableView forView:slv2) in:(0.0@0.0 corner:1.0@1.0). |
|
504 |
top2 open. |
|
119 | 505 |
" |
7 | 506 |
! ! |
0 | 507 |
|
105 | 508 |
!SelectionInListView class methodsFor:'instance creation'! |
509 |
||
510 |
on:aModel printItems:print oneItem:one aspect:aspect change:change |
|
511 |
list:list menu:menu initialSelection:initial useIndex:useIndex |
|
512 |
||
513 |
"for ST-80 compatibility" |
|
514 |
||
515 |
^ (self new) on:aModel |
|
516 |
printItems:print |
|
517 |
oneItem:one |
|
518 |
aspect:aspect |
|
519 |
change:change |
|
520 |
list:list |
|
521 |
menu:menu |
|
522 |
initialSelection:initial |
|
523 |
useIndex:useIndex |
|
524 |
! |
|
525 |
||
125 | 526 |
on:aModel aspect:aspect change:change list:list initialSelection:initial |
527 |
^ self on:aModel |
|
528 |
printItems:true |
|
529 |
oneItem:false |
|
530 |
aspect:aspect |
|
531 |
change:change |
|
532 |
list:list |
|
533 |
menu:nil |
|
534 |
initialSelection:initial |
|
535 |
useIndex:true |
|
536 |
! |
|
537 |
||
105 | 538 |
on:aModel printItems:print oneItem:one aspect:aspect |
539 |
change:change list:list menu:menu initialSelection:initial |
|
540 |
||
541 |
"for ST-80 compatibility" |
|
542 |
||
119 | 543 |
^ self on:aModel |
105 | 544 |
printItems:print |
545 |
oneItem:one |
|
546 |
aspect:aspect |
|
547 |
change:change |
|
548 |
list:list |
|
549 |
menu:menu |
|
550 |
initialSelection:initial |
|
551 |
useIndex:false |
|
119 | 552 |
! |
553 |
||
554 |
on:aModel aspect:aspect change:change list:list menu:menu initialSelection:initial |
|
555 |
^ self on:aModel |
|
556 |
printItems:true |
|
557 |
oneItem:false |
|
558 |
aspect:aspect |
|
559 |
change:change |
|
560 |
list:list |
|
561 |
menu:menu |
|
562 |
initialSelection:initial |
|
563 |
useIndex:true |
|
105 | 564 |
! ! |
565 |
||
22 | 566 |
!SelectionInListView class methodsFor:'defaults'! |
567 |
||
125 | 568 |
defaultListMessage |
569 |
^ #list |
|
570 |
! |
|
571 |
||
572 |
defaultChangeMessage |
|
573 |
^ #selectionIndex: |
|
574 |
! |
|
575 |
||
576 |
defaultAspectMessage |
|
577 |
^ nil |
|
578 |
! |
|
579 |
||
580 |
defaultSelectionMessage |
|
581 |
^ #selectionIndex |
|
582 |
! |
|
583 |
||
105 | 584 |
rightArrowShadowFormOn:aDevice |
585 |
"return the form used for the right arrow light pixels (3D only)" |
|
586 |
||
587 |
|f| |
|
59 | 588 |
|
105 | 589 |
((aDevice == Display) and:[RightArrowShadowForm notNil]) ifTrue:[ |
590 |
^ RightArrowShadowForm |
|
591 |
]. |
|
592 |
f := Form fromFile:'RightArrowShadow.xbm' resolution:100 on:aDevice. |
|
593 |
f isNil ifTrue:[ |
|
594 |
f := Form width:16 height:16 fromArray:#[2r00000000 2r00000000 |
|
595 |
2r00000000 2r00000000 |
|
596 |
2r00000000 2r00000000 |
|
597 |
2r00000000 2r00000000 |
|
598 |
2r00000000 2r00000000 |
|
599 |
2r00000000 2r00000000 |
|
600 |
2r00000000 2r00000000 |
|
601 |
2r00000000 2r00000000 |
|
602 |
2r00000000 2r00010000 |
|
603 |
2r00000000 2r00100000 |
|
604 |
2r00000000 2r01000000 |
|
605 |
2r00000000 2r10000000 |
|
606 |
2r00000001 2r00000000 |
|
607 |
2r00000010 2r00000000 |
|
608 |
2r00000000 2r00000000 |
|
609 |
2r00000000 2r00000000] |
|
610 |
on:aDevice |
|
611 |
]. |
|
612 |
(aDevice == Display) ifTrue:[ |
|
613 |
RightArrowShadowForm := f |
|
614 |
]. |
|
615 |
^ f |
|
59 | 616 |
! |
617 |
||
22 | 618 |
rightArrowLightFormOn:aDevice |
619 |
"return the form used for the right arrow light pixels (3D only)" |
|
620 |
||
621 |
|f| |
|
622 |
||
623 |
((aDevice == Display) and:[RightArrowLightForm notNil]) ifTrue:[ |
|
59 | 624 |
^ RightArrowLightForm |
22 | 625 |
]. |
626 |
f := Form fromFile:'RightArrowLight.xbm' resolution:100 on:aDevice. |
|
627 |
f isNil ifTrue:[ |
|
59 | 628 |
f := Form width:16 height:16 fromArray:#[2r00000000 2r00000000 |
629 |
2r00000000 2r00000000 |
|
630 |
2r00000000 2r00000000 |
|
631 |
2r00000110 2r00000000 |
|
632 |
2r00000101 2r00000000 |
|
633 |
2r00000100 2r10000000 |
|
634 |
2r00000100 2r01000000 |
|
635 |
2r00000100 2r00100000 |
|
636 |
2r00000100 2r00000000 |
|
637 |
2r00000100 2r00000000 |
|
638 |
2r00000100 2r00000000 |
|
639 |
2r00000100 2r00000000 |
|
640 |
2r00000100 2r00000000 |
|
641 |
2r00000100 2r00000000 |
|
642 |
2r00000000 2r00000000 |
|
643 |
2r00000000 2r00000000] |
|
644 |
on:aDevice |
|
22 | 645 |
]. |
646 |
(aDevice == Display) ifTrue:[ |
|
59 | 647 |
RightArrowLightForm := f |
22 | 648 |
]. |
649 |
^ f |
|
650 |
! |
|
651 |
||
105 | 652 |
updateStyleCache |
653 |
DefaultDisabledForegroundColor := StyleSheet colorAt:'selectionDisabledForegroundColor'. |
|
654 |
DefaultHilightForegroundColor := StyleSheet colorAt:'selectionHilightForegroundColor'. |
|
655 |
DefaultHilightBackgroundColor := StyleSheet colorAt:'selectionHilightBackgroundColor'. |
|
656 |
DefaultHilightFrameColor := StyleSheet colorAt:'selectionHilightFrameColor'. |
|
657 |
DefaultHilightLevel := StyleSheet at:'selectionHilightLevel' default:0. |
|
658 |
DefaultRightArrowStyle := StyleSheet at:'selectionRightArrowStyle'. |
|
659 |
DefaultRightArrowLevel := StyleSheet at:'selectionRightArrowLevel'. |
|
660 |
DefaultForegroundColor := StyleSheet colorAt:'selectionForegroundColor'. |
|
661 |
DefaultBackgroundColor := StyleSheet colorAt:'selectionBackgroundColor'. |
|
662 |
DefaultShadowColor := StyleSheet colorAt:'selectionShadowColor'. |
|
663 |
DefaultLightColor := StyleSheet colorAt:'selectionLightColor'. |
|
664 |
DefaultFont := StyleSheet fontAt:'selectionFont'. |
|
146 | 665 |
RightArrowForm := nil. |
22 | 666 |
|
105 | 667 |
" |
668 |
self updateStyleCache |
|
669 |
" |
|
22 | 670 |
! |
671 |
||
672 |
rightArrowFormOn:aDevice |
|
673 |
"return the form used for the right arrow (non 3D)" |
|
674 |
||
146 | 675 |
|f bits| |
22 | 676 |
|
677 |
((aDevice == Display) and:[RightArrowForm notNil]) ifTrue:[ |
|
59 | 678 |
^ RightArrowForm |
22 | 679 |
]. |
680 |
f := Form fromFile:'RightArrow.xbm' resolution:100 on:aDevice. |
|
681 |
f isNil ifTrue:[ |
|
146 | 682 |
DefaultRightArrowStyle == #solid ifTrue:[ |
683 |
bits := #[2r00000000 2r00000000 |
|
684 |
2r00000000 2r00000000 |
|
685 |
2r00000000 2r00000000 |
|
686 |
2r00000010 2r00000000 |
|
687 |
2r00000011 2r00000000 |
|
688 |
2r00000011 2r10000000 |
|
689 |
2r00000011 2r11000000 |
|
690 |
2r00000011 2r11100000 |
|
691 |
2r00000011 2r11110000 |
|
692 |
2r00000011 2r11100000 |
|
693 |
2r00000011 2r11000000 |
|
694 |
2r00000011 2r10000000 |
|
695 |
2r00000011 2r00000000 |
|
696 |
2r00000010 2r00000000 |
|
697 |
2r00000000 2r00000000 |
|
698 |
2r00000000 2r00000000] |
|
699 |
] ifFalse:[ |
|
700 |
bits := #[2r00000000 2r00000000 |
|
701 |
2r00000000 2r00000000 |
|
702 |
2r00000000 2r00000000 |
|
703 |
2r00000110 2r00000000 |
|
704 |
2r00000101 2r00000000 |
|
705 |
2r00000100 2r10000000 |
|
706 |
2r00000100 2r01000000 |
|
707 |
2r00000100 2r00100000 |
|
708 |
2r00000100 2r00010000 |
|
709 |
2r00000100 2r00100000 |
|
710 |
2r00000100 2r01000000 |
|
711 |
2r00000100 2r10000000 |
|
712 |
2r00000101 2r00000000 |
|
713 |
2r00000110 2r00000000 |
|
714 |
2r00000000 2r00000000 |
|
715 |
2r00000000 2r00000000] |
|
716 |
]. |
|
717 |
f := Form width:16 height:16 fromArray:bits on:aDevice |
|
22 | 718 |
]. |
719 |
(aDevice == Display) ifTrue:[ |
|
59 | 720 |
RightArrowForm := f |
22 | 721 |
]. |
722 |
^ f |
|
31 | 723 |
! |
724 |
||
725 |
smallRightArrowLightFormOn:aDevice |
|
726 |
"return the form used for the small right arrow light pixels (3D only)" |
|
727 |
||
728 |
|f| |
|
729 |
||
730 |
((aDevice == Display) and:[SmallRightArrowLightForm notNil]) ifTrue:[ |
|
59 | 731 |
^ SmallRightArrowLightForm |
31 | 732 |
]. |
733 |
f := Form fromFile:'SmallRightArrowLight.xbm' resolution:100 on:aDevice. |
|
734 |
f isNil ifTrue:[ |
|
59 | 735 |
f := Form width:9 height:9 fromArray:#[2r00000000 2r00000000 |
736 |
2r01100000 2r00000000 |
|
737 |
2r01011000 2r00000000 |
|
738 |
2r01000110 2r00000000 |
|
739 |
2r01000000 2r00000000 |
|
740 |
2r01000000 2r00000000 |
|
741 |
2r01000000 2r00000000 |
|
742 |
2r01000000 2r00000000 |
|
743 |
2r00000000 2r00000000] |
|
744 |
on:aDevice |
|
31 | 745 |
]. |
746 |
(aDevice == Display) ifTrue:[ |
|
59 | 747 |
SmallRightArrowLightForm := f |
31 | 748 |
]. |
749 |
^ f |
|
750 |
! |
|
751 |
||
752 |
smallRightArrowShadowFormOn:aDevice |
|
753 |
"return the form used for the small right arrow light pixels (3D only)" |
|
754 |
||
755 |
|f| |
|
756 |
||
757 |
((aDevice == Display) and:[SmallRightArrowShadowForm notNil]) ifTrue:[ |
|
59 | 758 |
^ SmallRightArrowShadowForm |
31 | 759 |
]. |
760 |
f := Form fromFile:'SmallRightArrowShadow.xbm' resolution:100 on:aDevice. |
|
761 |
f isNil ifTrue:[ |
|
59 | 762 |
f := Form width:9 height:9 fromArray:#[2r00000000 2r00000000 |
763 |
2r00000000 2r00000000 |
|
764 |
2r00000000 2r00000000 |
|
765 |
2r00000000 2r00000000 |
|
766 |
2r00000001 2r00000000 |
|
767 |
2r00000110 2r00000000 |
|
768 |
2r00011000 2r00000000 |
|
769 |
2r00100000 2r00000000 |
|
770 |
2r00000000 2r00000000] |
|
771 |
on:aDevice |
|
31 | 772 |
]. |
773 |
(aDevice == Display) ifTrue:[ |
|
59 | 774 |
SmallRightArrowShadowForm := f |
31 | 775 |
]. |
776 |
^ f |
|
22 | 777 |
! ! |
778 |
||
125 | 779 |
!SelectionInListView methodsFor:'selections'! |
780 |
||
781 |
isInSelection:aNumber |
|
782 |
"return true, if line, aNumber is in the selection" |
|
783 |
||
784 |
selection isNil ifTrue:[^ false]. |
|
785 |
multipleSelectOk ifTrue:[ |
|
786 |
^ (selection includes:aNumber) |
|
787 |
]. |
|
788 |
^ (aNumber == selection) |
|
789 |
! |
|
790 |
||
791 |
selectWithoutScroll:aNumberOrNilOrCollection |
|
792 |
"select line, aNumber or deselect if argument is nil" |
|
793 |
||
794 |
|prevSelection newSelection| |
|
795 |
||
796 |
newSelection := aNumberOrNilOrCollection. |
|
797 |
newSelection notNil ifTrue:[ |
|
798 |
(self isValidSelection:newSelection) ifFalse:[ |
|
799 |
newSelection := nil |
|
800 |
] |
|
801 |
]. |
|
802 |
||
803 |
(newSelection = selection) ifTrue: [^ self]. |
|
804 |
||
805 |
" |
|
806 |
redraw old selection unhighlighted |
|
807 |
" |
|
808 |
selection notNil ifTrue: [ |
|
809 |
prevSelection := selection. |
|
810 |
selection := nil. |
|
811 |
multipleSelectOk ifTrue:[ |
|
812 |
prevSelection do:[:line | |
|
813 |
self redrawElement:line |
|
814 |
] |
|
815 |
] ifFalse:[ |
|
816 |
self redrawElement:prevSelection |
|
817 |
] |
|
818 |
]. |
|
819 |
||
820 |
selection := newSelection. |
|
821 |
||
822 |
" |
|
823 |
redraw new selection unhighlighted |
|
824 |
" |
|
825 |
newSelection notNil ifTrue:[ |
|
826 |
multipleSelectOk ifTrue:[ |
|
827 |
newSelection isCollection ifFalse:[ |
|
828 |
selection := OrderedCollection with:newSelection. |
|
829 |
]. |
|
830 |
selection do:[:line | |
|
831 |
self redrawElement:line |
|
832 |
] |
|
833 |
] ifFalse:[ |
|
834 |
self redrawElement:selection |
|
835 |
] |
|
836 |
] |
|
837 |
||
838 |
! |
|
839 |
||
840 |
makeSelectionVisible |
|
841 |
"scroll to make the selection line visible" |
|
842 |
||
843 |
|line| |
|
844 |
||
845 |
selection notNil ifTrue:[ |
|
846 |
multipleSelectOk ifTrue:[ |
|
847 |
line := selection first. |
|
848 |
] ifFalse:[ |
|
849 |
line := selection |
|
850 |
]. |
|
851 |
self makeLineVisible:line |
|
852 |
] |
|
853 |
! |
|
854 |
||
855 |
selection:aNumberOrNil |
|
856 |
"select line, aNumber or deselect if argument is nil; |
|
857 |
scroll to make the selected line visible" |
|
858 |
||
859 |
self selectWithoutScroll:aNumberOrNil. |
|
860 |
selection notNil ifTrue:[self makeSelectionVisible] |
|
861 |
! |
|
862 |
||
863 |
selectionValue |
|
864 |
"return the selection value i.e. the text in the selected line. |
|
865 |
For multiple selections a collection containing the entries is returned." |
|
866 |
||
867 |
selection isNil ifTrue:[^ nil]. |
|
868 |
||
869 |
multipleSelectOk ifTrue:[ |
|
870 |
^ selection collect:[:nr | self at:nr] |
|
871 |
]. |
|
872 |
^ self at:selection |
|
873 |
||
874 |
! |
|
875 |
||
876 |
hasSelection |
|
877 |
"return true, if the view has a selection" |
|
878 |
||
879 |
^ selection notNil |
|
880 |
! |
|
881 |
||
882 |
selectElement:anObject |
|
883 |
"select the element with same printString as the argument, anObject. |
|
884 |
Scroll to make the new selection visible." |
|
885 |
||
886 |
|lineNo| |
|
887 |
||
888 |
list notNil ifTrue:[ |
|
889 |
items notNil ifTrue:[ |
|
890 |
lineNo := items indexOf:anObject ifAbsent:nil |
|
891 |
] ifFalse:[ |
|
892 |
lineNo := list indexOf:(anObject printString) ifAbsent:nil. |
|
893 |
]. |
|
894 |
lineNo notNil ifTrue:[self selection:lineNo] |
|
895 |
] |
|
896 |
! |
|
897 |
||
898 |
selection |
|
899 |
"return the selection index or collection of indices (if multipleSelect is on)" |
|
900 |
||
901 |
^ selection |
|
902 |
! |
|
903 |
||
904 |
selectionChangedFrom:oldSelection |
|
905 |
"selection has changed. Call actionblock and/or send changeMessage if defined" |
|
906 |
||
907 |
|arg| |
|
908 |
||
909 |
arg := self argForChangeMessage. |
|
910 |
" |
|
911 |
the ST/X way of doing things - perform actionBlock |
|
912 |
" |
|
913 |
actionBlock notNil ifTrue:[actionBlock value:arg]. |
|
914 |
" |
|
915 |
the ST-80 way of doing things - notify model via changeMsg |
|
916 |
" |
|
917 |
"/ ST80 sends 0 as index, if the same selection is reselected ... |
|
918 |
selection == oldSelection ifTrue:[ |
|
919 |
arg := 0 |
|
920 |
]. |
|
921 |
self sendChangeMessageWith:arg |
|
922 |
! |
|
923 |
||
924 |
deselect |
|
925 |
"deselect" |
|
926 |
||
927 |
self selection:nil |
|
928 |
! |
|
929 |
||
930 |
deselectWithoutRedraw |
|
931 |
"deselect - no redraw" |
|
932 |
||
933 |
selection := nil |
|
934 |
! |
|
935 |
||
936 |
numberOfSelections |
|
937 |
"return the number of selected entries" |
|
938 |
||
939 |
|sz| |
|
940 |
||
941 |
selection isNil ifTrue:[^ 0]. |
|
942 |
sz := selection size. |
|
943 |
sz > 0 ifTrue:[^ sz]. |
|
944 |
^ 1 |
|
945 |
! |
|
946 |
||
947 |
valueIsInSelection:someString |
|
948 |
"return true, if someString is in the selection" |
|
949 |
||
950 |
|sel| |
|
951 |
||
952 |
selection isNil ifTrue:[^ false]. |
|
953 |
sel := self selectionValue. |
|
954 |
self numberOfSelections > 1 ifTrue:[ |
|
955 |
^ (sel includes:someString) |
|
956 |
]. |
|
957 |
^ (someString = sel) |
|
958 |
! |
|
959 |
||
960 |
selectElementWithoutScroll:anObject |
|
961 |
"select the element with same printString as the argument, anObject. |
|
962 |
Do not scroll." |
|
963 |
||
964 |
|lineNo| |
|
965 |
||
966 |
list notNil ifTrue:[ |
|
967 |
items notNil ifTrue:[ |
|
968 |
lineNo := items indexOf:anObject ifAbsent:nil |
|
969 |
] ifFalse:[ |
|
970 |
lineNo := list indexOf:(anObject printString) ifAbsent:nil. |
|
971 |
]. |
|
972 |
lineNo notNil ifTrue:[self selectWithoutScroll:lineNo] |
|
973 |
] |
|
974 |
! |
|
975 |
||
976 |
nextAfterSelection |
|
977 |
"return the index of the next selectable entry after the selection. |
|
978 |
Wrap at end." |
|
979 |
||
980 |
|next| |
|
981 |
||
982 |
selection isNil ifTrue:[ |
|
983 |
next := firstLineShown |
|
984 |
] ifFalse:[ |
|
985 |
selection size ~~ 0 ifTrue:[ |
|
986 |
next := selection max + 1 |
|
987 |
] ifFalse:[ |
|
988 |
next := selection + 1 |
|
989 |
]. |
|
990 |
]. |
|
991 |
(self isValidSelection:next) ifFalse:[ |
|
992 |
next > self size ifTrue:[ |
|
993 |
next := 1. |
|
994 |
] ifFalse:[ |
|
995 |
[next <= self size |
|
996 |
and:[(self isValidSelection:next) not]] whileTrue:[ |
|
997 |
next := next + 1 |
|
998 |
]. |
|
999 |
]. |
|
1000 |
]. |
|
1001 |
(self isValidSelection:next) ifFalse:[ |
|
1002 |
next := nil |
|
1003 |
]. |
|
1004 |
^ next |
|
1005 |
! |
|
1006 |
||
1007 |
previousBeforeSelection |
|
1008 |
"return the index of the previous selectable entry before the selection. |
|
1009 |
Wrap at beginning." |
|
1010 |
||
1011 |
|prev| |
|
1012 |
||
1013 |
selection isNil ifTrue:[ |
|
1014 |
prev := firstLineShown - 1 |
|
1015 |
] ifFalse:[ |
|
1016 |
selection size ~~ 0 ifTrue:[ |
|
1017 |
prev := selection min - 1 |
|
1018 |
] ifFalse:[ |
|
1019 |
prev := selection - 1 |
|
1020 |
]. |
|
1021 |
]. |
|
1022 |
(self isValidSelection:prev) ifFalse:[ |
|
1023 |
prev < 1 ifTrue:[ |
|
1024 |
prev := self size. |
|
1025 |
] ifFalse:[ |
|
1026 |
[prev >= 1 |
|
1027 |
and:[(self isValidSelection:prev) not]] whileTrue:[ |
|
1028 |
prev := prev - 1 |
|
1029 |
]. |
|
1030 |
]. |
|
1031 |
]. |
|
1032 |
(self isValidSelection:prev) ifFalse:[ |
|
1033 |
prev := nil |
|
1034 |
]. |
|
1035 |
^ prev |
|
1036 |
||
1037 |
! |
|
1038 |
||
1039 |
selectAll |
|
1040 |
"select all entries." |
|
1041 |
||
1042 |
|oldSelection| |
|
1043 |
||
1044 |
multipleSelectOk ifTrue:[ |
|
1045 |
oldSelection := selection. |
|
1046 |
selection := OrderedCollection withAll:(1 to:self size). |
|
1047 |
shown ifTrue:[self redraw]. |
|
1048 |
self selectionChangedFrom:oldSelection. |
|
1049 |
] |
|
1050 |
! |
|
1051 |
||
1052 |
toggleSelection:aNumber |
|
1053 |
"toggle selection-state of entry, aNumber" |
|
1054 |
||
1055 |
(self isInSelection:aNumber) ifTrue:[ |
|
1056 |
self removeFromSelection:aNumber |
|
1057 |
] ifFalse:[ |
|
1058 |
self addToSelection:aNumber |
|
1059 |
] |
|
1060 |
! |
|
1061 |
||
1062 |
selectNext |
|
1063 |
"select next line or first visible if there is currrently no selection. |
|
1064 |
Wrap at end." |
|
1065 |
||
1066 |
self selection:(self nextAfterSelection) |
|
1067 |
! |
|
1068 |
||
1069 |
selectPrevious |
|
1070 |
"select previous line or previous visible if there is currently no selection. |
|
1071 |
Wrap at beginning." |
|
1072 |
||
164 | 1073 |
self selection:(self previousBeforeSelection). |
1074 |
||
1075 |
"Modified: 26.9.1995 / 09:41:16 / stefan" |
|
125 | 1076 |
! |
1077 |
||
1078 |
selectionDo:aBlock |
|
1079 |
"perform aBlock for each nr in the selection. |
|
1080 |
For single selection, it is called once for the items nr. |
|
1081 |
For multiple selections, it is called for each." |
|
1082 |
||
1083 |
selection notNil ifTrue:[ |
|
1084 |
multipleSelectOk ifTrue:[ |
|
1085 |
selection do:aBlock |
|
1086 |
] ifFalse:[ |
|
1087 |
aBlock value:selection |
|
1088 |
]. |
|
1089 |
]. |
|
1090 |
||
1091 |
! |
|
1092 |
||
1093 |
selectionAsCollection |
|
1094 |
"return the selection as a collection of line numbers. |
|
1095 |
This allows users of this class to enumerate independent of |
|
1096 |
the multipleSelect style." |
|
1097 |
||
1098 |
selection isNil ifTrue:[^ #()]. |
|
1099 |
||
130 | 1100 |
"/ multipleSelectOk ifTrue:[ |
1101 |
"/ ^ (OrderedCollection new) add:selection; yourself. |
|
1102 |
"/ ]. |
|
1103 |
multipleSelectOk ifFalse:[ |
|
1104 |
^ (OrderedCollection new) add:selection; yourself. |
|
125 | 1105 |
]. |
1106 |
^ selection |
|
1107 |
! ! |
|
1108 |
||
0 | 1109 |
!SelectionInListView methodsFor:'redrawing'! |
1110 |
||
1111 |
redrawVisibleLine:visLineNr |
|
31 | 1112 |
"redraw a single line. |
1113 |
Must check, if any is in the selection and handle this case. |
|
1114 |
Otherwise draw using supers method." |
|
1115 |
||
131 | 1116 |
|listLine fg bg newFont id| |
0 | 1117 |
|
1118 |
fg := fgColor. |
|
1119 |
bg := bgColor. |
|
1120 |
listLine := self visibleLineToListLine:visLineNr. |
|
1121 |
listLine notNil ifTrue:[ |
|
59 | 1122 |
(self isInSelection:listLine) ifTrue:[ |
1123 |
^ self drawVisibleLineSelected:visLineNr |
|
1124 |
]. |
|
125 | 1125 |
|
1126 |
listAttributes notNil ifTrue:[ |
|
1127 |
(self line:listLine hasAttribute:#halfIntensity) ifTrue:[ |
|
60 | 1128 |
fg := halfIntensityFgColor |
125 | 1129 |
] ifFalse:[ |
1130 |
(self line:listLine hasAttribute:#disabled) ifTrue:[ |
|
1131 |
fg := halfIntensityFgColor |
|
1132 |
]. |
|
65 | 1133 |
]. |
125 | 1134 |
(self line:listLine hasAttribute:#bold) ifTrue:[ |
131 | 1135 |
newFont := font asBold. |
1136 |
(font bold |
|
1137 |
or:[id := (newFont on:device) fontId. |
|
1138 |
id isNil]) |
|
1139 |
ifTrue:[ |
|
125 | 1140 |
" |
1141 |
mhmh - what can be done, if the font is already bold ? |
|
1142 |
" |
|
1143 |
newFont := font. |
|
1144 |
fgColor brightness > 0.5 ifTrue:[ |
|
1145 |
fg := fgColor darkened "darkened". |
|
1146 |
] ifFalse:[ |
|
1147 |
fg := fgColor lightened "lightened" |
|
1148 |
]. |
|
1149 |
(fg brightness - bg brightness) abs < 0.25 ifTrue:[ |
|
1150 |
bgColor brightness > 0.5 ifTrue:[ |
|
1151 |
fg := fg darkened. |
|
1152 |
] ifFalse:[ |
|
1153 |
fg := fg lightened |
|
1154 |
]. |
|
1155 |
] |
|
77 | 1156 |
]. |
131 | 1157 |
id notNil ifTrue:[ |
1158 |
device setFont:id in:gcId. |
|
1159 |
]. |
|
125 | 1160 |
self drawVisibleLine:visLineNr with:fg and:bg. |
1161 |
device setFont:(font on:device) fontId in:gcId. |
|
1162 |
^ self |
|
1163 |
] |
|
63 | 1164 |
] |
31 | 1165 |
]. |
1166 |
^ self drawVisibleLine:visLineNr with:fg and:bg |
|
1167 |
! |
|
1168 |
||
125 | 1169 |
redrawElement:aNumber |
1170 |
"redraw an individual element" |
|
1171 |
||
1172 |
^ self redrawLine:aNumber |
|
1173 |
! |
|
1174 |
||
31 | 1175 |
drawVisibleLineSelected:visLineNr |
1176 |
"redraw a single line as selected." |
|
1177 |
||
1178 |
|listLine fg bg |
|
1179 |
y "{ Class: SmallInteger }" |
|
1180 |
wEdge| |
|
1181 |
||
1182 |
bg := hilightBgColor. |
|
1183 |
fg := hilightFgColor. |
|
1184 |
listLine := self visibleLineToListLine:visLineNr. |
|
1185 |
listLine notNil ifTrue:[ |
|
1186 |
"XXX only if -1/+1" |
|
1187 |
"/ hilightLevel ~~ 0 ifTrue:[ |
|
1188 |
"/ self paint:bg. |
|
59 | 1189 |
"/ self fillRectangleX:0 y:(self yOfVisibleLine:visLineNr)-1 width:width height:1 |
31 | 1190 |
"/ ]. |
1191 |
||
63 | 1192 |
strikeOut ifTrue:[ |
1193 |
self drawVisibleLine:visLineNr with:fgColor and:bgColor. |
|
1194 |
y := self yOfVisibleLine:visLineNr. |
|
1195 |
||
1196 |
self paint:fgColor. |
|
1197 |
y := y + (fontHeight // 2). |
|
1198 |
self displayLineFromX:0 y:y toX:width y:y. |
|
1199 |
^ self |
|
1200 |
]. |
|
1201 |
||
59 | 1202 |
self drawVisibleLine:visLineNr with:fg and:bg. |
1203 |
y := self yOfVisibleLine:visLineNr. |
|
31 | 1204 |
|
59 | 1205 |
" |
1206 |
a line above and below |
|
1207 |
" |
|
1208 |
hilightFrameColor notNil ifTrue:[ |
|
1209 |
self paint:hilightFrameColor. |
|
1210 |
self displayLineFromX:0 y:y toX:width y:y. |
|
1211 |
y := y + fontHeight - 1. |
|
1212 |
self displayLineFromX:0 y:y toX:width y:y. |
|
1213 |
^ self |
|
1214 |
]. |
|
31 | 1215 |
|
59 | 1216 |
" |
1217 |
an edge it around |
|
1218 |
" |
|
1219 |
(hilightLevel ~~ 0) ifTrue:[ |
|
31 | 1220 |
"XXX the -1/+1 need some more work" |
1221 |
"/ self drawEdgesForX:0 y:y-1 |
|
1222 |
"/ width:width height:fontHeight+1 |
|
1223 |
"/ level:hilightLevel. |
|
1224 |
||
59 | 1225 |
" |
1226 |
let edge start at left, extending to the full width |
|
1227 |
XXX: widthOfContents should be cached in ListView |
|
60 | 1228 |
(instead of recomputing all over) |
59 | 1229 |
" |
1230 |
wEdge := width-(2 * margin). |
|
60 | 1231 |
includesNonStrings ifFalse:[ |
59 | 1232 |
wEdge := wEdge max:(self widthOfContents). |
60 | 1233 |
]. |
59 | 1234 |
self drawEdgesForX:(margin - leftOffset) y:y |
1235 |
width:wEdge height:fontHeight |
|
1236 |
level:hilightLevel. |
|
31 | 1237 |
|
1238 |
||
155 | 1239 |
]. |
1240 |
^ self |
|
0 | 1241 |
]. |
31 | 1242 |
^ super drawVisibleLine:visLineNr with:fg and:bg |
155 | 1243 |
|
1244 |
"Modified: 31.8.1995 / 19:24:09 / claus" |
|
105 | 1245 |
! |
1246 |
||
1247 |
redrawFromVisibleLine:startVisLineNr to:endVisLineNr |
|
1248 |
"redraw a range of lines. |
|
1249 |
Must check, if any is in the selection and handle this case. |
|
1250 |
Otherwise draw it en-bloque using supers method." |
|
1251 |
||
1252 |
|special sel |
|
1253 |
selNo "{ Class: SmallInteger }" | |
|
1254 |
||
1255 |
((selection isCollection) or:[listAttributes notNil]) ifTrue:[ |
|
1256 |
startVisLineNr to:endVisLineNr do:[:visLine | |
|
1257 |
self redrawVisibleLine:visLine |
|
1258 |
]. |
|
1259 |
^ self |
|
1260 |
]. |
|
1261 |
||
1262 |
"XXX only if -1/+1" |
|
1263 |
"/ hilightLevel ~~ 0 ifTrue:[ |
|
1264 |
"/ self paint:bgColor. |
|
1265 |
"/ self fillRectangleX:0 y:(self yOfVisibleLine:startVisLineNr)-1 width:width height:1 |
|
1266 |
"/ ]. |
|
1267 |
special := true. |
|
1268 |
selection isNil ifTrue:[ |
|
1269 |
special := false |
|
1270 |
] ifFalse:[ |
|
1271 |
sel := self listLineToVisibleLine:selection. |
|
1272 |
sel isNil ifTrue:[ |
|
1273 |
special := false |
|
1274 |
] ifFalse:[ |
|
1275 |
special := (sel between:startVisLineNr and:endVisLineNr) |
|
1276 |
] |
|
1277 |
]. |
|
1278 |
special ifFalse:[ |
|
1279 |
^ super redrawFromVisibleLine:startVisLineNr |
|
1280 |
to:endVisLineNr |
|
1281 |
]. |
|
1282 |
||
1283 |
selNo := sel. |
|
1284 |
selNo > startVisLineNr ifTrue:[ |
|
1285 |
super redrawFromVisibleLine:startVisLineNr to:(selNo - 1) |
|
1286 |
]. |
|
1287 |
self redrawVisibleLine:selNo. |
|
1288 |
selNo < endVisLineNr ifTrue:[ |
|
1289 |
super redrawFromVisibleLine:(selNo + 1) to:endVisLineNr |
|
1290 |
] |
|
1291 |
! |
|
1292 |
||
125 | 1293 |
redrawVisibleLine:visLineNr from:startCol to:endCol |
1294 |
"redraw from a startCol to endCol. |
|
1295 |
Must check, if its in the selection and handle this case." |
|
1296 |
||
1297 |
(self visibleLineNeedsSpecialCare:visLineNr) ifTrue:[ |
|
1298 |
^ self redrawVisibleLine:visLineNr |
|
1299 |
]. |
|
1300 |
super redrawVisibleLine:visLineNr from:startCol to:endCol |
|
1301 |
! |
|
1302 |
||
105 | 1303 |
drawRightArrowInVisibleLine:visLineNr |
1304 |
"draw a right arrow (for submenus). |
|
1305 |
This method is not used here, but provided for subclasses such |
|
1306 |
as menus or file-lists." |
|
1307 |
||
1308 |
|y x form form2 topLeftColor botRightColor t| |
|
1309 |
||
1310 |
x := width - 16. |
|
1311 |
y := (self yOfVisibleLine:visLineNr). |
|
1312 |
||
146 | 1313 |
(device depth == 1 or:[arrowLevel == 0]) ifTrue:[ |
105 | 1314 |
form := self class rightArrowFormOn:device. |
1315 |
y := y + ((font height - form height) // 2). |
|
146 | 1316 |
(self isInSelection:(self visibleLineToListLine:visLineNr)) ifTrue:[ |
1317 |
self foreground:hilightFgColor |
|
1318 |
] ifFalse:[ |
|
1319 |
self foreground:fgColor. |
|
1320 |
]. |
|
105 | 1321 |
self displayForm:form x:x y:y. |
1322 |
] ifFalse:[ |
|
1323 |
smallArrow ifTrue:[ |
|
1324 |
form := self class smallRightArrowLightFormOn:device. |
|
1325 |
form2 := self class smallRightArrowShadowFormOn:device. |
|
1326 |
] ifFalse:[ |
|
1327 |
form := self class rightArrowLightFormOn:device. |
|
1328 |
form2 := self class rightArrowShadowFormOn:device. |
|
1329 |
]. |
|
1330 |
y := y + ((font height - form height) // 2). |
|
1331 |
||
1332 |
topLeftColor := lightColor. |
|
1333 |
botRightColor := shadowColor. |
|
1334 |
||
1335 |
"openwin arrow stays down" |
|
130 | 1336 |
styleSheet name ~~ #openwin ifTrue:[ |
105 | 1337 |
(self isInSelection:(self visibleLineToListLine:visLineNr)) ifTrue:[ |
1338 |
t := topLeftColor. |
|
1339 |
topLeftColor := botRightColor. |
|
1340 |
botRightColor := t. |
|
1341 |
] |
|
1342 |
]. |
|
1343 |
arrowLevel < 0 ifTrue:[ |
|
1344 |
t := topLeftColor. |
|
1345 |
topLeftColor := botRightColor. |
|
1346 |
botRightColor := t. |
|
1347 |
]. |
|
1348 |
||
1349 |
"/ self foreground:topLeftColor. |
|
1350 |
self paint:topLeftColor. |
|
1351 |
self displayForm:form x:x y:y. |
|
1352 |
"/ self foreground:botRightColor. |
|
1353 |
self paint:botRightColor. |
|
1354 |
self displayForm:form2 x:x y:y. |
|
1355 |
] |
|
1356 |
! |
|
1357 |
||
1358 |
redrawVisibleLine:visLineNr col:colNr |
|
1359 |
"redraw a single character. |
|
1360 |
Must check, if its in the selection and handle this case." |
|
1361 |
||
1362 |
(self visibleLineNeedsSpecialCare:visLineNr) ifTrue:[ |
|
1363 |
^ self redrawVisibleLine:visLineNr |
|
1364 |
]. |
|
1365 |
super redrawVisibleLine:visLineNr col:colNr |
|
1366 |
! |
|
1367 |
||
1368 |
redrawVisibleLine:visLineNr from:startCol |
|
1369 |
"redraw from a col to the right end. |
|
1370 |
Must check, if its in the selection and handle this case." |
|
1371 |
||
1372 |
(self visibleLineNeedsSpecialCare:visLineNr) ifTrue:[ |
|
1373 |
^ self redrawVisibleLine:visLineNr |
|
1374 |
]. |
|
1375 |
super redrawVisibleLine:visLineNr from:startCol |
|
1376 |
! ! |
|
1377 |
||
1378 |
!SelectionInListView methodsFor:'private'! |
|
1379 |
||
1380 |
getListFromModel |
|
119 | 1381 |
"if I have a model and a listMsg, get my list from it" |
1382 |
||
105 | 1383 |
|text| |
1384 |
||
119 | 1385 |
model notNil ifTrue:[ |
1386 |
listMsg notNil ifTrue:[ |
|
1387 |
items := model perform:listMsg. |
|
1388 |
items notNil ifTrue:[ |
|
1389 |
printItems ifTrue:[ |
|
1390 |
text := items collect:[:element | element printString] |
|
1391 |
] ifFalse:[ |
|
1392 |
text := items |
|
1393 |
]. |
|
128 | 1394 |
"/ text notNil ifTrue:[ |
1395 |
"/ text := text asStringCollection. |
|
1396 |
"/ ] |
|
119 | 1397 |
]. |
133 | 1398 |
self list:text keepSelection:true. "/ expandTabs:false |
119 | 1399 |
]. |
1400 |
]. |
|
1401 |
! |
|
1402 |
||
1403 |
getSelectionFromModel |
|
1404 |
"if I have a model and an initialSelectionMsg, get my selection from it" |
|
1405 |
||
1406 |
|sel| |
|
1407 |
||
1408 |
model notNil ifTrue:[ |
|
1409 |
initialSelectionMsg notNil ifTrue:[ |
|
1410 |
sel := model perform:initialSelectionMsg. |
|
1411 |
useIndex ifTrue:[ |
|
1412 |
self selection:sel |
|
105 | 1413 |
] ifFalse:[ |
119 | 1414 |
self selectElement:sel. |
105 | 1415 |
]. |
119 | 1416 |
] |
105 | 1417 |
]. |
125 | 1418 |
! |
1419 |
||
1420 |
argForChangeMessage |
|
1421 |
"return the argument for a selectionChange; |
|
1422 |
depending on the setting of useIndex, this is either the numeric |
|
1423 |
index of the selection or the value (i.e. the string)" |
|
1424 |
||
1425 |
useIndex ~~ false ifTrue:[ "/ i.e. everything except false |
|
1426 |
^ selection |
|
1427 |
]. |
|
1428 |
||
1429 |
printItems ifFalse:[ |
|
1430 |
^ self selectionValue |
|
1431 |
]. |
|
1432 |
||
1433 |
items notNil ifTrue:[ |
|
1434 |
multipleSelectOk ifTrue:[ |
|
1435 |
^ selection collect:[:nr | items at:nr] |
|
1436 |
]. |
|
1437 |
^ items at:selection |
|
1438 |
]. |
|
1439 |
||
1440 |
^ nil "/ cannot happen |
|
1441 |
! |
|
1442 |
||
1443 |
isValidSelection:aNumberOrCollection |
|
1444 |
"return true, if aNumber is ok as a selection index" |
|
1445 |
||
1446 |
aNumberOrCollection isNil ifTrue:[^ false]. |
|
1447 |
||
1448 |
(aNumberOrCollection isCollection) ifTrue:[ |
|
1449 |
multipleSelectOk ifFalse:[^ false]. |
|
1450 |
aNumberOrCollection do:[:index | |
|
1451 |
(index between:1 and:self size) ifFalse:[^ false]. |
|
1452 |
]. |
|
1453 |
^ true. |
|
1454 |
] ifFalse:[ |
|
1455 |
^ (aNumberOrCollection between:1 and:self size). |
|
1456 |
]. |
|
1457 |
||
1458 |
! |
|
1459 |
||
1460 |
positionToSelectionX:x y:y |
|
1461 |
"given a click position, return the selection lineNo" |
|
1462 |
||
1463 |
|visibleLine| |
|
1464 |
||
1465 |
(x between:0 and:width) ifTrue:[ |
|
1466 |
(y between:0 and:height) ifTrue:[ |
|
1467 |
visibleLine := self visibleLineOfY:y. |
|
1468 |
^ self visibleLineToListLine:visibleLine |
|
1469 |
] |
|
1470 |
]. |
|
1471 |
^ nil |
|
1472 |
! |
|
1473 |
||
1474 |
widthForScrollBetween:start and:end |
|
1475 |
"has to be redefined since WHOLE line is inverted/modified sometimes" |
|
1476 |
||
1477 |
| anySelectionInRange | |
|
1478 |
||
1479 |
selection notNil ifTrue:[ |
|
1480 |
multipleSelectOk ifTrue:[ |
|
1481 |
anySelectionInRange := false. |
|
1482 |
selection do:[:s | |
|
1483 |
(s between:start and:end) ifTrue:[ |
|
1484 |
anySelectionInRange := true |
|
1485 |
] |
|
1486 |
] |
|
1487 |
] ifFalse:[ |
|
1488 |
anySelectionInRange := selection between:start and:end |
|
1489 |
] |
|
1490 |
] ifFalse:[ |
|
1491 |
anySelectionInRange := false |
|
1492 |
]. |
|
1493 |
||
1494 |
anySelectionInRange ifTrue:[ |
|
1495 |
^ width |
|
1496 |
" |
|
1497 |
self is3D ifFalse:[ |
|
1498 |
^ width |
|
1499 |
]. |
|
130 | 1500 |
( #(next openwin) includes:styleSheet name) ifTrue:[ |
125 | 1501 |
^ width |
1502 |
]. |
|
1503 |
viewBackground = background ifFalse:[ |
|
1504 |
^ width |
|
1505 |
] |
|
1506 |
" |
|
1507 |
]. |
|
1508 |
^ super widthForScrollBetween:start and:end |
|
1509 |
! |
|
1510 |
||
1511 |
visibleLineNeedsSpecialCare:visLineNr |
|
1512 |
|listLine| |
|
1513 |
||
1514 |
listLine := self visibleLineToListLine:visLineNr. |
|
1515 |
listLine isNil ifTrue:[^ false]. |
|
1516 |
(self isInSelection:listLine) ifTrue:[^ true]. |
|
1517 |
listAttributes notNil ifTrue:[ |
|
1518 |
(listLine <= listAttributes size) ifTrue:[ |
|
1519 |
^ (listAttributes at:listLine) notNil |
|
1520 |
] |
|
1521 |
]. |
|
1522 |
^ false |
|
1523 |
! |
|
1524 |
||
1525 |
checkRemovingSelection:lineNr |
|
1526 |
"when a line is removed, we have to adjust selection" |
|
1527 |
||
1528 |
|newSelection| |
|
1529 |
||
1530 |
selection notNil ifTrue:[ |
|
1531 |
multipleSelectOk ifTrue:[ |
|
1532 |
newSelection := OrderedCollection new. |
|
1533 |
selection do:[:sel | |
|
1534 |
sel < lineNr ifTrue:[ |
|
1535 |
newSelection add:sel |
|
1536 |
] ifFalse:[ |
|
1537 |
sel > lineNr ifTrue:[ |
|
1538 |
newSelection add:(sel - 1) |
|
1539 |
] |
|
1540 |
"otherwise remove it from the selection" |
|
1541 |
] |
|
1542 |
]. |
|
1543 |
newSelection size == 0 ifTrue:[ |
|
1544 |
selection := nil |
|
1545 |
] ifFalse:[ |
|
1546 |
selection := newSelection |
|
1547 |
] |
|
1548 |
] ifFalse:[ |
|
1549 |
selection == lineNr ifTrue:[ |
|
1550 |
selection := nil |
|
1551 |
] ifFalse:[ |
|
1552 |
selection > lineNr ifTrue:[ |
|
1553 |
selection := selection - 1 |
|
1554 |
] |
|
1555 |
] |
|
1556 |
] |
|
1557 |
] |
|
1558 |
! |
|
1559 |
||
1560 |
scrollSelectDown |
|
1561 |
"auto scroll action; scroll and reinstall timed-block" |
|
1562 |
||
1563 |
self scrollDown. |
|
1564 |
Processor addTimedBlock:autoScrollBlock afterSeconds:autoScrollDeltaT. |
|
1565 |
! |
|
1566 |
||
1567 |
scrollSelectUp |
|
1568 |
"auto scroll action; scroll and reinstall timed-block" |
|
1569 |
||
1570 |
self scrollUp. |
|
1571 |
Processor addTimedBlock:autoScrollBlock afterSeconds:autoScrollDeltaT. |
|
1572 |
! ! |
|
1573 |
||
1574 |
!SelectionInListView methodsFor:'event handling'! |
|
1575 |
||
1576 |
buttonRelease:button x:x y:y |
|
1577 |
"stop any autoscroll" |
|
1578 |
||
1579 |
self stopAutoScroll |
|
1580 |
! |
|
1581 |
||
1582 |
buttonPress:button x:x y:y |
|
1583 |
|oldSelection listLineNr| |
|
1584 |
||
1585 |
((button == 1) or:[button == #select]) ifTrue:[ |
|
1586 |
enabled ifTrue:[ |
|
1587 |
listLineNr := self visibleLineToListLine:(self visibleLineOfY:y). |
|
1588 |
listLineNr notNil ifTrue:[ |
|
1589 |
(toggleSelect |
|
1590 |
and:[self isInSelection:listLineNr]) ifTrue:[ |
|
1591 |
oldSelection := selection copy. |
|
1592 |
self removeFromSelection:listLineNr |
|
1593 |
] ifFalse:[ |
|
1594 |
(self line:listLineNr hasAttribute:#disabled) ifTrue:[^ self]. |
|
1595 |
||
1596 |
(selectConditionBlock notNil |
|
1597 |
and:[(selectConditionBlock value:listLineNr) not]) ifTrue:[^ self]. |
|
1598 |
||
1599 |
(toggleSelect and:[multipleSelectOk]) ifTrue:[ |
|
1600 |
oldSelection := selection copy. |
|
1601 |
self addToSelection:listLineNr |
|
1602 |
] ifFalse:[ |
|
1603 |
oldSelection := selection copy. |
|
1604 |
self selectWithoutScroll:listLineNr. |
|
1605 |
]. |
|
1606 |
]. |
|
1607 |
((ignoreReselect not and:[selection notNil]) |
|
1608 |
or:[selection ~= oldSelection]) ifTrue:[ |
|
1609 |
self selectionChangedFrom:oldSelection. |
|
1610 |
]. |
|
1611 |
clickLine := listLineNr |
|
1612 |
]. |
|
1613 |
] |
|
1614 |
] ifFalse:[ |
|
1615 |
super buttonPress:button x:x y:y |
|
1616 |
] |
|
1617 |
! |
|
1618 |
||
1619 |
sizeChanged:how |
|
1620 |
"if there is a selection, make certain, its visible |
|
1621 |
after the sizechange" |
|
1622 |
||
1623 |
|first wasAtEnd| |
|
1624 |
||
1625 |
wasAtEnd := (firstLineShown + nFullLinesShown) >= self size. |
|
1626 |
||
1627 |
super sizeChanged:how. |
|
1628 |
||
1629 |
shown ifTrue:[ |
|
1630 |
selection notNil ifTrue:[ |
|
1631 |
multipleSelectOk ifTrue:[ |
|
1632 |
first := selection first |
|
1633 |
] ifFalse:[ |
|
1634 |
first := selection |
|
1635 |
]. |
|
1636 |
first notNil ifTrue:[self makeLineVisible:first] |
|
1637 |
] ifFalse:[ |
|
1638 |
" |
|
1639 |
if we where at the end before, move to the end again. |
|
1640 |
Still to be seen, if this is better in real life ... |
|
1641 |
" |
|
1642 |
wasAtEnd ifTrue:[ |
|
1643 |
"at end" |
|
1644 |
self scrollToBottom |
|
1645 |
] |
|
1646 |
] |
|
1647 |
] |
|
1648 |
! |
|
1649 |
||
1650 |
keyPress:key x:x y:y |
|
1651 |
"handle keyboard input" |
|
1652 |
||
132 | 1653 |
<resource: #keyboard ( #BeginOfText #EndOfText ) > |
1654 |
||
125 | 1655 |
|index startSearch backSearch searchPrefix| |
1656 |
||
1657 |
(key == #CursorUp) ifTrue:[ |
|
128 | 1658 |
index := self previousBeforeSelection. |
1659 |
self key:key select:index x:x y:y. |
|
1660 |
^ self |
|
125 | 1661 |
]. |
1662 |
(key == #CursorDown) ifTrue:[ |
|
128 | 1663 |
index := self nextAfterSelection. |
1664 |
self key:key select:index x:x y:y. |
|
1665 |
^ self |
|
125 | 1666 |
]. |
1667 |
"/ |
|
1668 |
"/ stupid: Home and End are cought in ScrollableView |
|
1669 |
"/ we normally do not get them ... |
|
1670 |
"/ (need to call handlesKey: from there ... |
|
1671 |
"/ ... and implement it here) |
|
1672 |
"/ |
|
132 | 1673 |
(key == #BeginOfText) ifTrue:[ |
128 | 1674 |
self key:key select:1 x:x y:y. |
1675 |
^ self |
|
125 | 1676 |
]. |
132 | 1677 |
(key == #EndOfText) ifTrue:[ |
128 | 1678 |
index := self size. |
1679 |
self key:key select:index x:x y:y. |
|
1680 |
^ self |
|
125 | 1681 |
]. |
1682 |
key == #Return ifTrue:[ |
|
128 | 1683 |
returnKeyActionStyle == #doubleClick ifTrue:[ |
1684 |
selection notNil ifTrue:[ |
|
1685 |
self doubleClicked |
|
1686 |
]. |
|
1687 |
^ self |
|
1688 |
]. |
|
1689 |
returnKeyActionStyle ~~ #pass ifTrue:[ |
|
1690 |
^ self |
|
1691 |
]. |
|
125 | 1692 |
]. |
1693 |
||
1694 |
" |
|
1695 |
alphabetic keys: search for next entry |
|
1696 |
starting with keys character. If shift is pressed, search backward |
|
1697 |
" |
|
1698 |
(self size > 0 |
|
1699 |
and:[key isCharacter |
|
1700 |
and:[key isLetter]]) ifTrue:[ |
|
128 | 1701 |
keyActionStyle isNil ifTrue:[^ self]. |
1702 |
keyActionStyle == #pass ifFalse:[ |
|
1703 |
searchPrefix := key asLowercase asString. |
|
125 | 1704 |
|
1705 |
"/ ... isISearch... ifFalse:[ |
|
1706 |
"/ iSearchString := '' |
|
1707 |
"/ ] ifTrue:[ |
|
1708 |
"/ iSearchString := iSearchString , searchPrefix. |
|
1709 |
"/ searchPrefix := iSearchString |
|
1710 |
"/ ]. |
|
1711 |
||
128 | 1712 |
backSearch := device shiftDown. |
1713 |
backSearch ifTrue:[ |
|
1714 |
selection notNil ifTrue:[ |
|
1715 |
selection size > 0 ifTrue:[ |
|
1716 |
startSearch := selection first - 1 |
|
1717 |
] ifFalse:[ |
|
1718 |
startSearch := selection - 1 |
|
1719 |
] |
|
1720 |
] ifFalse:[ |
|
1721 |
startSearch := self size |
|
1722 |
]. |
|
1723 |
startSearch < 1 ifTrue:[ |
|
1724 |
startSearch := self size. |
|
1725 |
]. |
|
1726 |
] ifFalse:[ |
|
1727 |
selection notNil ifTrue:[ |
|
1728 |
selection size > 0 ifTrue:[ |
|
1729 |
startSearch := selection last + 1 |
|
1730 |
] ifFalse:[ |
|
1731 |
startSearch := selection + 1 |
|
1732 |
] |
|
1733 |
] ifFalse:[ |
|
1734 |
startSearch := 1 |
|
1735 |
]. |
|
1736 |
startSearch > self size ifTrue:[ |
|
1737 |
startSearch := 1. |
|
1738 |
]. |
|
1739 |
]. |
|
1740 |
index := startSearch. |
|
1741 |
[true] whileTrue:[ |
|
1742 |
(((self at:index) asString) asLowercase startsWith:searchPrefix) ifTrue:[ |
|
1743 |
index = selection ifTrue:[^ self]. |
|
1744 |
^ self key:key select:index x:x y:y |
|
1745 |
]. |
|
1746 |
backSearch ifTrue:[ |
|
1747 |
index := index - 1. |
|
1748 |
index < 1 ifTrue:[index := self size] |
|
1749 |
] ifFalse:[ |
|
1750 |
index := index + 1. |
|
1751 |
index > self size ifTrue:[index := 1]. |
|
1752 |
]. |
|
1753 |
index == startSearch ifTrue:[ |
|
1754 |
^ self |
|
1755 |
] |
|
1756 |
] |
|
1757 |
]. |
|
125 | 1758 |
]. |
1759 |
^ super keyPress:key x:x y:y |
|
1760 |
! |
|
1761 |
||
1762 |
buttonMotion:buttonMask x:x y:y |
|
1763 |
"mouse-move while button was pressed - handle selection changes" |
|
1764 |
||
1765 |
|movedVisibleLine movedLine delta oldSelection oldSelCount| |
|
1766 |
||
1767 |
"is it the select or 1-button ?" |
|
1768 |
(device buttonMotionMask:buttonMask includesButton:#select) ifFalse:[ |
|
1769 |
(device buttonMotionMask:buttonMask includesButton:1) ifFalse:[ |
|
1770 |
^ self |
|
1771 |
]. |
|
1772 |
]. |
|
1773 |
||
1774 |
clickLine isNil ifTrue:[^ self]. |
|
1775 |
||
1776 |
"if moved outside of view, start autoscroll" |
|
1777 |
(y < 0) ifTrue:[ |
|
1778 |
self compressMotionEvents:false. |
|
1779 |
self startAutoScrollUp:y. |
|
1780 |
^ self |
|
1781 |
]. |
|
1782 |
(y > height) ifTrue:[ |
|
1783 |
self compressMotionEvents:false. |
|
1784 |
self startAutoScrollDown:(y - height). |
|
1785 |
^ self |
|
1786 |
]. |
|
1787 |
||
1788 |
"move inside - stop autoscroll if any" |
|
1789 |
self stopAutoScroll. |
|
1790 |
||
1791 |
movedVisibleLine := self visibleLineOfY:y. |
|
1792 |
movedLine := self visibleLineToAbsoluteLine:movedVisibleLine. |
|
1793 |
(movedLine == clickLine) ifTrue:[^ self]. |
|
1794 |
||
1795 |
multipleSelectOk ifTrue:[ |
|
1796 |
delta := (clickLine < movedLine) ifTrue:[1] ifFalse:[-1]. |
|
1797 |
||
1798 |
oldSelection := selection. |
|
1799 |
oldSelCount := selection size. |
|
1800 |
||
1801 |
(clickLine+delta) to:movedLine by:delta do:[:line | |
|
1802 |
(self isInSelection:line) ifTrue:[ |
|
1803 |
self removeFromSelection:line |
|
1804 |
] ifFalse:[ |
|
1805 |
self addToSelection:line |
|
1806 |
] |
|
1807 |
]. |
|
1808 |
((selection ~= oldSelection) |
|
1809 |
or:[selection size ~~ oldSelCount]) ifTrue:[ |
|
1810 |
self selectionChangedFrom:oldSelection. |
|
1811 |
] |
|
1812 |
] ifFalse:[ |
|
1813 |
"/ self selectWithoutScroll:movedLine |
|
1814 |
]. |
|
1815 |
||
1816 |
clickLine := movedLine |
|
1817 |
! |
|
1818 |
||
1819 |
key:key select:index x:x y:y |
|
1820 |
"select an entry by a keyboard action. |
|
1821 |
This is treated like a doubleClick on that entry" |
|
1822 |
||
1823 |
|oldSelection| |
|
1824 |
||
1825 |
(selectConditionBlock isNil or:[selectConditionBlock value:index]) ifTrue:[ |
|
128 | 1826 |
keyActionStyle notNil ifTrue:[ |
1827 |
keyActionStyle == #pass ifTrue:[ |
|
1828 |
^ super keyPress:key x:x y:y |
|
1829 |
]. |
|
1830 |
oldSelection := selection. |
|
1831 |
self selection:index. |
|
1832 |
self selectionChangedFrom:oldSelection. |
|
1833 |
keyActionStyle == #selectAndDoubleClick ifTrue:[ |
|
1834 |
self doubleClicked |
|
1835 |
] |
|
1836 |
] |
|
125 | 1837 |
]. |
1838 |
! |
|
1839 |
||
1840 |
buttonMultiPress:button x:x y:y |
|
1841 |
((button == 1) or:[button == #select]) ifTrue:[ |
|
1842 |
"/ doubleClickActionBlock isNil ifTrue:[ |
|
1843 |
"/ self buttonPress:button x:x y:y |
|
1844 |
"/ ]. |
|
1845 |
self doubleClicked. |
|
1846 |
] ifFalse:[ |
|
1847 |
super buttonMultiPress:button x:x y:y |
|
1848 |
] |
|
1849 |
! |
|
1850 |
||
1851 |
buttonShiftPress:button x:x y:y |
|
1852 |
"add to the selection (if multipleSelectOk); otherwise, |
|
1853 |
behave like normal select" |
|
1854 |
||
1855 |
|oldSelection listLineNr| |
|
1856 |
||
1857 |
((button == 1) or:[button == #select]) ifTrue:[ |
|
1858 |
toggleSelect ifTrue:[ |
|
1859 |
^ self buttonPress:button x:x y:y |
|
1860 |
]. |
|
1861 |
enabled ifTrue:[ |
|
1862 |
listLineNr := self visibleLineToListLine:(self visibleLineOfY:y). |
|
1863 |
listLineNr notNil ifTrue:[ |
|
1864 |
(self line:listLineNr hasAttribute:#disabled) ifTrue:[^ self]. |
|
1865 |
||
1866 |
(selectConditionBlock notNil |
|
1867 |
and:[(selectConditionBlock value:listLineNr) not]) ifTrue:[^ self]. |
|
1868 |
]. |
|
1869 |
oldSelection := selection copy. |
|
1870 |
listLineNr notNil ifTrue: [ |
|
1871 |
multipleSelectOk ifTrue:[ |
|
1872 |
(self isInSelection:listLineNr) ifTrue:[ |
|
1873 |
self removeFromSelection:listLineNr |
|
1874 |
] ifFalse:[ |
|
1875 |
self addToSelection:listLineNr |
|
1876 |
] |
|
1877 |
] ifFalse:[ |
|
1878 |
self selectWithoutScroll:listLineNr |
|
1879 |
] |
|
1880 |
]. |
|
1881 |
((ignoreReselect not and:[selection notNil]) |
|
1882 |
or:[selection ~= oldSelection]) ifTrue:[ |
|
1883 |
self selectionChangedFrom:oldSelection. |
|
1884 |
]. |
|
1885 |
clickLine := listLineNr |
|
1886 |
] |
|
1887 |
] ifFalse:[ |
|
1888 |
super buttonShiftPress:button x:x y:y |
|
1889 |
] |
|
1890 |
! |
|
1891 |
||
1892 |
doubleClicked |
|
1893 |
doubleClickActionBlock notNil ifTrue:[doubleClickActionBlock value:selection]. |
|
1894 |
(model notNil and:[doubleClickMsg notNil]) ifTrue:[ |
|
1895 |
self sendChangeMessage:doubleClickMsg with:(self argForChangeMessage). |
|
1896 |
]. |
|
1897 |
! ! |
|
1898 |
||
1899 |
!SelectionInListView methodsFor:'accessing-actions'! |
|
1900 |
||
1901 |
action:aBlock |
|
1902 |
"set the action block to be performed on select" |
|
1903 |
||
1904 |
actionBlock := aBlock |
|
1905 |
! |
|
1906 |
||
1907 |
doubleClickAction:aBlock |
|
1908 |
"set the double click action block to be performed on select" |
|
1909 |
||
1910 |
doubleClickActionBlock := aBlock |
|
1911 |
! |
|
1912 |
||
1913 |
selectConditionBlock:aBlock |
|
1914 |
"set the conditionBlock; this block is evaluated before a selection |
|
1915 |
change is performed; the change will not be done, if the evaluation |
|
1916 |
returns false. For example, this allows confirmation queries in |
|
1917 |
the SystemBrowser" |
|
1918 |
||
1919 |
selectConditionBlock := aBlock |
|
1920 |
! |
|
1921 |
||
1922 |
useIndex:aBoolean |
|
1923 |
"set/clear the useIndex flag. If set, both actionBlock and change-messages |
|
1924 |
are passed the index(indices) of the selection as argument. |
|
1925 |
If clear, the value(s) (i.e. the selected string) is passed. |
|
1926 |
Default is true." |
|
1927 |
||
1928 |
useIndex := aBoolean |
|
1929 |
! |
|
1930 |
||
1931 |
keyActionStyle:aSymbol |
|
1932 |
"defines how the view should respond to alpha-keys pressed. |
|
1933 |
Possible values are: |
|
1934 |
#select -> will select next entry starting with that |
|
1935 |
character and perform the click-action |
|
1936 |
||
1937 |
#selectAndDoubleclick -> will select next & perform double-click action |
|
1938 |
||
1939 |
#pass -> will pass key to superclass (i.e. no special treatment) |
|
1940 |
||
1941 |
nil -> will ignore key |
|
1942 |
||
1943 |
the default (set in #initialize) is #select |
|
1944 |
" |
|
1945 |
||
1946 |
keyActionStyle := aSymbol |
|
1947 |
! |
|
1948 |
||
1949 |
returnKeyActionStyle:aSymbol |
|
1950 |
"defines how the view should respond to a return key pressed. |
|
1951 |
Possible values are: |
|
1952 |
#doubleClick -> perform double-click action |
|
1953 |
||
1954 |
#pass -> will pass key to superclass (i.e. no special treatment) |
|
1955 |
||
1956 |
nil -> will ignore key |
|
1957 |
||
1958 |
the default (set in #initialize) is #doubleClick |
|
1959 |
" |
|
1960 |
||
1961 |
returnKeyActionStyle := aSymbol |
|
1962 |
! ! |
|
1963 |
||
1964 |
!SelectionInListView methodsFor:'accessing-attributes'! |
|
1965 |
||
1966 |
line:lineNr hasAttribute:aSymbol |
|
1967 |
"return true, if line nr has attribute, aSymbol; |
|
1968 |
currently supported attributes are: |
|
1969 |
#halfIntensity |
|
1970 |
#disabled |
|
1971 |
#bold |
|
1972 |
" |
|
1973 |
||
1974 |
|attr| |
|
1975 |
||
1976 |
listAttributes isNil ifTrue:[^ false]. |
|
1977 |
(lineNr > listAttributes size) ifTrue:[^ false]. |
|
1978 |
attr := listAttributes at:lineNr. |
|
1979 |
attr isNil ifTrue:[^ false]. |
|
1980 |
attr isSymbol ifTrue:[^ attr == aSymbol]. |
|
1981 |
^ (attr includes:aSymbol) |
|
1982 |
! |
|
1983 |
||
1984 |
setAttributes:aList |
|
1985 |
"set the attribute list. |
|
1986 |
No redraw is done - the caller should make sure to redraw afterwards |
|
1987 |
(or use this only before the view is visible)." |
|
1988 |
||
1989 |
listAttributes := aList |
|
1990 |
! |
|
1991 |
||
1992 |
attributeAt:index put:aSymbolOrCollectionOfSymbolsOrNil |
|
1993 |
"set a lines attribute(s); |
|
1994 |
currently supported are: |
|
1995 |
#halfIntensity |
|
1996 |
#disabled |
|
1997 |
#bold |
|
1998 |
" |
|
1999 |
||
2000 |
(index > self size) ifFalse:[ |
|
2001 |
listAttributes isNil ifTrue:[ |
|
2002 |
listAttributes := (OrderedCollection new:index) grow:index |
|
2003 |
] ifFalse:[ |
|
2004 |
(index > listAttributes size) ifTrue:[ |
|
2005 |
listAttributes grow:index |
|
2006 |
] |
|
2007 |
]. |
|
2008 |
aSymbolOrCollectionOfSymbolsOrNil = (listAttributes at:index) ifFalse:[ |
|
2009 |
listAttributes at:index put:aSymbolOrCollectionOfSymbolsOrNil. |
|
2010 |
self redrawLine:index |
|
2011 |
] |
|
2012 |
] |
|
2013 |
||
2014 |
! |
|
2015 |
||
2016 |
strikeOut:aBoolean |
|
2017 |
"turn on/off strikeOut mode" |
|
2018 |
||
2019 |
strikeOut := aBoolean. |
|
2020 |
! |
|
2021 |
||
2022 |
attributeAt:index |
|
2023 |
"return the line attribute of list line index. |
|
2024 |
currently supported are: |
|
2025 |
#halfIntensity |
|
2026 |
#disabled |
|
2027 |
#bold |
|
2028 |
" |
|
2029 |
||
2030 |
listAttributes isNil ifFalse:[ |
|
2031 |
(index > listAttributes size) ifFalse:[ |
|
2032 |
^ listAttributes at:index |
|
2033 |
] |
|
2034 |
]. |
|
2035 |
^ nil |
|
2036 |
! |
|
2037 |
||
2038 |
attributeAt:index add:aSymbolOrCollectionOfSymbols |
|
2039 |
"add to a lines attribute(s); |
|
2040 |
currently supported are: |
|
2041 |
#halfIntensity |
|
2042 |
#disabled |
|
2043 |
#bold |
|
2044 |
" |
|
2045 |
||
2046 |
|current| |
|
2047 |
||
2048 |
current := self attributeAt:index. |
|
2049 |
current isNil ifTrue:[ |
|
2050 |
current := Set new. |
|
2051 |
] ifFalse:[ |
|
2052 |
current isSymbol ifTrue:[ |
|
2053 |
current == aSymbolOrCollectionOfSymbols ifTrue:[^ self]. |
|
2054 |
current := Set with:current |
|
2055 |
] |
|
2056 |
]. |
|
2057 |
||
2058 |
aSymbolOrCollectionOfSymbols isSymbol ifTrue:[ |
|
2059 |
current := current add:aSymbolOrCollectionOfSymbols |
|
2060 |
] ifFalse:[ |
|
2061 |
(current includes:aSymbolOrCollectionOfSymbols) ifTrue:[^ self]. |
|
2062 |
current addAll:aSymbolOrCollectionOfSymbols |
|
2063 |
]. |
|
2064 |
self attributeAt:index put:current |
|
2065 |
! |
|
2066 |
||
2067 |
attributeAt:index remove:aSymbolOrCollectionOfSymbols |
|
2068 |
"remove a line attribute; |
|
2069 |
currently supported are: |
|
2070 |
#halfIntensity |
|
2071 |
#disabled |
|
2072 |
#bold |
|
2073 |
" |
|
2074 |
||
2075 |
|current| |
|
2076 |
||
2077 |
current := self attributeAt:index. |
|
2078 |
current isNil ifTrue:[^ self]. |
|
2079 |
current isSymbol ifTrue:[ |
|
2080 |
aSymbolOrCollectionOfSymbols isSymbol ifTrue:[ |
|
2081 |
current == aSymbolOrCollectionOfSymbols ifTrue:[current := nil] |
|
2082 |
] ifFalse:[ |
|
2083 |
(aSymbolOrCollectionOfSymbols includes:current) ifTrue:[ |
|
2084 |
current := nil |
|
2085 |
] |
|
2086 |
] |
|
2087 |
] ifFalse:[ |
|
2088 |
aSymbolOrCollectionOfSymbols isSymbol ifTrue:[ |
|
2089 |
current := current remove:aSymbolOrCollectionOfSymbols ifAbsent:[] |
|
2090 |
] ifFalse:[ |
|
2091 |
aSymbolOrCollectionOfSymbols removeAll:aSymbolOrCollectionOfSymbols |
|
2092 |
] |
|
2093 |
]. |
|
2094 |
self attributeAt:index put:current |
|
2095 |
! ! |
|
2096 |
||
2097 |
!SelectionInListView methodsFor:'accessing-behavior'! |
|
2098 |
||
2099 |
ignoreReselect:aBoolean |
|
2100 |
"set/clear the ignoreReselect flag - |
|
2101 |
if set, a click on an already selected entry is ignored. |
|
2102 |
Otherwise the notification is done, even if no |
|
2103 |
change in the selection occurs. |
|
130 | 2104 |
(for example, in browser to update a method). |
2105 |
Setting ignoreReselect to false makes sense if data is shown |
|
2106 |
which may change by itself (i.e. without the user doing anything) |
|
2107 |
For example, the inspector uses this, and redisplays the value, |
|
2108 |
if the selection is the same. |
|
2109 |
The default is true, meaning that a click on an already selected |
|
2110 |
does not lead to a notification via the actionBlock/change mechanism." |
|
125 | 2111 |
|
2112 |
ignoreReselect := aBoolean |
|
2113 |
! |
|
2114 |
||
2115 |
toggleSelect:aBoolean |
|
2116 |
"turn on/off toggle select. If true, clicking on a selected entry |
|
130 | 2117 |
unselects it and vice versa. The default is false, which means |
2118 |
that clicking on an already selected entry does not change its |
|
2119 |
select status (see also ignoreReselect:)." |
|
125 | 2120 |
|
2121 |
toggleSelect := aBoolean. |
|
2122 |
! |
|
2123 |
||
2124 |
multipleSelectOk:aBoolean |
|
130 | 2125 |
"allow/disallow multiple selections. If enabled, the |
2126 |
user may select multiple entries in the list, and the program |
|
2127 |
always gets a collection of selected items (indexes if useIndex is true, |
|
2128 |
values otherwise). The default is false, for single selections." |
|
125 | 2129 |
|
2130 |
multipleSelectOk := aBoolean. |
|
2131 |
aBoolean ifTrue:[ |
|
2132 |
self enableButtonMotionEvents |
|
2133 |
] ifFalse:[ |
|
2134 |
self disableButtonMotionEvents |
|
2135 |
] |
|
2136 |
! |
|
2137 |
||
2138 |
enable |
|
2139 |
"enable the view - selection changes are allowed" |
|
2140 |
||
2141 |
enabled := true |
|
2142 |
! |
|
2143 |
||
2144 |
disable |
|
2145 |
"disable the view - no selection changes are allowed" |
|
2146 |
||
2147 |
enabled := false |
|
2148 |
! ! |
|
2149 |
||
2150 |
!SelectionInListView methodsFor:'accessing-contents'! |
|
2151 |
||
128 | 2152 |
printItems:aBoolean |
2153 |
"set/clear the printItems flag. If set, items (as set via #list: or |
|
2154 |
as returned from the model) are sent #printString to display them. |
|
2155 |
If false, items are assumed to be either strings, or know how to |
|
2156 |
display themself in a GC (i.e. they are instances of ListEntry). |
|
2157 |
The default is false. |
|
2158 |
Caveat: printString seems to be too specialized - I'd rather have |
|
2159 |
a definable printSelector or - better - a printConverter. |
|
2160 |
This may be added in the future." |
|
2161 |
||
2162 |
printItems := aBoolean |
|
2163 |
! |
|
2164 |
||
125 | 2165 |
list:aCollection |
2166 |
"set the list - redefined, since setting the list implies unselecting |
|
2167 |
and clearing attributes." |
|
2168 |
||
133 | 2169 |
self list:aCollection keepSelection:false |
2170 |
! |
|
2171 |
||
2172 |
list:aCollection keepSelection:aBoolean |
|
2173 |
"set the list - redefined, since setting the list implies unselecting |
|
2174 |
and clearing attributes." |
|
2175 |
||
2176 |
|oldSelection| |
|
2177 |
||
125 | 2178 |
"somewhat of a kludge: if selection is first line, |
2179 |
we have to remove the highlight frame by hand here" |
|
2180 |
||
2181 |
(shown and:[hilightLevel ~~ 0]) ifTrue:[ |
|
2182 |
selection == firstLineShown ifTrue:[ |
|
2183 |
self paint:bgColor. |
|
2184 |
self fillRectangleX:margin y:margin |
|
2185 |
width:(width - (margin * 2)) |
|
2186 |
height:(hilightLevel abs). |
|
2187 |
]. |
|
2188 |
]. |
|
2189 |
||
133 | 2190 |
aBoolean ifTrue:[ |
2191 |
oldSelection := selection. |
|
2192 |
selection := nil. |
|
2193 |
]. |
|
125 | 2194 |
listAttributes := nil. |
151 | 2195 |
super list:aCollection expandTabs:printItems. |
133 | 2196 |
self selection:oldSelection. "/ nil if keep is false |
125 | 2197 |
! |
2198 |
||
2199 |
setList:aCollection |
|
2200 |
"set the list - redefined, since setting the list implies unselecting |
|
2201 |
and clearing attributes. |
|
2202 |
No redraw is done - the caller should make sure to redraw afterwards |
|
2203 |
(or use this only before the view is visible)." |
|
2204 |
||
2205 |
selection := nil. |
|
2206 |
listAttributes := nil. |
|
2207 |
super setList:aCollection. |
|
2208 |
! |
|
2209 |
||
133 | 2210 |
setContents:aCollection |
2211 |
"set the list - redefined, since setting the list implies unselecting |
|
2212 |
and clearing attributes. |
|
2213 |
No redraw is done - the caller should make sure to redraw afterwards |
|
2214 |
(or use this only before the view is visible)." |
|
2215 |
||
2216 |
selection := nil. |
|
2217 |
listAttributes := nil. |
|
2218 |
super setContents:aCollection. |
|
2219 |
! |
|
2220 |
||
2221 |
contents:aCollection |
|
2222 |
"set the list - redefined, since setting the list implies unselecting |
|
2223 |
and clearing attributes. |
|
2224 |
No redraw is done - the caller should make sure to redraw afterwards |
|
2225 |
(or use this only before the view is visible)." |
|
2226 |
||
2227 |
selection := nil. |
|
2228 |
listAttributes := nil. |
|
2229 |
super contents:aCollection. |
|
2230 |
! |
|
2231 |
||
125 | 2232 |
removeIndexWithoutRedraw:lineNr |
2233 |
"delete line - no redraw; |
|
2234 |
return true, if something was really deleted. |
|
2235 |
Redefined since we have to care for selection" |
|
2236 |
||
2237 |
self checkRemovingSelection:lineNr. |
|
2238 |
^ super removeIndexWithoutRedraw:lineNr |
|
2239 |
! |
|
2240 |
||
2241 |
removeIndex:lineNr |
|
2242 |
"delete line - with redraw. |
|
2243 |
Redefined since we have to care for selection" |
|
2244 |
||
2245 |
self checkRemovingSelection:lineNr. |
|
2246 |
^ super removeIndex:lineNr |
|
2247 |
! |
|
2248 |
||
2249 |
add:aValue beforeIndex:index |
|
2250 |
"must recompute our current selections" |
|
2251 |
||
2252 |
selection notNil ifTrue:[ |
|
2253 |
multipleSelectOk ifTrue:[ |
|
2254 |
selection := selection collect:[ :sel | |
|
2255 |
sel >= index ifTrue:[ |
|
2256 |
sel + 1 |
|
2257 |
] ifFalse:[ |
|
2258 |
sel |
|
2259 |
] |
|
2260 |
]. |
|
2261 |
] ifFalse:[ |
|
2262 |
selection >= index ifTrue:[ |
|
2263 |
selection := selection + 1. |
|
2264 |
]. |
|
2265 |
]. |
|
2266 |
]. |
|
2267 |
^ super add:aValue beforeIndex:index. |
|
105 | 2268 |
! ! |
2269 |
||
155 | 2270 |
!SelectionInListView methodsFor:'queries'! |
2271 |
||
2272 |
specClass |
|
2273 |
self class == SelectionInListView ifTrue:[^ SequenceViewSpec]. |
|
2274 |
^ nil |
|
2275 |
||
2276 |
"Modified: 5.9.1995 / 23:05:53 / claus" |
|
2277 |
! ! |
|
2278 |
||
105 | 2279 |
!SelectionInListView methodsFor:'initialization'! |
2280 |
||
2281 |
initCursor |
|
2282 |
"set the cursor - a hand" |
|
2283 |
||
2284 |
cursor := Cursor hand |
|
2285 |
! |
|
2286 |
||
2287 |
initialize |
|
2288 |
super initialize. |
|
2289 |
||
2290 |
fontHeight := font height + lineSpacing. |
|
2291 |
enabled := true. |
|
2292 |
ignoreReselect := true. |
|
125 | 2293 |
multipleSelectOk := toggleSelect := strikeOut := printItems := false. |
2294 |
useIndex := true. |
|
2295 |
||
105 | 2296 |
keyActionStyle := #select. |
125 | 2297 |
returnKeyActionStyle := #doubleClick. |
2298 |
||
2299 |
listMsg := self class defaultListMessage. |
|
2300 |
initialSelectionMsg := self class defaultSelectionMessage. |
|
2301 |
||
2302 |
! |
|
2303 |
||
2304 |
realize |
|
2305 |
super realize. |
|
2306 |
||
128 | 2307 |
"/ self getListFromModel. -- not needed; superclass did it already |
125 | 2308 |
self getSelectionFromModel. |
2309 |
||
2310 |
selection notNil ifTrue:[ |
|
130 | 2311 |
selection isCollection ifTrue:[ |
2312 |
self makeLineVisible:selection first |
|
2313 |
] ifFalse:[ |
|
2314 |
self makeLineVisible:selection |
|
2315 |
] |
|
125 | 2316 |
]. |
105 | 2317 |
! |
2318 |
||
2319 |
initStyle |
|
2320 |
|nm| |
|
2321 |
||
2322 |
super initStyle. |
|
2323 |
||
2324 |
DefaultFont notNil ifTrue:[ |
|
2325 |
font := DefaultFont on:device |
|
2326 |
]. |
|
2327 |
||
2328 |
bgColor := viewBackground. |
|
2329 |
hilightFrameColor := nil. |
|
2330 |
hilightLevel := 0. |
|
2331 |
arrowLevel := 1. |
|
2332 |
smallArrow := false. |
|
2333 |
||
2334 |
device hasGreyscales ifTrue:[ |
|
2335 |
" |
|
2336 |
must get rid of these hard codings |
|
2337 |
" |
|
130 | 2338 |
nm := styleSheet name. |
105 | 2339 |
(nm == #next) ifTrue:[ |
2340 |
hilightFgColor := fgColor. |
|
2341 |
hilightBgColor := White. |
|
2342 |
hilightFrameColor := fgColor |
|
2343 |
] ifFalse:[ |
|
2344 |
(nm == #motif) ifTrue:[ |
|
2345 |
fgColor := White. |
|
2346 |
bgColor := Grey. |
|
2347 |
viewBackground := bgColor. |
|
2348 |
hilightFgColor := bgColor "fgColor" "White". |
|
2349 |
hilightBgColor := fgColor "bgColor lightened" "darkened". |
|
2350 |
] ifFalse:[ |
|
2351 |
(nm == #openwin) ifTrue:[ |
|
2352 |
hilightFgColor := fgColor. |
|
2353 |
hilightBgColor := Color grey. |
|
2354 |
smallArrow := true. |
|
2355 |
] |
|
2356 |
] |
|
2357 |
] |
|
2358 |
]. |
|
2359 |
||
2360 |
hilightFgColor isNil ifTrue:[ |
|
2361 |
hilightFgColor := bgColor. |
|
2362 |
]. |
|
2363 |
hilightBgColor isNil ifTrue:[ |
|
2364 |
hilightBgColor := fgColor. |
|
2365 |
]. |
|
2366 |
DefaultForegroundColor notNil ifTrue:[ |
|
2367 |
fgColor := DefaultForegroundColor |
|
2368 |
]. |
|
2369 |
DefaultBackgroundColor notNil ifTrue:[ |
|
2370 |
bgColor := viewBackground := DefaultBackgroundColor |
|
2371 |
]. |
|
2372 |
DefaultHilightForegroundColor notNil ifTrue:[ |
|
2373 |
hilightFgColor := DefaultHilightForegroundColor |
|
2374 |
]. |
|
2375 |
DefaultHilightBackgroundColor notNil ifTrue:[ |
|
2376 |
hilightBgColor := DefaultHilightBackgroundColor |
|
2377 |
]. |
|
2378 |
DefaultHilightFrameColor notNil ifTrue:[ |
|
2379 |
hilightFrameColor := DefaultHilightFrameColor |
|
2380 |
]. |
|
2381 |
DefaultHilightLevel notNil ifTrue:[ |
|
2382 |
hilightLevel := DefaultHilightLevel |
|
2383 |
]. |
|
2384 |
DefaultRightArrowLevel notNil ifTrue:[ |
|
2385 |
arrowLevel := DefaultRightArrowLevel |
|
2386 |
]. |
|
2387 |
||
2388 |
DefaultShadowColor notNil ifTrue:[ |
|
2389 |
shadowColor := DefaultShadowColor on:device |
|
2390 |
]. |
|
2391 |
DefaultLightColor notNil ifTrue:[ |
|
2392 |
lightColor := DefaultLightColor on:device |
|
2393 |
]. |
|
2394 |
||
2395 |
(hilightLevel abs > 0) ifTrue:[ |
|
2396 |
lineSpacing := 3 |
|
2397 |
] ifFalse:[ |
|
2398 |
lineSpacing := 2 |
|
2399 |
]. |
|
2400 |
||
2401 |
hilightFgColor isNil ifTrue:[ |
|
2402 |
hilightFgColor := bgColor. |
|
2403 |
hilightBgColor := fgColor |
|
2404 |
]. |
|
2405 |
||
2406 |
DefaultDisabledForegroundColor notNil ifTrue:[ |
|
2407 |
halfIntensityFgColor := DefaultDisabledForegroundColor |
|
2408 |
] ifFalse:[ |
|
2409 |
halfIntensityFgColor := Color darkGrey. |
|
2410 |
]. |
|
2411 |
||
2412 |
fgColor := fgColor on:device. |
|
2413 |
bgColor := bgColor on:device. |
|
2414 |
halfIntensityFgColor := halfIntensityFgColor on:device. |
|
2415 |
hilightFrameColor notNil ifTrue:[hilightFrameColor := hilightFrameColor on:device]. |
|
2416 |
hilightFgColor := hilightFgColor on:device. |
|
2417 |
hilightBgColor := hilightBgColor on:device. |
|
0 | 2418 |
! ! |
2419 |
||
125 | 2420 |
!SelectionInListView methodsFor:'change & update'! |
0 | 2421 |
|
105 | 2422 |
update:something with:aParameter from:changedObject |
2423 |
changedObject == model ifTrue:[ |
|
128 | 2424 |
something == aspectMsg ifTrue:[ |
2425 |
self getListFromModel. |
|
2426 |
self getSelectionFromModel. |
|
2427 |
^ self |
|
2428 |
]. |
|
2429 |
something == listMsg ifTrue:[ |
|
2430 |
self getListFromModel. |
|
2431 |
^ self |
|
2432 |
]. |
|
2433 |
something == initialSelectionMsg ifTrue:[ |
|
2434 |
self getSelectionFromModel. |
|
2435 |
^ self |
|
2436 |
]. |
|
2437 |
something == #empty ifTrue:[ |
|
2438 |
self list:nil. |
|
2439 |
^ self |
|
2440 |
]. |
|
105 | 2441 |
]. |
2442 |
^ super update:something with:aParameter from:changedObject |
|
125 | 2443 |
! ! |
2444 |
||
2445 |
!SelectionInListView methodsFor:'accessing-selection'! |
|
2446 |
||
2447 |
addToSelection:aNumber |
|
2448 |
"add entry, aNumber to the selection. No scrolling is done." |
|
2449 |
||
2450 |
(self isValidSelection:aNumber) ifFalse:[^ self]. |
|
2451 |
||
2452 |
selection isNil ifTrue:[^ self selectWithoutScroll:aNumber]. |
|
2453 |
selection isCollection ifTrue:[ |
|
2454 |
(selection includes:aNumber) ifTrue:[^ self]. |
|
2455 |
(selectConditionBlock notNil |
|
2456 |
and:[(selectConditionBlock value:aNumber) not]) ifTrue:[^ self]. |
|
2457 |
selection add:aNumber |
|
2458 |
] ifFalse:[ |
|
2459 |
(aNumber == selection) ifTrue:[^ self]. |
|
2460 |
(selectConditionBlock notNil |
|
2461 |
and:[(selectConditionBlock value:aNumber) not]) ifTrue:[^ self]. |
|
2462 |
selection := OrderedCollection with:selection with:aNumber |
|
63 | 2463 |
]. |
125 | 2464 |
self redrawElement:aNumber |
2465 |
! |
|
2466 |
||
2467 |
addElementToSelection:anObject |
|
2468 |
"add the element with the same printstring as the argument, anObject |
|
2469 |
to the selection. The entry is searched by comparing printStrings. |
|
2470 |
No scrolling is done. Returns true, if ok, false if no such entry |
|
2471 |
was found." |
|
2472 |
||
2473 |
|lineNo str| |
|
2474 |
||
2475 |
str := anObject printString. |
|
2476 |
lineNo := list findFirst:[:entry | str = entry printString]. |
|
2477 |
lineNo ~~ 0 ifTrue:[ |
|
2478 |
self addToSelection:lineNo. |
|
2479 |
^ true |
|
0 | 2480 |
]. |
125 | 2481 |
^ false |
2482 |
! |
|
2483 |
||
2484 |
removeFromSelection:aNumber |
|
2485 |
"remove entry, aNumber from the selection." |
|
2486 |
||
2487 |
selection isNil ifTrue:[^ self]. |
|
0 | 2488 |
|
2489 |
multipleSelectOk ifTrue:[ |
|
125 | 2490 |
(selection includes:aNumber) ifFalse:[^ self]. |
2491 |
selection remove:aNumber. |
|
2492 |
selection size == 0 ifTrue:[ |
|
2493 |
selection := nil |
|
59 | 2494 |
] |
0 | 2495 |
] ifFalse:[ |
125 | 2496 |
(aNumber == selection) ifFalse:[^ self]. |
2497 |
selection := nil |
|
0 | 2498 |
]. |
125 | 2499 |
self redrawElement:aNumber |
0 | 2500 |
! ! |
125 | 2501 |
|
2502 |
!SelectionInListView methodsFor:'accessing-mvc'! |
|
2503 |
||
2504 |
on:aModel printItems:print oneItem:one aspect:aspectSymbol change:changeSymbol |
|
2505 |
list:listSymbol menu:menuSymbol initialSelection:initialSymbol useIndex:use |
|
2506 |
||
2507 |
"ST-80 compatibility" |
|
2508 |
||
2509 |
aspectMsg := aspectSymbol. |
|
2510 |
changeMsg := changeSymbol. |
|
2511 |
listMsg := listSymbol. |
|
2512 |
menuMsg := menuSymbol. |
|
2513 |
initialSelectionMsg := initialSymbol. |
|
2514 |
printItems := print. |
|
2515 |
oneItem := one. |
|
2516 |
useIndex := use. |
|
2517 |
ignoreReselect := false. "/ ST80 behavior |
|
2518 |
self model:aModel. |
|
2519 |
! |
|
2520 |
||
2521 |
doubleClickMessage |
|
2522 |
"return the symbol with which the model (if any) is informed about |
|
2523 |
double-click. If nil (which is the default), it is not informed." |
|
2524 |
||
2525 |
^ doubleClickMsg |
|
2526 |
! |
|
2527 |
||
2528 |
doubleClickMessage:aSymbol |
|
2529 |
"set the symbol with which the model (if any) is informed about double-click. |
|
2530 |
If nil (which is the default), it is not informed." |
|
2531 |
||
2532 |
doubleClickMsg := aSymbol |
|
2533 |
! |
|
2534 |
||
2535 |
doubleClick:aSymbol |
|
2536 |
"set the symbol with which the model is informed about double-click. |
|
2537 |
OBSOLETE: please use #doubleClickMessage:" |
|
2538 |
||
2539 |
self obsoleteMethodWarning:'please use #doubleClickMessage:'. |
|
2540 |
doubleClickMsg := aSymbol |
|
2541 |
! |
|
2542 |
||
2543 |
initialSelectionMessage |
|
2544 |
"return the symbol by which the model informes me about a changed |
|
2545 |
selectionIndex. This is used both in change notification and to |
|
2546 |
actually aquire a new selection value." |
|
2547 |
||
2548 |
^ initialSelectionMsg |
|
2549 |
! |
|
2550 |
||
2551 |
initialSelectionMessage:aSymbol |
|
2552 |
"set the symbol by which the model informes me about a changed |
|
2553 |
selectionIndex. This is used both in change notification and to |
|
2554 |
actually aquire a new selection value." |
|
2555 |
||
2556 |
initialSelectionMsg := aSymbol |
|
2557 |
! |
|
2558 |
||
2559 |
addModelInterfaceTo:aDictionary |
|
2560 |
"see comment in View>>modelInterface" |
|
2561 |
||
2562 |
super addModelInterfaceTo:aDictionary. |
|
2563 |
aDictionary at:#doubleClickMessage put:doubleClickMsg. |
|
2564 |
aDictionary at:#initialSelectionMessage put:initialSelectionMsg. |
|
2565 |
||
2566 |
" |
|
2567 |
SelectionInListView new modelInterface |
|
2568 |
" |
|
2569 |
! ! |