author | ca |
Wed, 25 Feb 1998 15:56:07 +0100 | |
changeset 787 | bbd70842b40b |
parent 698 | 797dc717a3b9 |
child 791 | 59f9fa223b0e |
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 |
|
787 | 16 |
instanceVariableNames:'triggerMonitorBlock monitoringDelayTime itemClass' |
487 | 17 |
classVariableNames:'' |
18 |
poolDictionaries:'' |
|
19 |
category:'Views-Text' |
|
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 |
||
73 |
scr directory:Filename currentDirectory. |
|
74 |
||
75 |
scr action:[:anIndex| Transcript showCR:anIndex. |
|
76 |
Transcript showCR:scr selectedPathname. |
|
77 |
]. |
|
78 |
top open |
|
79 |
[exEnd] |
|
80 |
||
81 |
||
513 | 82 |
open a FileSelectionTree useing a model |
83 |
[exBegin] |
|
84 |
|top scr model| |
|
85 |
||
86 |
top := StandardSystemView new label:'select'; extent:300@500. |
|
87 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
88 |
scr := scr scrolledView. |
|
89 |
model := (Filename currentDirectory asString) asValue. |
|
90 |
scr rootHolder:model. |
|
91 |
model inspect. |
|
92 |
||
93 |
scr action:[:anIndex| Transcript showCR:anIndex. |
|
94 |
Transcript showCR:scr selectedPathname. |
|
95 |
]. |
|
96 |
top open |
|
97 |
[exEnd] |
|
98 |
||
99 |
||
100 |
[exBegin] |
|
101 |
|top scr| |
|
102 |
||
103 |
top := StandardSystemView new label:'select'; extent:300@500. |
|
104 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
105 |
scr := scr scrolledView. |
|
106 |
||
107 |
scr directory:Filename currentDirectory. |
|
108 |
scr selectionHolder:nil asValue. |
|
109 |
scr selectionHolder inspect. |
|
110 |
scr multipleSelectOk:true. |
|
111 |
||
112 |
scr action:[:anIndex| Transcript showCR:anIndex. |
|
113 |
Transcript showCR:scr selectedPathname. |
|
114 |
]. |
|
115 |
top open |
|
116 |
[exEnd] |
|
117 |
||
118 |
||
487 | 119 |
|
120 |
open a FileSelectionTree on root path; show directory |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
121 |
indication (open/closed), no lines and not the root |
487 | 122 |
[exBegin] |
123 |
|top scr| |
|
124 |
||
125 |
top := StandardSystemView new label:'select'; extent:300@500. |
|
126 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
127 |
scr := scr scrolledView. |
|
128 |
scr showDirectoryIndicator:true. |
|
129 |
scr showLines:false. |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
130 |
scr showRoot:false. |
487 | 131 |
|
132 |
scr directory:'/'. |
|
133 |
||
134 |
scr action:[:anIndex| Transcript showCR:anIndex. |
|
135 |
Transcript showCR:scr selectedPathname. |
|
136 |
]. |
|
137 |
top open |
|
138 |
[exEnd] |
|
139 |
||
140 |
||
141 |
||
142 |
open a FileSelectionTree on root path; showing only files |
|
143 |
[exBegin] |
|
144 |
|top scr| |
|
145 |
||
146 |
top := StandardSystemView new label:'select'; extent:300@500. |
|
147 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
148 |
scr := scr scrolledView. |
|
787 | 149 |
scr itemClass:(FileSelectionItem filterClassForDirectoriesOnly). |
487 | 150 |
scr directory:'/'. |
151 |
||
152 |
scr action:[:anIndex| Transcript showCR:anIndex. |
|
153 |
Transcript showCR:scr selectedPathname. |
|
154 |
]. |
|
155 |
top open |
|
156 |
[exEnd] |
|
157 |
||
158 |
||
159 |
||
160 |
open a FileSelectionTree on a specified path |
|
161 |
[exBegin] |
|
162 |
|top scr| |
|
163 |
||
164 |
top := StandardSystemView new label:'select'; extent:300@500. |
|
165 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
166 |
scr := scr scrolledView. |
|
167 |
scr directory:'/'. |
|
168 |
scr showLines:false. |
|
169 |
scr action:[:anIndex| Transcript showCR:scr selectedPathname ]. |
|
170 |
scr doubleClickAction:[:anIndex| Transcript showCR:scr selectedPathname ]. |
|
171 |
top open |
|
172 |
[exEnd] |
|
173 |
||
174 |
||
175 |
||
176 |
open a FileSelectionTree on a specified path; show or hide |
|
177 |
lines on doubleClick on a file (not a directory) |
|
178 |
[exBegin] |
|
179 |
|top scr| |
|
180 |
||
181 |
top := StandardSystemView new label:'select'; extent:300@500. |
|
182 |
scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
183 |
scr := scr scrolledView. |
|
184 |
scr directory:'/'. |
|
185 |
||
186 |
scr action:[:anIndex| Transcript showCR:anIndex. |
|
187 |
Transcript showCR:scr selectedPathname. |
|
188 |
]. |
|
189 |
scr doubleClickAction:[:anIndex| |
|
190 |
|fn| |
|
191 |
fn := scr selectedPathname asFilename. |
|
192 |
fn isDirectory ifFalse:[ |
|
193 |
scr showLines:(scr showLines not) |
|
194 |
] |
|
195 |
]. |
|
196 |
top open |
|
197 |
[exEnd] |
|
198 |
||
199 |
||
200 |
||
492 | 201 |
example associated with a FileSelectionList |
202 |
[exBegin] |
|
203 |
|top tree list field label| |
|
204 |
||
205 |
top := StandardSystemView new label:'select'; extent:600@600. |
|
206 |
tree := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(0.5 @ 1.0) in:top. |
|
207 |
list := HVScrollableView for:FileSelectionList origin:(0.5 @ 25) corner:(1.0 @ 1.0) in:top. |
|
208 |
label := Label origin:(0.5 @ 2) in:top. |
|
209 |
label label:'pattern:'. |
|
210 |
field := EditField origin:0.5@2 in:top. |
|
211 |
field leftInset:(label preferredExtent x) + 5. |
|
212 |
field width:1.0. |
|
213 |
field editValue:'*'. |
|
214 |
field crAction:[list pattern:field editValue]. |
|
215 |
||
216 |
tree := tree scrolledView. |
|
217 |
list := list scrolledView. |
|
218 |
list ignoreDirectories:true. |
|
219 |
list pattern:(field editValue). |
|
220 |
||
787 | 221 |
tree itemClass:(FileSelectionItem filterClassForDirectoriesOnly). |
492 | 222 |
tree directory:(Filename homeDirectory). |
223 |
tree showDirectoryIndicator:true. |
|
224 |
list directory:(tree directory). |
|
225 |
||
226 |
list action:[:index| Transcript showCR:'you selected: ' , list selectedPathname]. |
|
227 |
tree action:[:anIndex| |
|
228 |
list directory:(tree selectedPathname). |
|
229 |
]. |
|
230 |
top open |
|
231 |
[exEnd] |
|
232 |
||
233 |
||
234 |
||
487 | 235 |
a more complex example |
236 |
[exBegin] |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
237 |
|top listD listF field lbl inset| |
487 | 238 |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
239 |
top := StandardSystemView new label:'select'; extent:600@600. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
240 |
inset := 26. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
241 |
listD := HVScrollableView for:FileSelectionTree origin:(0.0 @ inset) corner:(0.5 @ 1.0) in:top. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
242 |
listF := HVScrollableView for:FileSelectionTree origin:(0.5 @ 0.0) corner:(1.0 @ 1.0) in:top. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
243 |
listD := listD scrolledView. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
244 |
listF := listF scrolledView. |
487 | 245 |
|
787 | 246 |
listD itemClass:(FileSelectionItem filterClassForDirectoriesOnly). |
247 |
listF itemClass:(FileSelectionItem filterClassForFilesOnly). |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
248 |
listD showDirectoryIndicator:true. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
249 |
listD showLines:false. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
250 |
listF showLines:false. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
251 |
listF showRoot:false. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
252 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
253 |
lbl := Label label:'directory:' in:top. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
254 |
lbl origin:5 @ ((inset - lbl preferredExtent y) // 2). |
487 | 255 |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
256 |
field := FilenameEditField in:top. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
257 |
field origin:(4 + lbl corner x) @ ((inset - field preferredExtent y) // 2). |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
258 |
field width:0.5. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
259 |
field rightInset:(field origin x + 4). |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
260 |
field directoriesOnly. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
261 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
262 |
field crAction:[|dir| |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
263 |
dir := field editValue asFilename. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
264 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
265 |
(dir isDirectory and:[listD directory ~= dir pathName]) ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
266 |
listD changeDirectory:dir |
487 | 267 |
] |
268 |
]. |
|
269 |
||
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
270 |
listF action:[:anIndex||file| |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
271 |
(file := listF selectedPathname) notNil ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
272 |
Transcript showCR:'selection: ', file |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
273 |
] |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
274 |
]. |
487 | 275 |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
276 |
listD directory:(Filename homeDirectory). |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
277 |
field editValue:listD directory. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
278 |
|
569 | 279 |
listD doubleClickAction:[:anIndex||path| |
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
280 |
path := listD selectedPathname. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
281 |
listF directory:path. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
282 |
path notNil ifTrue:[field editValue:path] |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
283 |
]. |
487 | 284 |
top open |
285 |
[exEnd] |
|
286 |
" |
|
287 |
||
569 | 288 |
! ! |
289 |
||
290 |
!FileSelectionTree class methodsFor:'constants'! |
|
291 |
||
292 |
monitoringDelayTime |
|
293 |
"default delay time of monitoring task in seconds |
|
294 |
" |
|
295 |
^ 2 |
|
487 | 296 |
! ! |
297 |
||
298 |
!FileSelectionTree methodsFor:'accessing'! |
|
299 |
||
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
300 |
changeDirectory:aPathname |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
301 |
"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
|
302 |
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
|
303 |
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
|
304 |
" |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
305 |
|oldSel child loc oldPath oldFile newFile newPath node idx| |
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 |
( aPathname notNil |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
308 |
and:[(newFile := aPathname asFilename) isDirectory |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
309 |
and:[(oldPath := self directory) notNil]] |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
310 |
) ifFalse:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
311 |
^ self directory:aPathname |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
312 |
]. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
313 |
newPath := newFile pathName. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
314 |
oldFile := oldPath asFilename. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
315 |
oldSel := self selectedNode. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
316 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
317 |
(newPath startsWith:oldPath) ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
318 |
node := self detectNode:[:aNode|aNode pathName = newPath]. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
319 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
320 |
node isNil ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
321 |
^ self directory:newFile |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
322 |
]. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
323 |
] ifFalse:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
324 |
(oldPath startsWith:newPath) ifFalse:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
325 |
^ self directory:newFile |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
326 |
]. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
327 |
child := model root. |
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 |
[newPath = oldPath] whileFalse:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
330 |
oldFile := oldFile directory. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
331 |
node := self itemClass pathName:oldFile. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
332 |
node expand. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
333 |
loc := node children. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
334 |
idx := loc findFirst:[:el| el pathName = oldPath ]. |
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 |
idx == 0 ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
337 |
^ self directory:newFile |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
338 |
]. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
339 |
|
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
340 |
loc at:idx put:child. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
341 |
child parent:node. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
342 |
child := node. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
343 |
oldPath := oldFile pathName. |
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 |
]. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
346 |
selection := nil. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
347 |
node parent:nil. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
348 |
model root:node. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
349 |
self setSelection:(self indexOfNode:oldSel). |
586 | 350 |
model removeDependent:self. |
351 |
model selection:selection. |
|
352 |
model addDependent:self. |
|
495
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 |
|
487 | 355 |
directory |
356 |
"get the full pathname of the root directory |
|
357 |
" |
|
358 |
|root| |
|
359 |
||
360 |
(root := model root) notNil ifTrue:[ |
|
361 |
^ root pathName |
|
362 |
]. |
|
363 |
^ nil |
|
364 |
! |
|
365 |
||
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
366 |
directory:aPath |
487 | 367 |
"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
|
368 |
aPath. The pathname must be a directory otherwise the root directory |
487 | 369 |
is set to nil. |
370 |
" |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
371 |
|root path| |
492 | 372 |
|
586 | 373 |
model selection:(selection := nil). |
487 | 374 |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
375 |
(aPath notNil and:[(path := aPath asFilename) isDirectory]) ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
376 |
root := self itemClass pathName:path. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
377 |
model root:root. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
378 |
model expand:root. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
379 |
] ifFalse:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
380 |
model root:nil. |
586 | 381 |
]. |
487 | 382 |
|
383 |
! |
|
384 |
||
385 |
itemClass |
|
386 |
"returns current itemClass used |
|
387 |
" |
|
388 |
^ itemClass |
|
389 |
! |
|
390 |
||
391 |
itemClass:anItemClass |
|
392 |
"set itemClass to be used |
|
393 |
" |
|
394 |
|directory| |
|
395 |
||
396 |
(anItemClass notNil and:[anItemClass ~~ itemClass]) ifTrue:[ |
|
397 |
itemClass := anItemClass. |
|
547 | 398 |
computeResources := true. |
487 | 399 |
self refetchDeviceResources. |
400 |
||
401 |
(directory := self directory) notNil ifTrue:[ |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
402 |
self directory:directory "/ recompute list |
487 | 403 |
]. |
404 |
]. |
|
405 |
||
492 | 406 |
! |
407 |
||
408 |
pathnameAtIndex:anIndex |
|
409 |
"returns pathname at an index or nil |
|
410 |
" |
|
411 |
|node| |
|
412 |
||
413 |
(node := self nodeAtIndex:anIndex) notNil ifTrue:[ |
|
414 |
^ node pathName |
|
415 |
]. |
|
416 |
^ nil |
|
487 | 417 |
! ! |
418 |
||
569 | 419 |
!FileSelectionTree methodsFor:'accessing monitoring'! |
420 |
||
421 |
monitoring |
|
422 |
"returns true if monitor process is running |
|
423 |
" |
|
573 | 424 |
^ triggerMonitorBlock notNil |
569 | 425 |
! |
426 |
||
427 |
monitoring:aState |
|
428 |
"enable or disable monitoring |
|
429 |
" |
|
430 |
aState ifTrue:[ |
|
573 | 431 |
triggerMonitorBlock notNil ifTrue:[^ self]. |
432 |
triggerMonitorBlock := [self sensor pushUserEvent:#monitorCycle for:self]. |
|
433 |
Processor addTimedBlock:triggerMonitorBlock afterSeconds:(self monitoringDelayTime). |
|
569 | 434 |
] ifFalse:[ |
573 | 435 |
triggerMonitorBlock isNil ifTrue:[^ self]. |
436 |
Processor removeTimedBlock:triggerMonitorBlock. |
|
437 |
triggerMonitorBlock := nil. |
|
569 | 438 |
]. |
439 |
! |
|
440 |
||
441 |
monitoringDelayTime |
|
442 |
"delay time of monitoring task in seconds |
|
443 |
" |
|
444 |
^ monitoringDelayTime |
|
445 |
! |
|
446 |
||
447 |
monitoringDelayTime:seconds |
|
448 |
"delay time of monitoring task in seconds |
|
449 |
" |
|
450 |
seconds > 0 ifTrue:[ |
|
451 |
monitoringDelayTime := seconds |
|
452 |
] |
|
453 |
! ! |
|
454 |
||
487 | 455 |
!FileSelectionTree methodsFor:'initialization'! |
456 |
||
569 | 457 |
destroy |
458 |
||
573 | 459 |
triggerMonitorBlock notNil ifTrue:[ |
460 |
Processor removeTimedBlock:triggerMonitorBlock. |
|
461 |
triggerMonitorBlock := nil |
|
569 | 462 |
]. |
463 |
super destroy. |
|
464 |
||
465 |
! |
|
466 |
||
787 | 467 |
fetchDefaultImages |
468 |
"returns a directory with default keys and images |
|
487 | 469 |
" |
787 | 470 |
^ self itemClass keysAndIcons. |
487 | 471 |
! |
472 |
||
473 |
initialize |
|
474 |
"setup my model and set the default path to the current directory; on default |
|
475 |
multiple selection is disabled. |
|
476 |
" |
|
477 |
super initialize. |
|
478 |
itemClass := FileSelectionItem. |
|
569 | 479 |
monitoringDelayTime := self class monitoringDelayTime. |
513 | 480 |
! ! |
481 |
||
482 |
!FileSelectionTree methodsFor:'model'! |
|
483 |
||
484 |
rootFromModel |
|
485 |
"update hierarchical list from root model |
|
486 |
" |
|
487 |
|oldPath newPath| |
|
488 |
||
489 |
(newPath := rootHolder value) notNil ifTrue:[ |
|
490 |
newPath := newPath asString. |
|
491 |
]. |
|
492 |
||
493 |
self directory = newPath ifFalse:[ |
|
494 |
self changeDirectory:newPath |
|
495 |
] |
|
496 |
! |
|
497 |
||
498 |
selectionFromModel |
|
499 |
"set the selection derived from the selectionHolder |
|
500 |
" |
|
501 |
|selection value shown| |
|
502 |
||
503 |
selectionHolder isNil ifTrue:[ |
|
504 |
^ self |
|
505 |
]. |
|
506 |
||
507 |
value := selectionHolder value. |
|
508 |
||
509 |
multipleSelectOk ifFalse:[ |
|
510 |
value isNil ifTrue:[ |
|
511 |
self deselect |
|
512 |
] ifFalse:[ |
|
513 |
value asFilename exists ifFalse:[ |
|
514 |
selectionHolder value:nil |
|
515 |
] ifTrue:[ |
|
516 |
self selectPathname:value |
|
517 |
] |
|
518 |
]. |
|
519 |
^ self |
|
520 |
]. |
|
521 |
||
522 |
value size == 0 ifTrue:[ |
|
523 |
^ self deselect |
|
524 |
]. |
|
525 |
||
526 |
selection := value select:[:aPath| aPath asFilename exists ]. |
|
527 |
||
528 |
selection size ~~ value size ifTrue:[ |
|
529 |
selection size ~~ 0 ifTrue:[selectionHolder value:selection] |
|
530 |
ifFalse:[selectionHolder value:nil]. |
|
531 |
^ self |
|
532 |
]. |
|
533 |
||
534 |
selection size == 1 ifTrue:[ |
|
535 |
^ self selectPathname:(selection first) |
|
536 |
]. |
|
537 |
shown := true. |
|
538 |
||
539 |
selection do:[:el|(self showFile:el) ifFalse:[shown := false]]. |
|
540 |
||
541 |
shown ifFalse:[ |
|
542 |
model recomputeList. |
|
543 |
]. |
|
544 |
||
545 |
selection := selection collect:[:el| |
|
546 |
listOfNodes findFirst:[:n| n pathName = el] |
|
547 |
]. |
|
548 |
super selection:selection. |
|
487 | 549 |
|
513 | 550 |
! |
551 |
||
552 |
selectionToModel |
|
553 |
"write selection to selection holder |
|
554 |
" |
|
555 |
|old new| |
|
556 |
||
557 |
old := selectionHolder value. |
|
558 |
||
559 |
multipleSelectOk ifFalse:[ |
|
560 |
(new := self pathnameAtIndex:selection) = old ifFalse:[ |
|
561 |
selectionHolder value:new |
|
562 |
] |
|
563 |
] ifTrue:[ |
|
564 |
self numberOfSelections == 0 ifTrue:[ |
|
565 |
old size ~~ 0 ifTrue:[ |
|
566 |
selectionHolder value:nil |
|
567 |
] |
|
568 |
] ifFalse:[ |
|
569 |
new := selection collect:[:i|(listOfNodes at:i) pathName]. |
|
570 |
||
571 |
new size ~~ old size ifTrue:[ |
|
572 |
selectionHolder value:new |
|
573 |
] ifFalse:[ |
|
574 |
new do:[:pN| |
|
575 |
(old findFirst:[:pO| pO = pN]) == 0 ifTrue:[ |
|
576 |
^ selectionHolder value:new |
|
577 |
] |
|
578 |
] |
|
579 |
] |
|
580 |
] |
|
581 |
] |
|
582 |
||
583 |
! ! |
|
584 |
||
585 |
!FileSelectionTree methodsFor:'private'! |
|
586 |
||
569 | 587 |
monitorCycle |
588 |
"run monitor cycle |
|
589 |
" |
|
590 |
|sz root sel new old| |
|
591 |
||
573 | 592 |
(root := model root) isNil ifFalse:[ |
593 |
root hasObsoleteNodes ifTrue:[ |
|
594 |
(root repairObsoleteNodes) ifTrue:[ |
|
595 |
sz := self numberOfSelections. |
|
596 |
||
597 |
sz ~~ 0 ifTrue:[ |
|
598 |
old := self selection. |
|
599 |
||
600 |
sz == 1 ifTrue:[ |
|
601 |
sel := self selectedNode |
|
602 |
] ifFalse:[ |
|
603 |
sel := OrderedCollection new. |
|
604 |
self selectionDo:[:i| sel add:(listOfNodes at:i) ]. |
|
605 |
]. |
|
606 |
selection := nil. |
|
607 |
]. |
|
608 |
selection := old. |
|
609 |
model root:root. |
|
610 |
||
611 |
sz ~~ 0 ifTrue:[ |
|
787 | 612 |
sz == 1 ifTrue:[ |
573 | 613 |
self selectNode:sel. |
614 |
] ifFalse:[ |
|
615 |
new := OrderedCollection new. |
|
616 |
||
617 |
sel do:[:n||i| |
|
618 |
(i := self indexOfNode:n) ~~ 0 ifTrue:[new add:i] |
|
619 |
]. |
|
620 |
self selection:new |
|
621 |
] |
|
622 |
]. |
|
623 |
] |
|
624 |
] |
|
569 | 625 |
]. |
626 |
||
573 | 627 |
Processor addTimedBlock:triggerMonitorBlock afterSeconds:(self monitoringDelayTime). |
569 | 628 |
|
629 |
! |
|
630 |
||
513 | 631 |
showFile:aPathname |
632 |
"show a file |
|
633 |
" |
|
569 | 634 |
|components path size root node shown| |
513 | 635 |
|
636 |
path := aPathname asString. |
|
637 |
root := self directory. |
|
638 |
shown := true. |
|
639 |
||
640 |
(path startsWith:root) ifFalse:[ |
|
641 |
self error. |
|
642 |
^ shown |
|
643 |
]. |
|
569 | 644 |
size := root size. |
645 |
path size <= (size + 2) ifTrue:[^ shown]. |
|
646 |
size == 1 ifFalse:[path := path copyFrom:(size + 2)] |
|
647 |
ifTrue:[path := path copyFrom:2]. |
|
513 | 648 |
|
649 |
components := Filename components:path. |
|
650 |
node := model root. |
|
651 |
||
652 |
components do:[:el||next| |
|
653 |
next := node detectChild:[:e|e name = el]. |
|
654 |
next isNil ifTrue:[ |
|
655 |
self error. |
|
656 |
^ shown |
|
657 |
]. |
|
658 |
node hidden ifTrue:[ |
|
659 |
node expand. |
|
660 |
shown := false. |
|
661 |
]. |
|
662 |
node := next. |
|
663 |
]. |
|
664 |
^ shown |
|
487 | 665 |
! ! |
666 |
||
667 |
!FileSelectionTree methodsFor:'selection'! |
|
668 |
||
669 |
selectPathname:aPath |
|
670 |
"set selection to a path |
|
671 |
" |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
672 |
|components path| |
487 | 673 |
|
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
674 |
(aPath notNil and:[aPath asFilename exists]) ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
675 |
((path := aPath asString) = self selectedPathname) ifTrue:[ |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
676 |
^ self |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
677 |
]. |
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
678 |
components := Filename components:(path copyFrom:(self directory size + 1)). |
487 | 679 |
]. |
495
e34c13af578d
directory indication, path selection and change root path
ca
parents:
492
diff
changeset
|
680 |
self selectFromListOfNames:components. |
487 | 681 |
! |
682 |
||
683 |
selectedPathname |
|
684 |
"if there is a single selection, the full pathname of the selected |
|
685 |
entry will be returned otherwise nil |
|
686 |
" |
|
687 |
|node| |
|
688 |
||
689 |
(node := self selectedNode) notNil ifTrue:[ |
|
690 |
^ node pathName |
|
691 |
]. |
|
692 |
^ nil |
|
693 |
||
694 |
! ! |
|
695 |
||
696 |
!FileSelectionTree class methodsFor:'documentation'! |
|
697 |
||
698 |
version |
|
787 | 699 |
^ '$Header: /cvs/stx/stx/libwidg2/FileSelectionTree.st,v 1.11 1998-02-25 14:56:07 ca Exp $' |
487 | 700 |
! ! |