author | penk |
Mon, 25 Mar 2002 11:08:27 +0100 | |
changeset 2087 | 7d3e66c0f7f3 |
parent 1818 | fe99c5c721e9 |
child 2400 | f41d9fcbdaae |
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 |
||
1818 | 15 |
"{ Package: 'stx:libwidg2' }" |
16 |
||
487 | 17 |
SelectionInTreeView subclass:#FileSelectionTree |
1173 | 18 |
instanceVariableNames:'triggerMonitorBlock monitoringDelayTime' |
487 | 19 |
classVariableNames:'' |
20 |
poolDictionaries:'' |
|
1233 | 21 |
category:'Views-Trees' |
487 | 22 |
! |
23 |
||
24 |
!FileSelectionTree class methodsFor:'documentation'! |
|
25 |
||
26 |
copyright |
|
27 |
" |
|
488 | 28 |
COPYRIGHT (c) 1997 by eXept Software AG |
487 | 29 |
All Rights Reserved |
30 |
||
31 |
This software is furnished under a license and may be used |
|
32 |
only in accordance with the terms of that license and with the |
|
33 |
inclusion of the above copyright notice. This software may not |
|
34 |
be provided or otherwise made available to, or used by, any |
|
35 |
other person. No title to or ownership of the software is |
|
36 |
hereby transferred. |
|
37 |
" |
|
38 |
||
39 |
||
40 |
! |
|
41 |
||
42 |
documentation |
|
43 |
" |
|
44 |
somewhat like a FileSelectionInList; but specialized for hierarchical (i.e. tree-like) |
|
45 |
lists and adds the functions to show/hide subtrees. |
|
46 |
Requires SelectionInTree as model and FileSelectionItem (or compatible) list entries. |
|
47 |
||
48 |
You can define your own TreeItem instead of useing the default class FileSelectionItem |
|
49 |
by seting the class through to #itemClass: |
|
50 |
||
51 |
[see also:] |
|
52 |
FileSelectionItem |
|
53 |
SelectionInTree |
|
54 |
SelectionInTreeView |
|
55 |
SelectionInListView |
|
56 |
||
57 |
[author:] |
|
58 |
Claus Atzkern |
|
59 |
" |
|
60 |
||
61 |
||
62 |
||
63 |
! |
|
64 |
||
65 |
examples |
|
66 |
" |
|
67 |
open a FileSelectionTree on current directory |
|
68 |
[exBegin] |
|
69 |
|top scr| |
|
70 |
||
71 |
top := StandardSystemView new label:'select'; extent:300@500. |
|
72 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
73 |
scr := scr scrolledView. |
|
74 |
||
812 | 75 |
scr directory:'/'. |
76 |
scr showDirectoryIndicator:true. |
|
77 |
scr showRoot:false. |
|
78 |
scr showLines:false. |
|
79 |
scr allowDrag:true. |
|
80 |
scr multipleSelectOk:true. |
|
487 | 81 |
|
82 |
top open |
|
83 |
[exEnd] |
|
84 |
||
85 |
||
513 | 86 |
open a FileSelectionTree useing a model |
87 |
[exBegin] |
|
88 |
|top scr model| |
|
89 |
||
90 |
top := StandardSystemView new label:'select'; extent:300@500. |
|
91 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
92 |
scr := scr scrolledView. |
|
93 |
model := (Filename currentDirectory asString) asValue. |
|
94 |
scr rootHolder:model. |
|
95 |
model inspect. |
|
96 |
||
97 |
scr action:[:anIndex| Transcript showCR:anIndex. |
|
98 |
Transcript showCR:scr selectedPathname. |
|
99 |
]. |
|
100 |
top open |
|
101 |
[exEnd] |
|
102 |
||
103 |
||
104 |
[exBegin] |
|
105 |
|top scr| |
|
106 |
||
107 |
top := StandardSystemView new label:'select'; extent:300@500. |
|
108 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
109 |
scr := scr scrolledView. |
|
110 |
||
111 |
scr directory:Filename currentDirectory. |
|
112 |
scr selectionHolder:nil asValue. |
|
113 |
scr selectionHolder inspect. |
|
114 |
scr multipleSelectOk:true. |
|
115 |
||
116 |
scr action:[:anIndex| Transcript showCR:anIndex. |
|
117 |
Transcript showCR:scr selectedPathname. |
|
118 |
]. |
|
119 |
top open |
|
120 |
[exEnd] |
|
121 |
||
122 |
||
487 | 123 |
|
124 |
open a FileSelectionTree on root path; show directory |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
125 |
indication (open/closed), no lines and not the root |
487 | 126 |
[exBegin] |
127 |
|top scr| |
|
128 |
||
129 |
top := StandardSystemView new label:'select'; extent:300@500. |
|
130 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
131 |
scr := scr scrolledView. |
|
132 |
scr showDirectoryIndicator:true. |
|
133 |
scr showLines:false. |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
134 |
scr showRoot:false. |
487 | 135 |
|
136 |
scr directory:'/'. |
|
137 |
||
138 |
scr action:[:anIndex| Transcript showCR:anIndex. |
|
139 |
Transcript showCR:scr selectedPathname. |
|
140 |
]. |
|
141 |
top open |
|
142 |
[exEnd] |
|
143 |
||
144 |
||
145 |
||
146 |
open a FileSelectionTree on root path; showing only files |
|
147 |
[exBegin] |
|
148 |
|top scr| |
|
149 |
||
150 |
top := StandardSystemView new label:'select'; extent:300@500. |
|
151 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
152 |
scr := scr scrolledView. |
|
787 | 153 |
scr itemClass:(FileSelectionItem filterClassForDirectoriesOnly). |
487 | 154 |
scr directory:'/'. |
155 |
||
156 |
scr action:[:anIndex| Transcript showCR:anIndex. |
|
157 |
Transcript showCR:scr selectedPathname. |
|
158 |
]. |
|
159 |
top open |
|
160 |
[exEnd] |
|
161 |
||
162 |
||
163 |
||
164 |
open a FileSelectionTree on a specified path |
|
165 |
[exBegin] |
|
166 |
|top scr| |
|
167 |
||
168 |
top := StandardSystemView new label:'select'; extent:300@500. |
|
169 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
170 |
scr := scr scrolledView. |
|
171 |
scr directory:'/'. |
|
172 |
scr showLines:false. |
|
173 |
scr action:[:anIndex| Transcript showCR:scr selectedPathname ]. |
|
174 |
scr doubleClickAction:[:anIndex| Transcript showCR:scr selectedPathname ]. |
|
175 |
top open |
|
176 |
[exEnd] |
|
177 |
||
178 |
||
179 |
||
180 |
open a FileSelectionTree on a specified path; show or hide |
|
181 |
lines on doubleClick on a file (not a directory) |
|
182 |
[exBegin] |
|
183 |
|top scr| |
|
184 |
||
185 |
top := StandardSystemView new label:'select'; extent:300@500. |
|
186 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
187 |
scr := scr scrolledView. |
|
188 |
scr directory:'/'. |
|
189 |
||
190 |
scr action:[:anIndex| Transcript showCR:anIndex. |
|
191 |
Transcript showCR:scr selectedPathname. |
|
192 |
]. |
|
193 |
scr doubleClickAction:[:anIndex| |
|
194 |
|fn| |
|
195 |
fn := scr selectedPathname asFilename. |
|
196 |
fn isDirectory ifFalse:[ |
|
197 |
scr showLines:(scr showLines not) |
|
198 |
] |
|
199 |
]. |
|
200 |
top open |
|
201 |
[exEnd] |
|
202 |
||
203 |
||
204 |
||
492 | 205 |
example associated with a FileSelectionList |
206 |
[exBegin] |
|
207 |
|top tree list field label| |
|
208 |
||
209 |
top := StandardSystemView new label:'select'; extent:600@600. |
|
210 |
tree := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(0.5 @ 1.0) in:top. |
|
211 |
list := HVScrollableView for:FileSelectionList origin:(0.5 @ 25) corner:(1.0 @ 1.0) in:top. |
|
212 |
label := Label origin:(0.5 @ 2) in:top. |
|
213 |
label label:'pattern:'. |
|
214 |
field := EditField origin:0.5@2 in:top. |
|
215 |
field leftInset:(label preferredExtent x) + 5. |
|
216 |
field width:1.0. |
|
217 |
field editValue:'*'. |
|
218 |
field crAction:[list pattern:field editValue]. |
|
219 |
||
220 |
tree := tree scrolledView. |
|
221 |
list := list scrolledView. |
|
222 |
list ignoreDirectories:true. |
|
223 |
list pattern:(field editValue). |
|
224 |
||
787 | 225 |
tree itemClass:(FileSelectionItem filterClassForDirectoriesOnly). |
492 | 226 |
tree directory:(Filename homeDirectory). |
227 |
tree showDirectoryIndicator:true. |
|
228 |
list directory:(tree directory). |
|
229 |
||
230 |
list action:[:index| Transcript showCR:'you selected: ' , list selectedPathname]. |
|
231 |
tree action:[:anIndex| |
|
232 |
list directory:(tree selectedPathname). |
|
233 |
]. |
|
234 |
top open |
|
235 |
[exEnd] |
|
236 |
||
237 |
||
238 |
||
487 | 239 |
a more complex example |
240 |
[exBegin] |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
241 |
|top listD listF field lbl inset| |
487 | 242 |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
243 |
top := StandardSystemView new label:'select'; extent:600@600. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
244 |
inset := 26. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
245 |
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
|
246 |
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
|
247 |
listD := listD scrolledView. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
248 |
listF := listF scrolledView. |
487 | 249 |
|
787 | 250 |
listD itemClass:(FileSelectionItem filterClassForDirectoriesOnly). |
251 |
listF itemClass:(FileSelectionItem filterClassForFilesOnly). |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
252 |
listD showDirectoryIndicator:true. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
253 |
listD showLines:false. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
254 |
listF showLines:false. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
255 |
listF showRoot:false. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
256 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
257 |
lbl := Label label:'directory:' in:top. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
258 |
lbl origin:5 @ ((inset - lbl preferredExtent y) // 2). |
487 | 259 |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
260 |
field := FilenameEditField in:top. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
261 |
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
|
262 |
field width:0.5. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
263 |
field rightInset:(field origin x + 4). |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
264 |
field directoriesOnly. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
265 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
266 |
field crAction:[|dir| |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
267 |
dir := field editValue asFilename. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
268 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
269 |
(dir isDirectory and:[listD directory ~= dir pathName]) ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
270 |
listD changeDirectory:dir |
487 | 271 |
] |
272 |
]. |
|
273 |
||
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
274 |
listF action:[:anIndex||file| |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
275 |
(file := listF selectedPathname) notNil ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
276 |
Transcript showCR:'selection: ', file |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
277 |
] |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
278 |
]. |
487 | 279 |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
280 |
listD directory:(Filename homeDirectory). |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
281 |
field editValue:listD directory. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
282 |
|
569 | 283 |
listD doubleClickAction:[:anIndex||path| |
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
284 |
path := listD selectedPathname. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
285 |
listF directory:path. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
286 |
path notNil ifTrue:[field editValue:path] |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
287 |
]. |
487 | 288 |
top open |
289 |
[exEnd] |
|
290 |
" |
|
291 |
||
812 | 292 |
|
569 | 293 |
! ! |
294 |
||
295 |
!FileSelectionTree class methodsFor:'constants'! |
|
296 |
||
297 |
monitoringDelayTime |
|
298 |
"default delay time of monitoring task in seconds |
|
299 |
" |
|
300 |
^ 2 |
|
487 | 301 |
! ! |
302 |
||
303 |
!FileSelectionTree methodsFor:'accessing'! |
|
304 |
||
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
305 |
changeDirectory:aPathname |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
306 |
"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
|
307 |
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
|
308 |
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
|
309 |
" |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
310 |
|oldSel child loc oldPath oldFile newFile newPath node idx| |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
311 |
|
812 | 312 |
newFile := self makeLegalFilename:aPathname. |
313 |
oldPath := self directory. |
|
314 |
||
1140 | 315 |
(newFile notNil |
316 |
and:[newFile isDirectory |
|
317 |
and:[oldPath notNil]]) ifFalse:[ |
|
812 | 318 |
^ self directory:newFile |
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
319 |
]. |
812 | 320 |
|
321 |
(newPath := newFile pathName) = oldPath ifTrue:[ |
|
322 |
^ self |
|
323 |
]. |
|
324 |
||
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
325 |
oldFile := oldPath asFilename. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
326 |
oldSel := self selectedNode. |
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 |
(newPath startsWith:oldPath) ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
329 |
node := self detectNode:[:aNode|aNode pathName = newPath]. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
330 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
331 |
node isNil ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
332 |
^ self directory:newFile |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
333 |
]. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
334 |
] ifFalse:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
335 |
(oldPath startsWith:newPath) ifFalse:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
336 |
^ self directory:newFile |
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 |
child := model root. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
339 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
340 |
[newPath = oldPath] whileFalse:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
341 |
oldFile := oldFile directory. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
342 |
node := self itemClass pathName:oldFile. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
343 |
node expand. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
344 |
loc := node children. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
345 |
idx := loc findFirst:[:el| el pathName = oldPath ]. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
346 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
347 |
idx == 0 ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
348 |
^ self directory:newFile |
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 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
351 |
loc at:idx put:child. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
352 |
child parent:node. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
353 |
child := node. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
354 |
oldPath := oldFile pathName. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
355 |
] |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
356 |
]. |
812 | 357 |
|
358 |
node children size == 0 ifTrue:[ |
|
359 |
oldSel := node. |
|
360 |
||
361 |
(node := node parent) isNil ifTrue:[ |
|
362 |
^ self directory:newFile |
|
363 |
] |
|
364 |
] ifFalse:[ |
|
365 |
node isExpandable ifTrue:[ |
|
366 |
^ self directory:newFile |
|
367 |
] |
|
368 |
]. |
|
369 |
||
370 |
selection := nil. |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
371 |
node parent:nil. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
372 |
model root:node. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
373 |
self setSelection:(self indexOfNode:oldSel). |
586 | 374 |
model removeDependent:self. |
375 |
model selection:selection. |
|
376 |
model addDependent:self. |
|
1140 | 377 |
|
378 |
"Modified: / 24.9.1998 / 13:00:09 / cg" |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
379 |
! |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
380 |
|
487 | 381 |
directory |
382 |
"get the full pathname of the root directory |
|
383 |
" |
|
384 |
|root| |
|
385 |
||
386 |
(root := model root) notNil ifTrue:[ |
|
387 |
^ root pathName |
|
388 |
]. |
|
389 |
^ nil |
|
390 |
! |
|
391 |
||
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
392 |
directory:aPath |
487 | 393 |
"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
|
394 |
aPath. The pathname must be a directory otherwise the root directory |
487 | 395 |
is set to nil. |
396 |
" |
|
1142 | 397 |
|root path isOK| |
492 | 398 |
|
586 | 399 |
model selection:(selection := nil). |
812 | 400 |
path := self makeLegalFilename:aPath. |
487 | 401 |
|
1140 | 402 |
(path notNil |
403 |
and:[path isDirectory |
|
404 |
and:[path isExecutable]]) ifTrue:[ |
|
1142 | 405 |
isOK := true. |
406 |
] ifFalse:[ |
|
407 |
"/ special for WIN32 / VMS |
|
408 |
isOK := path isVolumeAbsolute |
|
409 |
]. |
|
410 |
isOK ifTrue:[ |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
411 |
root := self itemClass pathName:path. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
412 |
model root:root. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
413 |
model expand:root. |
1140 | 414 |
] ifFalse:[ |
1142 | 415 |
model root:nil |
586 | 416 |
]. |
487 | 417 |
|
1142 | 418 |
"Modified: / 24.9.1998 / 17:43:11 / cg" |
487 | 419 |
! |
420 |
||
421 |
itemClass:anItemClass |
|
422 |
"set itemClass to be used |
|
423 |
" |
|
1173 | 424 |
|directory old new| |
487 | 425 |
|
1173 | 426 |
old := self itemClass. |
427 |
super itemClass:anItemClass. |
|
428 |
new := self itemClass. |
|
487 | 429 |
|
1173 | 430 |
(old ~~ new and:[new notNil and:[(directory := self directory) notNil]]) ifTrue:[ |
431 |
self directory:directory "/ recompute list |
|
487 | 432 |
]. |
433 |
||
492 | 434 |
! |
435 |
||
436 |
pathnameAtIndex:anIndex |
|
437 |
"returns pathname at an index or nil |
|
438 |
" |
|
439 |
|node| |
|
440 |
||
441 |
(node := self nodeAtIndex:anIndex) notNil ifTrue:[ |
|
442 |
^ node pathName |
|
443 |
]. |
|
444 |
^ nil |
|
487 | 445 |
! ! |
446 |
||
1818 | 447 |
!FileSelectionTree methodsFor:'accessing-monitoring'! |
569 | 448 |
|
449 |
monitoring |
|
450 |
"returns true if monitor process is running |
|
451 |
" |
|
573 | 452 |
^ triggerMonitorBlock notNil |
569 | 453 |
! |
454 |
||
455 |
monitoring:aState |
|
456 |
"enable or disable monitoring |
|
457 |
" |
|
458 |
aState ifTrue:[ |
|
573 | 459 |
triggerMonitorBlock notNil ifTrue:[^ self]. |
460 |
triggerMonitorBlock := [self sensor pushUserEvent:#monitorCycle for:self]. |
|
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| |
|
605 |
(old findFirst:[:pO| pO = pN]) == 0 ifTrue:[ |
|
606 |
^ selectionHolder value:new |
|
607 |
] |
|
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 |
|
621 |
( (root := model root) isNil |
|
622 |
or:[(file := self makeLegalFilename:aFile) isNil] |
|
623 |
) ifTrue:[ |
|
624 |
^ nil |
|
625 |
]. |
|
626 |
||
627 |
p1 := root pathName. |
|
628 |
p2 := file pathName. |
|
629 |
||
630 |
(p2 startsWith:p1) ifFalse:[ |
|
631 |
^ nil |
|
632 |
]. |
|
633 |
p1 := Filename components:p1. |
|
634 |
p2 := (Filename components:p2) copyFrom:(p1 size). |
|
635 |
||
1379
bc7f3700e933
care for caseless-filename-systems
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
636 |
Filename isCaseSensitive ifFalse:[ |
bc7f3700e933
care for caseless-filename-systems
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
637 |
^ model |
bc7f3700e933
care for caseless-filename-systems
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
638 |
detectItem:[:aNode :name | aNode name asLowercase = name asLowercase] |
bc7f3700e933
care for caseless-filename-systems
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
639 |
arguments:p2. |
bc7f3700e933
care for caseless-filename-systems
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
640 |
]. |
bc7f3700e933
care for caseless-filename-systems
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
641 |
|
1143 | 642 |
^ model |
643 |
detectItem:[:aNode :name | aNode name = name ] |
|
644 |
arguments:p2. |
|
645 |
||
1379
bc7f3700e933
care for caseless-filename-systems
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
646 |
"Modified: / 18.5.1999 / 19:30:19 / cg" |
856 | 647 |
! |
648 |
||
812 | 649 |
makeLegalFilename:aFile |
1269 | 650 |
|filename| |
812 | 651 |
|
1140 | 652 |
aFile isNil ifTrue:[ ^ nil ]. |
812 | 653 |
|
1140 | 654 |
(filename := aFile asFilename) exists ifTrue:[ |
655 |
filename isDirectory ifFalse:[ |
|
656 |
^ filename |
|
657 |
] |
|
812 | 658 |
]. |
1079
d793b0b568e1
use filenames makeLegalFilename (for win32)
Claus Gittinger <cg@exept.de>
parents:
856
diff
changeset
|
659 |
|
1269 | 660 |
^ filename makeLegalFilename. |
812 | 661 |
|
1140 | 662 |
"Modified: / 24.9.1998 / 12:41:29 / cg" |
812 | 663 |
! |
664 |
||
569 | 665 |
monitorCycle |
666 |
"run monitor cycle |
|
667 |
" |
|
668 |
|sz root sel new old| |
|
669 |
||
573 | 670 |
(root := model root) isNil ifFalse:[ |
671 |
root hasObsoleteNodes ifTrue:[ |
|
672 |
(root repairObsoleteNodes) ifTrue:[ |
|
673 |
sz := self numberOfSelections. |
|
674 |
||
675 |
sz ~~ 0 ifTrue:[ |
|
676 |
old := self selection. |
|
677 |
||
678 |
sz == 1 ifTrue:[ |
|
679 |
sel := self selectedNode |
|
680 |
] ifFalse:[ |
|
681 |
sel := OrderedCollection new. |
|
682 |
self selectionDo:[:i| sel add:(listOfNodes at:i) ]. |
|
683 |
]. |
|
684 |
selection := nil. |
|
685 |
]. |
|
686 |
selection := old. |
|
687 |
model root:root. |
|
688 |
||
689 |
sz ~~ 0 ifTrue:[ |
|
787 | 690 |
sz == 1 ifTrue:[ |
573 | 691 |
self selectNode:sel. |
692 |
] ifFalse:[ |
|
693 |
new := OrderedCollection new. |
|
694 |
||
695 |
sel do:[:n||i| |
|
696 |
(i := self indexOfNode:n) ~~ 0 ifTrue:[new add:i] |
|
697 |
]. |
|
698 |
self selection:new |
|
699 |
] |
|
700 |
]. |
|
701 |
] |
|
702 |
] |
|
569 | 703 |
]. |
704 |
||
573 | 705 |
Processor addTimedBlock:triggerMonitorBlock afterSeconds:(self monitoringDelayTime). |
569 | 706 |
|
487 | 707 |
! ! |
708 |
||
709 |
!FileSelectionTree methodsFor:'selection'! |
|
710 |
||
711 |
selectPathname:aPath |
|
712 |
"set selection to a path |
|
713 |
" |
|
856 | 714 |
self selectNode:(self fileName2node:aPath) |
715 |
! |
|
716 |
||
717 |
selectedNodeExpand:doExpand |
|
718 |
"collapse or expand selected node. |
|
719 |
Redefined to show a busy cursor while reading dirs" |
|
487 | 720 |
|
856 | 721 |
doExpand ifTrue:[ |
722 |
self withWaitCursorDo:[ |
|
723 |
super selectedNodeExpand:doExpand |
|
724 |
] |
|
725 |
] ifFalse:[ |
|
726 |
super selectedNodeExpand:doExpand |
|
727 |
] |
|
487 | 728 |
! |
729 |
||
730 |
selectedPathname |
|
731 |
"if there is a single selection, the full pathname of the selected |
|
732 |
entry will be returned otherwise nil |
|
733 |
" |
|
734 |
|node| |
|
735 |
||
736 |
(node := self selectedNode) notNil ifTrue:[ |
|
737 |
^ node pathName |
|
738 |
]. |
|
739 |
^ nil |
|
740 |
||
741 |
! ! |
|
742 |
||
743 |
!FileSelectionTree class methodsFor:'documentation'! |
|
744 |
||
745 |
version |
|
2087 | 746 |
^ '$Header: /cvs/stx/stx/libwidg2/FileSelectionTree.st,v 1.26 2002-03-25 10:08:27 penk Exp $' |
487 | 747 |
! ! |