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