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