author | Claus Gittinger <cg@exept.de> |
Sat, 07 Mar 2020 00:22:39 +0100 | |
changeset 6237 | 12ad20ee2671 |
parent 6219 | 342922e53517 |
permissions | -rw-r--r-- |
6219 | 1 |
"{ Encoding: utf8 }" |
2 |
||
487 | 3 |
" |
488 | 4 |
COPYRIGHT (c) 1997 by eXept Software AG |
487 | 5 |
All Rights Reserved |
6 |
||
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
1818 | 14 |
"{ Package: 'stx:libwidg2' }" |
15 |
||
5060 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
487 | 18 |
SelectionInTreeView subclass:#FileSelectionTree |
1173 | 19 |
instanceVariableNames:'triggerMonitorBlock monitoringDelayTime' |
487 | 20 |
classVariableNames:'' |
21 |
poolDictionaries:'' |
|
1233 | 22 |
category:'Views-Trees' |
487 | 23 |
! |
24 |
||
25 |
!FileSelectionTree class methodsFor:'documentation'! |
|
26 |
||
27 |
copyright |
|
28 |
" |
|
488 | 29 |
COPYRIGHT (c) 1997 by eXept Software AG |
487 | 30 |
All Rights Reserved |
31 |
||
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
||
40 |
||
41 |
! |
|
42 |
||
43 |
documentation |
|
44 |
" |
|
45 |
somewhat like a FileSelectionInList; but specialized for hierarchical (i.e. tree-like) |
|
5685 | 46 |
lists and adds the functions to show/hide subtrees. |
487 | 47 |
Requires SelectionInTree as model and FileSelectionItem (or compatible) list entries. |
48 |
||
5685 | 49 |
You can define your own TreeItem instead of using the default class FileSelectionItem |
50 |
by setting the class through to #itemClass: |
|
487 | 51 |
|
52 |
[see also:] |
|
53 |
FileSelectionItem |
|
54 |
SelectionInTree |
|
55 |
SelectionInTreeView |
|
56 |
SelectionInListView |
|
57 |
||
58 |
[author:] |
|
59 |
Claus Atzkern |
|
60 |
" |
|
61 |
! |
|
62 |
||
63 |
examples |
|
64 |
" |
|
65 |
open a FileSelectionTree on current directory |
|
66 |
[exBegin] |
|
67 |
|top scr| |
|
68 |
||
69 |
top := StandardSystemView new label:'select'; extent:300@500. |
|
70 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
71 |
scr := scr scrolledView. |
|
72 |
||
812 | 73 |
scr directory:'/'. |
74 |
scr showDirectoryIndicator:true. |
|
75 |
scr showRoot:false. |
|
76 |
scr showLines:false. |
|
77 |
scr allowDrag:true. |
|
78 |
scr multipleSelectOk:true. |
|
487 | 79 |
|
80 |
top open |
|
81 |
[exEnd] |
|
82 |
||
83 |
||
5686 | 84 |
open a FileSelectionTree using a model |
513 | 85 |
[exBegin] |
86 |
|top scr model| |
|
87 |
||
88 |
top := StandardSystemView new label:'select'; extent:300@500. |
|
89 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
90 |
scr := scr scrolledView. |
|
91 |
model := (Filename currentDirectory asString) asValue. |
|
92 |
scr rootHolder:model. |
|
93 |
model inspect. |
|
94 |
||
95 |
scr action:[:anIndex| Transcript showCR:anIndex. |
|
96 |
Transcript showCR:scr selectedPathname. |
|
97 |
]. |
|
98 |
top open |
|
99 |
[exEnd] |
|
100 |
||
101 |
||
102 |
[exBegin] |
|
103 |
|top scr| |
|
104 |
||
105 |
top := StandardSystemView new label:'select'; extent:300@500. |
|
106 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
107 |
scr := scr scrolledView. |
|
108 |
||
109 |
scr directory:Filename currentDirectory. |
|
110 |
scr selectionHolder:nil asValue. |
|
111 |
scr selectionHolder inspect. |
|
112 |
scr multipleSelectOk:true. |
|
113 |
||
114 |
scr action:[:anIndex| Transcript showCR:anIndex. |
|
115 |
Transcript showCR:scr selectedPathname. |
|
116 |
]. |
|
117 |
top open |
|
118 |
[exEnd] |
|
119 |
||
120 |
||
487 | 121 |
|
122 |
open a FileSelectionTree on root path; show directory |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
123 |
indication (open/closed), no lines and not the root |
487 | 124 |
[exBegin] |
125 |
|top scr| |
|
126 |
||
127 |
top := StandardSystemView new label:'select'; extent:300@500. |
|
128 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
129 |
scr := scr scrolledView. |
|
130 |
scr showDirectoryIndicator:true. |
|
131 |
scr showLines:false. |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
132 |
scr showRoot:false. |
487 | 133 |
|
134 |
scr directory:'/'. |
|
135 |
||
136 |
scr action:[:anIndex| Transcript showCR:anIndex. |
|
137 |
Transcript showCR:scr selectedPathname. |
|
138 |
]. |
|
139 |
top open |
|
140 |
[exEnd] |
|
141 |
||
142 |
||
143 |
||
144 |
open a FileSelectionTree on root path; showing only files |
|
145 |
[exBegin] |
|
146 |
|top scr| |
|
147 |
||
148 |
top := StandardSystemView new label:'select'; extent:300@500. |
|
149 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
150 |
scr := scr scrolledView. |
|
787 | 151 |
scr itemClass:(FileSelectionItem filterClassForDirectoriesOnly). |
487 | 152 |
scr directory:'/'. |
153 |
||
154 |
scr action:[:anIndex| Transcript showCR:anIndex. |
|
155 |
Transcript showCR:scr selectedPathname. |
|
156 |
]. |
|
157 |
top open |
|
158 |
[exEnd] |
|
159 |
||
160 |
||
161 |
||
162 |
open a FileSelectionTree on a specified path |
|
163 |
[exBegin] |
|
164 |
|top scr| |
|
165 |
||
166 |
top := StandardSystemView new label:'select'; extent:300@500. |
|
167 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
168 |
scr := scr scrolledView. |
|
169 |
scr directory:'/'. |
|
170 |
scr showLines:false. |
|
171 |
scr action:[:anIndex| Transcript showCR:scr selectedPathname ]. |
|
172 |
scr doubleClickAction:[:anIndex| Transcript showCR:scr selectedPathname ]. |
|
173 |
top open |
|
174 |
[exEnd] |
|
175 |
||
176 |
||
177 |
||
178 |
open a FileSelectionTree on a specified path; show or hide |
|
179 |
lines on doubleClick on a file (not a directory) |
|
180 |
[exBegin] |
|
181 |
|top scr| |
|
182 |
||
183 |
top := StandardSystemView new label:'select'; extent:300@500. |
|
184 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
185 |
scr := scr scrolledView. |
|
186 |
scr directory:'/'. |
|
187 |
||
188 |
scr action:[:anIndex| Transcript showCR:anIndex. |
|
189 |
Transcript showCR:scr selectedPathname. |
|
190 |
]. |
|
191 |
scr doubleClickAction:[:anIndex| |
|
192 |
|fn| |
|
193 |
fn := scr selectedPathname asFilename. |
|
194 |
fn isDirectory ifFalse:[ |
|
195 |
scr showLines:(scr showLines not) |
|
196 |
] |
|
197 |
]. |
|
198 |
top open |
|
199 |
[exEnd] |
|
200 |
||
201 |
||
202 |
||
492 | 203 |
example associated with a FileSelectionList |
204 |
[exBegin] |
|
205 |
|top tree list field label| |
|
206 |
||
207 |
top := StandardSystemView new label:'select'; extent:600@600. |
|
208 |
tree := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(0.5 @ 1.0) in:top. |
|
209 |
list := HVScrollableView for:FileSelectionList origin:(0.5 @ 25) corner:(1.0 @ 1.0) in:top. |
|
210 |
label := Label origin:(0.5 @ 2) in:top. |
|
211 |
label label:'pattern:'. |
|
212 |
field := EditField origin:0.5@2 in:top. |
|
213 |
field leftInset:(label preferredExtent x) + 5. |
|
214 |
field width:1.0. |
|
215 |
field editValue:'*'. |
|
216 |
field crAction:[list pattern:field editValue]. |
|
217 |
||
218 |
tree := tree scrolledView. |
|
219 |
list := list scrolledView. |
|
220 |
list ignoreDirectories:true. |
|
221 |
list pattern:(field editValue). |
|
222 |
||
787 | 223 |
tree itemClass:(FileSelectionItem filterClassForDirectoriesOnly). |
492 | 224 |
tree directory:(Filename homeDirectory). |
225 |
tree showDirectoryIndicator:true. |
|
226 |
list directory:(tree directory). |
|
227 |
||
228 |
list action:[:index| Transcript showCR:'you selected: ' , list selectedPathname]. |
|
229 |
tree action:[:anIndex| |
|
230 |
list directory:(tree selectedPathname). |
|
231 |
]. |
|
232 |
top open |
|
233 |
[exEnd] |
|
234 |
||
235 |
||
236 |
||
487 | 237 |
a more complex example |
238 |
[exBegin] |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
239 |
|top listD listF field lbl inset| |
487 | 240 |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
241 |
top := StandardSystemView new label:'select'; extent:600@600. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
242 |
inset := 26. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
243 |
listD := HVScrollableView for:FileSelectionTree origin:(0.0 @ inset) corner:(0.5 @ 1.0) in:top. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
244 |
listF := HVScrollableView for:FileSelectionTree origin:(0.5 @ 0.0) corner:(1.0 @ 1.0) in:top. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
245 |
listD := listD scrolledView. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
246 |
listF := listF scrolledView. |
487 | 247 |
|
787 | 248 |
listD itemClass:(FileSelectionItem filterClassForDirectoriesOnly). |
249 |
listF itemClass:(FileSelectionItem filterClassForFilesOnly). |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
250 |
listD showDirectoryIndicator:true. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
251 |
listD showLines:false. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
252 |
listF showLines:false. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
253 |
listF showRoot:false. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
254 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
255 |
lbl := Label label:'directory:' in:top. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
256 |
lbl origin:5 @ ((inset - lbl preferredExtent y) // 2). |
487 | 257 |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
258 |
field := FilenameEditField in:top. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
259 |
field origin:(4 + lbl corner x) @ ((inset - field preferredExtent y) // 2). |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
260 |
field width:0.5. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
261 |
field rightInset:(field origin x + 4). |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
262 |
field directoriesOnly. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
263 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
264 |
field crAction:[|dir| |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
265 |
dir := field editValue asFilename. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
266 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
267 |
(dir isDirectory and:[listD directory ~= dir pathName]) ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
268 |
listD changeDirectory:dir |
487 | 269 |
] |
270 |
]. |
|
271 |
||
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
272 |
listF action:[:anIndex||file| |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
273 |
(file := listF selectedPathname) notNil ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
274 |
Transcript showCR:'selection: ', file |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
275 |
] |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
276 |
]. |
487 | 277 |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
278 |
listD directory:(Filename homeDirectory). |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
279 |
field editValue:listD directory. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
280 |
|
569 | 281 |
listD doubleClickAction:[:anIndex||path| |
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
282 |
path := listD selectedPathname. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
283 |
listF directory:path. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
284 |
path notNil ifTrue:[field editValue:path] |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
285 |
]. |
487 | 286 |
top open |
287 |
[exEnd] |
|
288 |
" |
|
569 | 289 |
! ! |
290 |
||
291 |
!FileSelectionTree class methodsFor:'constants'! |
|
292 |
||
293 |
monitoringDelayTime |
|
294 |
"default delay time of monitoring task in seconds |
|
295 |
" |
|
296 |
^ 2 |
|
487 | 297 |
! ! |
298 |
||
299 |
!FileSelectionTree methodsFor:'accessing'! |
|
300 |
||
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
301 |
changeDirectory:aPathname |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
302 |
"change the root directory; try to reuse old hierarchy list and |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
303 |
the selection in case of a single selection. The pathname must |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
304 |
be a directory otherwise the root directory is set to nil |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
305 |
" |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
306 |
|oldSel child loc oldPath oldFile newFile newPath node idx| |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
307 |
|
812 | 308 |
newFile := self makeLegalFilename:aPathname. |
309 |
oldPath := self directory. |
|
310 |
||
1140 | 311 |
(newFile notNil |
312 |
and:[newFile isDirectory |
|
313 |
and:[oldPath notNil]]) ifFalse:[ |
|
812 | 314 |
^ self directory:newFile |
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
315 |
]. |
812 | 316 |
|
317 |
(newPath := newFile pathName) = oldPath ifTrue:[ |
|
318 |
^ self |
|
319 |
]. |
|
320 |
||
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
321 |
oldFile := oldPath asFilename. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
322 |
oldSel := self selectedNode. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
323 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
324 |
(newPath startsWith:oldPath) ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
325 |
node := self detectNode:[:aNode|aNode pathName = newPath]. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
326 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
327 |
node isNil ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
328 |
^ self directory:newFile |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
329 |
]. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
330 |
] ifFalse:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
331 |
(oldPath startsWith:newPath) ifFalse:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
332 |
^ self directory:newFile |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
333 |
]. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
334 |
child := model root. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
335 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
336 |
[newPath = oldPath] whileFalse:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
337 |
oldFile := oldFile directory. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
338 |
node := self itemClass pathName:oldFile. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
339 |
node expand. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
340 |
loc := node children. |
2832 | 341 |
idx := loc findFirst:[:el| el pathName = oldPath ]. |
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
342 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
343 |
idx == 0 ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
344 |
^ self directory:newFile |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
345 |
]. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
346 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
347 |
loc at:idx put:child. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
348 |
child parent:node. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
349 |
child := node. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
350 |
oldPath := oldFile pathName. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
351 |
] |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
352 |
]. |
812 | 353 |
|
354 |
node children size == 0 ifTrue:[ |
|
355 |
oldSel := node. |
|
356 |
||
357 |
(node := node parent) isNil ifTrue:[ |
|
358 |
^ self directory:newFile |
|
359 |
] |
|
360 |
] ifFalse:[ |
|
361 |
node isExpandable ifTrue:[ |
|
362 |
^ self directory:newFile |
|
363 |
] |
|
364 |
]. |
|
365 |
||
366 |
selection := nil. |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
367 |
node parent:nil. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
368 |
model root:node. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
369 |
self setSelection:(self indexOfNode:oldSel). |
586 | 370 |
model removeDependent:self. |
371 |
model selection:selection. |
|
372 |
model addDependent:self. |
|
1140 | 373 |
|
374 |
"Modified: / 24.9.1998 / 13:00:09 / cg" |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
375 |
! |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
376 |
|
487 | 377 |
directory |
378 |
"get the full pathname of the root directory |
|
379 |
" |
|
380 |
|root| |
|
381 |
||
382 |
(root := model root) notNil ifTrue:[ |
|
383 |
^ root pathName |
|
384 |
]. |
|
385 |
^ nil |
|
386 |
! |
|
387 |
||
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
388 |
directory:aPath |
487 | 389 |
"change the root directory of the selection tree to the full pathName, |
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
390 |
aPath. The pathname must be a directory otherwise the root directory |
487 | 391 |
is set to nil. |
392 |
" |
|
1142 | 393 |
|root path isOK| |
492 | 394 |
|
586 | 395 |
model selection:(selection := nil). |
812 | 396 |
path := self makeLegalFilename:aPath. |
487 | 397 |
|
1140 | 398 |
(path notNil |
399 |
and:[path isDirectory |
|
400 |
and:[path isExecutable]]) ifTrue:[ |
|
1142 | 401 |
isOK := true. |
402 |
] ifFalse:[ |
|
403 |
"/ special for WIN32 / VMS |
|
404 |
isOK := path isVolumeAbsolute |
|
405 |
]. |
|
406 |
isOK ifTrue:[ |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
407 |
root := self itemClass pathName:path. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
408 |
model root:root. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
409 |
model expand:root. |
1140 | 410 |
] ifFalse:[ |
1142 | 411 |
model root:nil |
586 | 412 |
]. |
487 | 413 |
|
1142 | 414 |
"Modified: / 24.9.1998 / 17:43:11 / cg" |
487 | 415 |
! |
416 |
||
417 |
itemClass:anItemClass |
|
418 |
"set itemClass to be used |
|
419 |
" |
|
1173 | 420 |
|directory old new| |
487 | 421 |
|
1173 | 422 |
old := self itemClass. |
423 |
super itemClass:anItemClass. |
|
424 |
new := self itemClass. |
|
487 | 425 |
|
1173 | 426 |
(old ~~ new and:[new notNil and:[(directory := self directory) notNil]]) ifTrue:[ |
427 |
self directory:directory "/ recompute list |
|
487 | 428 |
]. |
429 |
||
492 | 430 |
! |
431 |
||
432 |
pathnameAtIndex:anIndex |
|
433 |
"returns pathname at an index or nil |
|
434 |
" |
|
435 |
|node| |
|
436 |
||
437 |
(node := self nodeAtIndex:anIndex) notNil ifTrue:[ |
|
438 |
^ node pathName |
|
439 |
]. |
|
440 |
^ nil |
|
487 | 441 |
! ! |
442 |
||
1818 | 443 |
!FileSelectionTree methodsFor:'accessing-monitoring'! |
569 | 444 |
|
445 |
monitoring |
|
446 |
"returns true if monitor process is running |
|
447 |
" |
|
573 | 448 |
^ triggerMonitorBlock notNil |
569 | 449 |
! |
450 |
||
5448 | 451 |
monitoring:aBoolean |
452 |
"enable or disable monitoring" |
|
453 |
||
454 |
aBoolean ifTrue:[ |
|
573 | 455 |
triggerMonitorBlock notNil ifTrue:[^ self]. |
2400 | 456 |
"/ triggerMonitorBlock := [self sensor pushUserEvent:#monitorCycle for:self]. |
457 |
triggerMonitorBlock := [self pushEvent:#monitorCycle]. |
|
573 | 458 |
Processor addTimedBlock:triggerMonitorBlock afterSeconds:(self monitoringDelayTime). |
569 | 459 |
] ifFalse:[ |
573 | 460 |
triggerMonitorBlock isNil ifTrue:[^ self]. |
461 |
Processor removeTimedBlock:triggerMonitorBlock. |
|
462 |
triggerMonitorBlock := nil. |
|
569 | 463 |
]. |
5448 | 464 |
|
465 |
"Modified (comment): / 04-02-2017 / 21:32:26 / cg" |
|
569 | 466 |
! |
467 |
||
468 |
monitoringDelayTime |
|
469 |
"delay time of monitoring task in seconds |
|
470 |
" |
|
471 |
^ monitoringDelayTime |
|
472 |
! |
|
473 |
||
474 |
monitoringDelayTime:seconds |
|
475 |
"delay time of monitoring task in seconds |
|
476 |
" |
|
477 |
seconds > 0 ifTrue:[ |
|
478 |
monitoringDelayTime := seconds |
|
479 |
] |
|
480 |
! ! |
|
481 |
||
812 | 482 |
!FileSelectionTree methodsFor:'drag & drop'! |
483 |
||
484 |
dragObjectForNode:aNode |
|
485 |
"returns the dragable object for a node; could be redefined in subclass |
|
486 |
" |
|
487 |
^ DropObject new:(aNode contents) |
|
488 |
||
489 |
||
490 |
||
491 |
! ! |
|
492 |
||
487 | 493 |
!FileSelectionTree methodsFor:'initialization'! |
494 |
||
569 | 495 |
destroy |
496 |
||
573 | 497 |
triggerMonitorBlock notNil ifTrue:[ |
498 |
Processor removeTimedBlock:triggerMonitorBlock. |
|
499 |
triggerMonitorBlock := nil |
|
569 | 500 |
]. |
501 |
super destroy. |
|
502 |
||
503 |
! |
|
504 |
||
487 | 505 |
initialize |
6219 | 506 |
"setup my model and set the default path to the current directory; |
507 |
by default, multiple selection is disabled. |
|
487 | 508 |
" |
1173 | 509 |
itemClass := FileSelectionItem. |
510 |
||
487 | 511 |
super initialize. |
1173 | 512 |
|
513 |
itemClass := FileSelectionItem. |
|
569 | 514 |
monitoringDelayTime := self class monitoringDelayTime. |
1173 | 515 |
supportsExpandAll := false. |
513 | 516 |
! ! |
517 |
||
518 |
!FileSelectionTree methodsFor:'model'! |
|
519 |
||
520 |
rootFromModel |
|
521 |
"update hierarchical list from root model |
|
522 |
" |
|
1269 | 523 |
|newPath| |
513 | 524 |
|
525 |
(newPath := rootHolder value) notNil ifTrue:[ |
|
526 |
newPath := newPath asString. |
|
2087 | 527 |
self directory = newPath ifFalse:[ |
528 |
self changeDirectory:newPath |
|
529 |
] |
|
513 | 530 |
]. |
531 |
||
532 |
! |
|
533 |
||
534 |
selectionFromModel |
|
535 |
"set the selection derived from the selectionHolder |
|
536 |
" |
|
1269 | 537 |
|selection value size| |
513 | 538 |
|
539 |
selectionHolder isNil ifTrue:[ |
|
540 |
^ self |
|
541 |
]. |
|
542 |
||
856 | 543 |
(value := selectionHolder value) isNil ifTrue:[ |
544 |
^ self deselect |
|
545 |
]. |
|
513 | 546 |
|
547 |
multipleSelectOk ifFalse:[ |
|
856 | 548 |
(value isKindOf:TreeItem) ifTrue:[ |
549 |
super selectionFromModel |
|
513 | 550 |
] ifFalse:[ |
551 |
value asFilename exists ifFalse:[ |
|
552 |
selectionHolder value:nil |
|
553 |
] ifTrue:[ |
|
554 |
self selectPathname:value |
|
555 |
] |
|
556 |
]. |
|
557 |
^ self |
|
558 |
]. |
|
559 |
||
856 | 560 |
value isEmpty ifTrue:[ |
513 | 561 |
^ self deselect |
562 |
]. |
|
563 |
||
856 | 564 |
(value first isKindOf:TreeItem) ifTrue:[ |
565 |
^ super selectionFromModel |
|
566 |
]. |
|
513 | 567 |
selection := value select:[:aPath| aPath asFilename exists ]. |
568 |
||
856 | 569 |
(size := selection size) ~~ value size ifTrue:[ |
570 |
size ~~ 0 ifTrue:[selectionHolder value:selection] |
|
571 |
ifFalse:[selectionHolder value:nil]. |
|
572 |
^ self |
|
513 | 573 |
]. |
856 | 574 |
selection := selection collect:[:aPath| self fileName2node:aPath ]. |
575 |
model doMakeVisible:selection. |
|
576 |
selection := selection collect:[:el| listOfNodes identityIndexOf:el ]. |
|
513 | 577 |
super selection:selection. |
578 |
! |
|
579 |
||
580 |
selectionToModel |
|
581 |
"write selection to selection holder |
|
582 |
" |
|
583 |
|old new| |
|
584 |
||
585 |
old := selectionHolder value. |
|
586 |
||
587 |
multipleSelectOk ifFalse:[ |
|
588 |
(new := self pathnameAtIndex:selection) = old ifFalse:[ |
|
1143 | 589 |
"/ selectionHolder value:new. |
590 |
selectionHolder value:new withoutNotifying:self. |
|
513 | 591 |
] |
592 |
] ifTrue:[ |
|
593 |
self numberOfSelections == 0 ifTrue:[ |
|
594 |
old size ~~ 0 ifTrue:[ |
|
595 |
selectionHolder value:nil |
|
596 |
] |
|
597 |
] ifFalse:[ |
|
598 |
new := selection collect:[:i|(listOfNodes at:i) pathName]. |
|
599 |
||
600 |
new size ~~ old size ifTrue:[ |
|
601 |
selectionHolder value:new |
|
602 |
] ifFalse:[ |
|
603 |
new do:[:pN| |
|
5060 | 604 |
(old includes:pN) ifFalse:[ |
605 |
^ selectionHolder value:new |
|
606 |
] |
|
513 | 607 |
] |
608 |
] |
|
609 |
] |
|
610 |
] |
|
611 |
||
1143 | 612 |
"Modified: / 24.9.1998 / 19:25:55 / cg" |
513 | 613 |
! ! |
614 |
||
615 |
!FileSelectionTree methodsFor:'private'! |
|
616 |
||
856 | 617 |
fileName2node:aFile |
1269 | 618 |
|root file p1 p2| |
856 | 619 |
|
2719 | 620 |
root := model root. |
621 |
root isNil ifTrue:[ ^ nil ]. |
|
622 |
||
623 |
"/ file := self makeLegalFilename:aFile. |
|
624 |
"/ file isNil ifTrue:[ ^ nil ]. |
|
625 |
||
626 |
file := aFile asFilename. |
|
856 | 627 |
|
628 |
p1 := root pathName. |
|
629 |
p2 := file pathName. |
|
630 |
||
631 |
(p2 startsWith:p1) ifFalse:[ |
|
632 |
^ nil |
|
633 |
]. |
|
634 |
p1 := Filename components:p1. |
|
635 |
p2 := (Filename components:p2) copyFrom:(p1 size). |
|
636 |
||
5254 | 637 |
"/ that's a kludge for network drives |
3602
f5b68b5591c3
fixed entry callback and net-drive handling
Claus Gittinger <cg@exept.de>
parents:
2974
diff
changeset
|
638 |
(p2 first endsWith:$\) ifTrue:[ |
3609 | 639 |
(p2 first endsWith:':\') ifFalse:[ |
640 |
p2 := p2 copy. |
|
4208
62cbffb9921d
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
3609
diff
changeset
|
641 |
p2 at:1 put:(p2 first copyButLast:1). |
3609 | 642 |
] |
3602
f5b68b5591c3
fixed entry callback and net-drive handling
Claus Gittinger <cg@exept.de>
parents:
2974
diff
changeset
|
643 |
]. |
f5b68b5591c3
fixed entry callback and net-drive handling
Claus Gittinger <cg@exept.de>
parents:
2974
diff
changeset
|
644 |
|
1379
bc7f3700e933
care for caseless-filename-systems
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
645 |
Filename isCaseSensitive ifFalse:[ |
bc7f3700e933
care for caseless-filename-systems
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
646 |
^ model |
3602
f5b68b5591c3
fixed entry callback and net-drive handling
Claus Gittinger <cg@exept.de>
parents:
2974
diff
changeset
|
647 |
detectItem:[:aNode :name | |
f5b68b5591c3
fixed entry callback and net-drive handling
Claus Gittinger <cg@exept.de>
parents:
2974
diff
changeset
|
648 |
aNode name asLowercase = name asLowercase |
f5b68b5591c3
fixed entry callback and net-drive handling
Claus Gittinger <cg@exept.de>
parents:
2974
diff
changeset
|
649 |
or:[ aNode fileName name = name asLowercase ] |
f5b68b5591c3
fixed entry callback and net-drive handling
Claus Gittinger <cg@exept.de>
parents:
2974
diff
changeset
|
650 |
] |
1379
bc7f3700e933
care for caseless-filename-systems
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
651 |
arguments:p2. |
bc7f3700e933
care for caseless-filename-systems
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
652 |
]. |
bc7f3700e933
care for caseless-filename-systems
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
653 |
|
1143 | 654 |
^ model |
655 |
detectItem:[:aNode :name | aNode name = name ] |
|
656 |
arguments:p2. |
|
657 |
||
1379
bc7f3700e933
care for caseless-filename-systems
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
658 |
"Modified: / 18.5.1999 / 19:30:19 / cg" |
856 | 659 |
! |
660 |
||
812 | 661 |
makeLegalFilename:aFile |
1269 | 662 |
|filename| |
812 | 663 |
|
1140 | 664 |
aFile isNil ifTrue:[ ^ nil ]. |
812 | 665 |
|
1140 | 666 |
(filename := aFile asFilename) exists ifTrue:[ |
667 |
filename isDirectory ifFalse:[ |
|
668 |
^ filename |
|
669 |
] |
|
812 | 670 |
]. |
1079
d793b0b568e1
use filenames makeLegalFilename (for win32)
Claus Gittinger <cg@exept.de>
parents:
856
diff
changeset
|
671 |
|
1269 | 672 |
^ filename makeLegalFilename. |
812 | 673 |
|
1140 | 674 |
"Modified: / 24.9.1998 / 12:41:29 / cg" |
812 | 675 |
! |
676 |
||
569 | 677 |
monitorCycle |
678 |
"run monitor cycle |
|
679 |
" |
|
680 |
|sz root sel new old| |
|
681 |
||
4247 | 682 |
(root := model root) notNil ifTrue:[ |
573 | 683 |
root hasObsoleteNodes ifTrue:[ |
684 |
(root repairObsoleteNodes) ifTrue:[ |
|
685 |
sz := self numberOfSelections. |
|
686 |
||
687 |
sz ~~ 0 ifTrue:[ |
|
688 |
old := self selection. |
|
689 |
||
690 |
sz == 1 ifTrue:[ |
|
691 |
sel := self selectedNode |
|
692 |
] ifFalse:[ |
|
693 |
sel := OrderedCollection new. |
|
694 |
self selectionDo:[:i| sel add:(listOfNodes at:i) ]. |
|
695 |
]. |
|
696 |
selection := nil. |
|
697 |
]. |
|
698 |
selection := old. |
|
699 |
model root:root. |
|
700 |
||
701 |
sz ~~ 0 ifTrue:[ |
|
787 | 702 |
sz == 1 ifTrue:[ |
573 | 703 |
self selectNode:sel. |
704 |
] ifFalse:[ |
|
705 |
new := OrderedCollection new. |
|
706 |
||
707 |
sel do:[:n||i| |
|
708 |
(i := self indexOfNode:n) ~~ 0 ifTrue:[new add:i] |
|
709 |
]. |
|
710 |
self selection:new |
|
711 |
] |
|
712 |
]. |
|
713 |
] |
|
714 |
] |
|
569 | 715 |
]. |
716 |
||
573 | 717 |
Processor addTimedBlock:triggerMonitorBlock afterSeconds:(self monitoringDelayTime). |
487 | 718 |
! ! |
719 |
||
720 |
!FileSelectionTree methodsFor:'selection'! |
|
721 |
||
722 |
selectPathname:aPath |
|
723 |
"set selection to a path |
|
724 |
" |
|
856 | 725 |
self selectNode:(self fileName2node:aPath) |
726 |
! |
|
727 |
||
728 |
selectedNodeExpand:doExpand |
|
729 |
"collapse or expand selected node. |
|
730 |
Redefined to show a busy cursor while reading dirs" |
|
487 | 731 |
|
856 | 732 |
doExpand ifTrue:[ |
733 |
self withWaitCursorDo:[ |
|
734 |
super selectedNodeExpand:doExpand |
|
735 |
] |
|
736 |
] ifFalse:[ |
|
737 |
super selectedNodeExpand:doExpand |
|
738 |
] |
|
487 | 739 |
! |
740 |
||
741 |
selectedPathname |
|
742 |
"if there is a single selection, the full pathname of the selected |
|
743 |
entry will be returned otherwise nil |
|
744 |
" |
|
745 |
|node| |
|
746 |
||
747 |
(node := self selectedNode) notNil ifTrue:[ |
|
748 |
^ node pathName |
|
749 |
]. |
|
2973 | 750 |
^ nil |
487 | 751 |
! ! |
752 |
||
753 |
!FileSelectionTree class methodsFor:'documentation'! |
|
754 |
||
755 |
version |
|
5060 | 756 |
^ '$Header$' |
5686 | 757 |
! |
758 |
||
759 |
version_CVS |
|
760 |
^ '$Header$' |
|
487 | 761 |
! ! |
4208
62cbffb9921d
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
3609
diff
changeset
|
762 |