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