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