author | Claus Gittinger <cg@exept.de> |
Sun, 07 Mar 1999 14:30:12 +0100 | |
changeset 1233 | ba2244433fd4 |
parent 1173 | fd8b36ca763f |
child 1269 | f33ad4d38b5b |
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 |
" |
|
12 |
||
13 |
||
14 |
||
15 |
SelectionInTreeView subclass:#FileSelectionTree |
|
1173 | 16 |
instanceVariableNames:'triggerMonitorBlock monitoringDelayTime' |
487 | 17 |
classVariableNames:'' |
18 |
poolDictionaries:'' |
|
1233 | 19 |
category:'Views-Trees' |
487 | 20 |
! |
21 |
||
22 |
!FileSelectionTree class methodsFor:'documentation'! |
|
23 |
||
24 |
copyright |
|
25 |
" |
|
488 | 26 |
COPYRIGHT (c) 1997 by eXept Software AG |
487 | 27 |
All Rights Reserved |
28 |
||
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
||
37 |
||
38 |
! |
|
39 |
||
40 |
documentation |
|
41 |
" |
|
42 |
somewhat like a FileSelectionInList; but specialized for hierarchical (i.e. tree-like) |
|
43 |
lists and adds the functions to show/hide subtrees. |
|
44 |
Requires SelectionInTree as model and FileSelectionItem (or compatible) list entries. |
|
45 |
||
46 |
You can define your own TreeItem instead of useing the default class FileSelectionItem |
|
47 |
by seting the class through to #itemClass: |
|
48 |
||
49 |
[see also:] |
|
50 |
FileSelectionItem |
|
51 |
SelectionInTree |
|
52 |
SelectionInTreeView |
|
53 |
SelectionInListView |
|
54 |
||
55 |
[author:] |
|
56 |
Claus Atzkern |
|
57 |
" |
|
58 |
||
59 |
||
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 |
||
513 | 84 |
open a FileSelectionTree useing a model |
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 |
" |
|
289 |
||
812 | 290 |
|
569 | 291 |
! ! |
292 |
||
293 |
!FileSelectionTree class methodsFor:'constants'! |
|
294 |
||
295 |
monitoringDelayTime |
|
296 |
"default delay time of monitoring task in seconds |
|
297 |
" |
|
298 |
^ 2 |
|
487 | 299 |
! ! |
300 |
||
301 |
!FileSelectionTree methodsFor:'accessing'! |
|
302 |
||
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
303 |
changeDirectory:aPathname |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
304 |
"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
|
305 |
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
|
306 |
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
|
307 |
" |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
308 |
|oldSel child loc oldPath oldFile newFile newPath node idx| |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
309 |
|
812 | 310 |
newFile := self makeLegalFilename:aPathname. |
311 |
oldPath := self directory. |
|
312 |
||
1140 | 313 |
(newFile notNil |
314 |
and:[newFile isDirectory |
|
315 |
and:[oldPath notNil]]) ifFalse:[ |
|
812 | 316 |
^ self directory:newFile |
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
317 |
]. |
812 | 318 |
|
319 |
(newPath := newFile pathName) = oldPath ifTrue:[ |
|
320 |
^ self |
|
321 |
]. |
|
322 |
||
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
323 |
oldFile := oldPath asFilename. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
324 |
oldSel := self selectedNode. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
325 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
326 |
(newPath startsWith:oldPath) ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
327 |
node := self detectNode:[:aNode|aNode pathName = newPath]. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
328 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
329 |
node isNil ifTrue:[ |
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 |
] ifFalse:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
333 |
(oldPath startsWith:newPath) ifFalse:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
334 |
^ self directory:newFile |
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 |
child := model root. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
337 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
338 |
[newPath = oldPath] whileFalse:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
339 |
oldFile := oldFile directory. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
340 |
node := self itemClass pathName:oldFile. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
341 |
node expand. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
342 |
loc := node children. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
343 |
idx := loc findFirst:[:el| el pathName = oldPath ]. |
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 |
idx == 0 ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
346 |
^ self directory:newFile |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
347 |
]. |
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 |
loc at:idx put:child. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
350 |
child parent:node. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
351 |
child := node. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
352 |
oldPath := oldFile pathName. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
353 |
] |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
354 |
]. |
812 | 355 |
|
356 |
node children size == 0 ifTrue:[ |
|
357 |
oldSel := node. |
|
358 |
||
359 |
(node := node parent) isNil ifTrue:[ |
|
360 |
^ self directory:newFile |
|
361 |
] |
|
362 |
] ifFalse:[ |
|
363 |
node isExpandable ifTrue:[ |
|
364 |
^ self directory:newFile |
|
365 |
] |
|
366 |
]. |
|
367 |
||
368 |
selection := nil. |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
369 |
node parent:nil. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
370 |
model root:node. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
371 |
self setSelection:(self indexOfNode:oldSel). |
586 | 372 |
model removeDependent:self. |
373 |
model selection:selection. |
|
374 |
model addDependent:self. |
|
1140 | 375 |
|
376 |
"Modified: / 24.9.1998 / 13:00:09 / cg" |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
377 |
! |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
378 |
|
487 | 379 |
directory |
380 |
"get the full pathname of the root directory |
|
381 |
" |
|
382 |
|root| |
|
383 |
||
384 |
(root := model root) notNil ifTrue:[ |
|
385 |
^ root pathName |
|
386 |
]. |
|
387 |
^ nil |
|
388 |
! |
|
389 |
||
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
390 |
directory:aPath |
487 | 391 |
"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
|
392 |
aPath. The pathname must be a directory otherwise the root directory |
487 | 393 |
is set to nil. |
394 |
" |
|
1142 | 395 |
|root path isOK| |
492 | 396 |
|
586 | 397 |
model selection:(selection := nil). |
812 | 398 |
path := self makeLegalFilename:aPath. |
487 | 399 |
|
1140 | 400 |
(path notNil |
401 |
and:[path isDirectory |
|
402 |
and:[path isExecutable]]) ifTrue:[ |
|
1142 | 403 |
isOK := true. |
404 |
] ifFalse:[ |
|
405 |
"/ special for WIN32 / VMS |
|
406 |
isOK := path isVolumeAbsolute |
|
407 |
]. |
|
408 |
isOK ifTrue:[ |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
409 |
root := self itemClass pathName:path. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
410 |
model root:root. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
411 |
model expand:root. |
1140 | 412 |
] ifFalse:[ |
1142 | 413 |
model root:nil |
586 | 414 |
]. |
487 | 415 |
|
1142 | 416 |
"Modified: / 24.9.1998 / 17:43:11 / cg" |
487 | 417 |
! |
418 |
||
419 |
itemClass:anItemClass |
|
420 |
"set itemClass to be used |
|
421 |
" |
|
1173 | 422 |
|directory old new| |
487 | 423 |
|
1173 | 424 |
old := self itemClass. |
425 |
super itemClass:anItemClass. |
|
426 |
new := self itemClass. |
|
487 | 427 |
|
1173 | 428 |
(old ~~ new and:[new notNil and:[(directory := self directory) notNil]]) ifTrue:[ |
429 |
self directory:directory "/ recompute list |
|
487 | 430 |
]. |
431 |
||
492 | 432 |
! |
433 |
||
434 |
pathnameAtIndex:anIndex |
|
435 |
"returns pathname at an index or nil |
|
436 |
" |
|
437 |
|node| |
|
438 |
||
439 |
(node := self nodeAtIndex:anIndex) notNil ifTrue:[ |
|
440 |
^ node pathName |
|
441 |
]. |
|
442 |
^ nil |
|
487 | 443 |
! ! |
444 |
||
569 | 445 |
!FileSelectionTree methodsFor:'accessing monitoring'! |
446 |
||
447 |
monitoring |
|
448 |
"returns true if monitor process is running |
|
449 |
" |
|
573 | 450 |
^ triggerMonitorBlock notNil |
569 | 451 |
! |
452 |
||
453 |
monitoring:aState |
|
454 |
"enable or disable monitoring |
|
455 |
" |
|
456 |
aState ifTrue:[ |
|
573 | 457 |
triggerMonitorBlock notNil ifTrue:[^ self]. |
458 |
triggerMonitorBlock := [self sensor pushUserEvent:#monitorCycle for:self]. |
|
459 |
Processor addTimedBlock:triggerMonitorBlock afterSeconds:(self monitoringDelayTime). |
|
569 | 460 |
] ifFalse:[ |
573 | 461 |
triggerMonitorBlock isNil ifTrue:[^ self]. |
462 |
Processor removeTimedBlock:triggerMonitorBlock. |
|
463 |
triggerMonitorBlock := nil. |
|
569 | 464 |
]. |
465 |
! |
|
466 |
||
467 |
monitoringDelayTime |
|
468 |
"delay time of monitoring task in seconds |
|
469 |
" |
|
470 |
^ monitoringDelayTime |
|
471 |
! |
|
472 |
||
473 |
monitoringDelayTime:seconds |
|
474 |
"delay time of monitoring task in seconds |
|
475 |
" |
|
476 |
seconds > 0 ifTrue:[ |
|
477 |
monitoringDelayTime := seconds |
|
478 |
] |
|
479 |
! ! |
|
480 |
||
812 | 481 |
!FileSelectionTree methodsFor:'drag & drop'! |
482 |
||
483 |
dragObjectForNode:aNode |
|
484 |
"returns the dragable object for a node; could be redefined in subclass |
|
485 |
" |
|
486 |
^ DropObject new:(aNode contents) |
|
487 |
||
488 |
||
489 |
||
490 |
! ! |
|
491 |
||
487 | 492 |
!FileSelectionTree methodsFor:'initialization'! |
493 |
||
569 | 494 |
destroy |
495 |
||
573 | 496 |
triggerMonitorBlock notNil ifTrue:[ |
497 |
Processor removeTimedBlock:triggerMonitorBlock. |
|
498 |
triggerMonitorBlock := nil |
|
569 | 499 |
]. |
500 |
super destroy. |
|
501 |
||
502 |
! |
|
503 |
||
487 | 504 |
initialize |
505 |
"setup my model and set the default path to the current directory; on default |
|
506 |
multiple selection is disabled. |
|
507 |
" |
|
1173 | 508 |
itemClass := FileSelectionItem. |
509 |
||
487 | 510 |
super initialize. |
1173 | 511 |
|
512 |
itemClass := FileSelectionItem. |
|
569 | 513 |
monitoringDelayTime := self class monitoringDelayTime. |
1173 | 514 |
supportsExpandAll := false. |
513 | 515 |
! ! |
516 |
||
517 |
!FileSelectionTree methodsFor:'model'! |
|
518 |
||
519 |
rootFromModel |
|
520 |
"update hierarchical list from root model |
|
521 |
" |
|
522 |
|oldPath newPath| |
|
523 |
||
524 |
(newPath := rootHolder value) notNil ifTrue:[ |
|
525 |
newPath := newPath asString. |
|
526 |
]. |
|
527 |
||
528 |
self directory = newPath ifFalse:[ |
|
529 |
self changeDirectory:newPath |
|
530 |
] |
|
531 |
! |
|
532 |
||
533 |
selectionFromModel |
|
534 |
"set the selection derived from the selectionHolder |
|
535 |
" |
|
856 | 536 |
|selection value shown size coll| |
513 | 537 |
|
538 |
selectionHolder isNil ifTrue:[ |
|
539 |
^ self |
|
540 |
]. |
|
541 |
||
856 | 542 |
(value := selectionHolder value) isNil ifTrue:[ |
543 |
^ self deselect |
|
544 |
]. |
|
513 | 545 |
|
546 |
multipleSelectOk ifFalse:[ |
|
856 | 547 |
(value isKindOf:TreeItem) ifTrue:[ |
548 |
super selectionFromModel |
|
513 | 549 |
] ifFalse:[ |
550 |
value asFilename exists ifFalse:[ |
|
551 |
selectionHolder value:nil |
|
552 |
] ifTrue:[ |
|
553 |
self selectPathname:value |
|
554 |
] |
|
555 |
]. |
|
556 |
^ self |
|
557 |
]. |
|
558 |
||
856 | 559 |
value isEmpty ifTrue:[ |
513 | 560 |
^ self deselect |
561 |
]. |
|
562 |
||
856 | 563 |
(value first isKindOf:TreeItem) ifTrue:[ |
564 |
^ super selectionFromModel |
|
565 |
]. |
|
513 | 566 |
selection := value select:[:aPath| aPath asFilename exists ]. |
567 |
||
856 | 568 |
(size := selection size) ~~ value size ifTrue:[ |
569 |
size ~~ 0 ifTrue:[selectionHolder value:selection] |
|
570 |
ifFalse:[selectionHolder value:nil]. |
|
571 |
^ self |
|
513 | 572 |
]. |
856 | 573 |
selection := selection collect:[:aPath| self fileName2node:aPath ]. |
574 |
model doMakeVisible:selection. |
|
575 |
selection := selection collect:[:el| listOfNodes identityIndexOf:el ]. |
|
513 | 576 |
super selection:selection. |
577 |
! |
|
578 |
||
579 |
selectionToModel |
|
580 |
"write selection to selection holder |
|
581 |
" |
|
582 |
|old new| |
|
583 |
||
584 |
old := selectionHolder value. |
|
585 |
||
586 |
multipleSelectOk ifFalse:[ |
|
587 |
(new := self pathnameAtIndex:selection) = old ifFalse:[ |
|
1143 | 588 |
"/ selectionHolder value:new. |
589 |
selectionHolder value:new withoutNotifying:self. |
|
513 | 590 |
] |
591 |
] ifTrue:[ |
|
592 |
self numberOfSelections == 0 ifTrue:[ |
|
593 |
old size ~~ 0 ifTrue:[ |
|
594 |
selectionHolder value:nil |
|
595 |
] |
|
596 |
] ifFalse:[ |
|
597 |
new := selection collect:[:i|(listOfNodes at:i) pathName]. |
|
598 |
||
599 |
new size ~~ old size ifTrue:[ |
|
600 |
selectionHolder value:new |
|
601 |
] ifFalse:[ |
|
602 |
new do:[:pN| |
|
603 |
(old findFirst:[:pO| pO = pN]) == 0 ifTrue:[ |
|
604 |
^ selectionHolder value:new |
|
605 |
] |
|
606 |
] |
|
607 |
] |
|
608 |
] |
|
609 |
] |
|
610 |
||
1143 | 611 |
"Modified: / 24.9.1998 / 19:25:55 / cg" |
513 | 612 |
! ! |
613 |
||
614 |
!FileSelectionTree methodsFor:'private'! |
|
615 |
||
856 | 616 |
fileName2node:aFile |
617 |
|root file p1 p2 t| |
|
618 |
||
619 |
( (root := model root) isNil |
|
620 |
or:[(file := self makeLegalFilename:aFile) isNil] |
|
621 |
) ifTrue:[ |
|
622 |
^ nil |
|
623 |
]. |
|
624 |
||
625 |
p1 := root pathName. |
|
626 |
p2 := file pathName. |
|
627 |
||
628 |
(p2 startsWith:p1) ifFalse:[ |
|
629 |
^ nil |
|
630 |
]. |
|
631 |
p1 := Filename components:p1. |
|
632 |
p2 := (Filename components:p2) copyFrom:(p1 size). |
|
633 |
||
1143 | 634 |
^ model |
635 |
detectItem:[:aNode :name | aNode name = name ] |
|
636 |
arguments:p2. |
|
637 |
||
638 |
"Modified: / 24.9.1998 / 18:22:44 / cg" |
|
856 | 639 |
! |
640 |
||
812 | 641 |
makeLegalFilename:aFile |
642 |
|filename separator sepSize pathName pthSize| |
|
643 |
||
1140 | 644 |
aFile isNil ifTrue:[ ^ nil ]. |
812 | 645 |
|
1140 | 646 |
"/ (filename := aFile asFilename) exists ifFalse:[ |
647 |
"/ ^ nil |
|
648 |
"/ ]. |
|
812 | 649 |
|
1140 | 650 |
(filename := aFile asFilename) exists ifTrue:[ |
651 |
filename isDirectory ifFalse:[ |
|
652 |
^ filename |
|
653 |
] |
|
812 | 654 |
]. |
1079
d793b0b568e1
use filenames makeLegalFilename (for win32)
Claus Gittinger <cg@exept.de>
parents:
856
diff
changeset
|
655 |
|
d793b0b568e1
use filenames makeLegalFilename (for win32)
Claus Gittinger <cg@exept.de>
parents:
856
diff
changeset
|
656 |
^ filename makeLegalFilename. |
d793b0b568e1
use filenames makeLegalFilename (for win32)
Claus Gittinger <cg@exept.de>
parents:
856
diff
changeset
|
657 |
|
1122
cd042d65d811
uncommented unused code in #makeLegalFilename:
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
658 |
"/ separator := Filename separator. |
cd042d65d811
uncommented unused code in #makeLegalFilename:
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
659 |
"/ pathName := filename pathName. |
cd042d65d811
uncommented unused code in #makeLegalFilename:
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
660 |
"/ |
cd042d65d811
uncommented unused code in #makeLegalFilename:
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
661 |
"/ (pathName endsWith:separator) ifFalse:[ |
cd042d65d811
uncommented unused code in #makeLegalFilename:
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
662 |
"/ ^ filename |
cd042d65d811
uncommented unused code in #makeLegalFilename:
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
663 |
"/ ]. |
cd042d65d811
uncommented unused code in #makeLegalFilename:
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
664 |
"/ sepSize := (separator size) max:1. |
cd042d65d811
uncommented unused code in #makeLegalFilename:
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
665 |
"/ pthSize := pathName size. |
cd042d65d811
uncommented unused code in #makeLegalFilename:
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
666 |
"/ |
cd042d65d811
uncommented unused code in #makeLegalFilename:
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
667 |
"/ pthSize == sepSize ifTrue:[ |
cd042d65d811
uncommented unused code in #makeLegalFilename:
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
668 |
"/ ^ filename |
cd042d65d811
uncommented unused code in #makeLegalFilename:
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
669 |
"/ ]. |
cd042d65d811
uncommented unused code in #makeLegalFilename:
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
670 |
"/ pathName := pathName copyFrom:1 to:(pthSize - sepSize). |
cd042d65d811
uncommented unused code in #makeLegalFilename:
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
671 |
"/ filename := pathName asFilename. |
cd042d65d811
uncommented unused code in #makeLegalFilename:
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
672 |
"/ |
cd042d65d811
uncommented unused code in #makeLegalFilename:
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
673 |
"/ filename isDirectory ifTrue:[ |
cd042d65d811
uncommented unused code in #makeLegalFilename:
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
674 |
"/ ^ filename |
cd042d65d811
uncommented unused code in #makeLegalFilename:
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
675 |
"/ ]. |
cd042d65d811
uncommented unused code in #makeLegalFilename:
Claus Gittinger <cg@exept.de>
parents:
1079
diff
changeset
|
676 |
"/ ^ aFile asFilename |
812 | 677 |
|
1140 | 678 |
"Modified: / 24.9.1998 / 12:41:29 / cg" |
812 | 679 |
! |
680 |
||
569 | 681 |
monitorCycle |
682 |
"run monitor cycle |
|
683 |
" |
|
684 |
|sz root sel new old| |
|
685 |
||
573 | 686 |
(root := model root) isNil ifFalse:[ |
687 |
root hasObsoleteNodes ifTrue:[ |
|
688 |
(root repairObsoleteNodes) ifTrue:[ |
|
689 |
sz := self numberOfSelections. |
|
690 |
||
691 |
sz ~~ 0 ifTrue:[ |
|
692 |
old := self selection. |
|
693 |
||
694 |
sz == 1 ifTrue:[ |
|
695 |
sel := self selectedNode |
|
696 |
] ifFalse:[ |
|
697 |
sel := OrderedCollection new. |
|
698 |
self selectionDo:[:i| sel add:(listOfNodes at:i) ]. |
|
699 |
]. |
|
700 |
selection := nil. |
|
701 |
]. |
|
702 |
selection := old. |
|
703 |
model root:root. |
|
704 |
||
705 |
sz ~~ 0 ifTrue:[ |
|
787 | 706 |
sz == 1 ifTrue:[ |
573 | 707 |
self selectNode:sel. |
708 |
] ifFalse:[ |
|
709 |
new := OrderedCollection new. |
|
710 |
||
711 |
sel do:[:n||i| |
|
712 |
(i := self indexOfNode:n) ~~ 0 ifTrue:[new add:i] |
|
713 |
]. |
|
714 |
self selection:new |
|
715 |
] |
|
716 |
]. |
|
717 |
] |
|
718 |
] |
|
569 | 719 |
]. |
720 |
||
573 | 721 |
Processor addTimedBlock:triggerMonitorBlock afterSeconds:(self monitoringDelayTime). |
569 | 722 |
|
487 | 723 |
! ! |
724 |
||
725 |
!FileSelectionTree methodsFor:'selection'! |
|
726 |
||
727 |
selectPathname:aPath |
|
728 |
"set selection to a path |
|
729 |
" |
|
856 | 730 |
self selectNode:(self fileName2node:aPath) |
731 |
! |
|
732 |
||
733 |
selectedNodeExpand:doExpand |
|
734 |
"collapse or expand selected node. |
|
735 |
Redefined to show a busy cursor while reading dirs" |
|
487 | 736 |
|
856 | 737 |
doExpand ifTrue:[ |
738 |
self withWaitCursorDo:[ |
|
739 |
super selectedNodeExpand:doExpand |
|
740 |
] |
|
741 |
] ifFalse:[ |
|
742 |
super selectedNodeExpand:doExpand |
|
743 |
] |
|
487 | 744 |
! |
745 |
||
746 |
selectedPathname |
|
747 |
"if there is a single selection, the full pathname of the selected |
|
748 |
entry will be returned otherwise nil |
|
749 |
" |
|
750 |
|node| |
|
751 |
||
752 |
(node := self selectedNode) notNil ifTrue:[ |
|
753 |
^ node pathName |
|
754 |
]. |
|
755 |
^ nil |
|
756 |
||
757 |
! ! |
|
758 |
||
759 |
!FileSelectionTree class methodsFor:'documentation'! |
|
760 |
||
761 |
version |
|
1233 | 762 |
^ '$Header: /cvs/stx/stx/libwidg2/FileSelectionTree.st,v 1.22 1999-03-07 13:30:12 cg Exp $' |
487 | 763 |
! ! |