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