author | Claus Gittinger <cg@exept.de> |
Thu, 13 Feb 2003 21:53:21 +0100 | |
changeset 4557 | 8aa2be8c22bd |
parent 4534 | 60139c1a36e6 |
child 4577 | 52c443045ead |
permissions | -rw-r--r-- |
3892 | 1 |
"{ Package: 'stx:libtool' }" |
2 |
||
3 |
AbstractFileBrowser subclass:#DirectoryTreeBrowser |
|
4071 | 4 |
instanceVariableNames:'dirBrowser updateToExternFileHolderLock oldDropItem |
3995
8341aed594d2
Fix for single values and FileDialog
Stefan Vogel <sv@exept.de>
parents:
3989
diff
changeset
|
5 |
expandItemTimedBlock updateTreeSelection inDropMode canDropItem |
8341aed594d2
Fix for single values and FileDialog
Stefan Vogel <sv@exept.de>
parents:
3989
diff
changeset
|
6 |
doubleClickAction newVisibilityHolder allowFileOperations |
4151 | 7 |
multipleSelect treeSelectionHolder sortInTreeVisibilityHolder |
8 |
sortPropertyInTree sortCaselessInTreeBrowser' |
|
3995
8341aed594d2
Fix for single values and FileDialog
Stefan Vogel <sv@exept.de>
parents:
3989
diff
changeset
|
9 |
classVariableNames:'' |
8341aed594d2
Fix for single values and FileDialog
Stefan Vogel <sv@exept.de>
parents:
3989
diff
changeset
|
10 |
poolDictionaries:'' |
8341aed594d2
Fix for single values and FileDialog
Stefan Vogel <sv@exept.de>
parents:
3989
diff
changeset
|
11 |
category:'Interface-Tools-File' |
3892 | 12 |
! |
13 |
||
14 |
HierarchicalFileList subclass:#DirTreeBrowserHFL |
|
3995
8341aed594d2
Fix for single values and FileDialog
Stefan Vogel <sv@exept.de>
parents:
3989
diff
changeset
|
15 |
instanceVariableNames:'draggedItem grayDirectoryIcon' |
8341aed594d2
Fix for single values and FileDialog
Stefan Vogel <sv@exept.de>
parents:
3989
diff
changeset
|
16 |
classVariableNames:'' |
8341aed594d2
Fix for single values and FileDialog
Stefan Vogel <sv@exept.de>
parents:
3989
diff
changeset
|
17 |
poolDictionaries:'' |
8341aed594d2
Fix for single values and FileDialog
Stefan Vogel <sv@exept.de>
parents:
3989
diff
changeset
|
18 |
privateIn:DirectoryTreeBrowser |
3892 | 19 |
! |
20 |
||
21 |
!DirectoryTreeBrowser class methodsFor:'documentation'! |
|
22 |
||
23 |
documentation |
|
24 |
" |
|
25 |
documentation to be added. |
|
26 |
||
27 |
[author:] |
|
28 |
Christian Penk (penk@bierfix) |
|
29 |
||
30 |
[see also:] |
|
31 |
||
32 |
[instance variables:] |
|
33 |
||
34 |
[class variables:] |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
examples |
|
39 |
" |
|
40 |
Starting the application: |
|
41 |
[exBegin] |
|
42 |
DirectoryTreeBrowser open |
|
43 |
||
44 |
[exEnd] |
|
45 |
||
46 |
more examples to be added: |
|
47 |
[exBegin] |
|
48 |
... add code fragment for |
|
49 |
... executable example here ... |
|
50 |
[exEnd] |
|
51 |
" |
|
52 |
! ! |
|
53 |
||
54 |
!DirectoryTreeBrowser class methodsFor:'instance creation'! |
|
55 |
||
56 |
open |
|
57 |
||
58 |
^ super open |
|
59 |
" |
|
60 |
DirectoryTreeBrowser open |
|
61 |
" |
|
62 |
! |
|
63 |
||
64 |
openOn:aFileName |
|
65 |
||
66 |
| file | |
|
67 |
file := aFileName asFilename. |
|
68 |
file exists ifTrue:[ |
|
69 |
self openOn:aFileName withFiles:(file isDirectory not) |
|
70 |
] |
|
71 |
||
72 |
" |
|
73 |
DirectoryTreeBrowser openOn:Filename homeDirectory |
|
74 |
DirectoryTreeBrowser openOn:(Filename homeDirectory construct:'.bashrc') |
|
75 |
" |
|
76 |
! |
|
77 |
||
78 |
openOn:aFileName withFiles:aBoolean |
|
79 |
||
80 |
| instance| |
|
81 |
||
82 |
instance := DirectoryTreeBrowser new. |
|
83 |
instance open. |
|
84 |
instance viewFilesInDirectoryTree value:aBoolean. |
|
85 |
instance currentFileNameHolder value:(OrderedCollection with:aFileName). |
|
86 |
" |
|
87 |
DirectoryTreeBrowser openOn:Filename homeDirectory |
|
88 |
DirectoryTreeBrowser openOn:(Filename homeDirectory construct:'.bashrc') withFiles:false |
|
89 |
" |
|
90 |
! ! |
|
91 |
||
92 |
!DirectoryTreeBrowser class methodsFor:'defaults'! |
|
93 |
||
94 |
timeForExpandOnDropInMilliseconds |
|
95 |
||
96 |
^ 1500 |
|
97 |
! ! |
|
98 |
||
99 |
!DirectoryTreeBrowser class methodsFor:'interface specs'! |
|
100 |
||
101 |
windowSpec |
|
102 |
"This resource specification was automatically generated |
|
103 |
by the UIPainter of ST/X." |
|
104 |
||
105 |
"Do not manually edit this!! If it is corrupted, |
|
106 |
the UIPainter may not be able to read the specification." |
|
107 |
||
108 |
" |
|
109 |
UIPainter new openOnClass:DirectoryTreeBrowser andSelector:#windowSpec |
|
110 |
DirectoryTreeBrowser new openInterface:#windowSpec |
|
111 |
DirectoryTreeBrowser open |
|
112 |
" |
|
113 |
||
114 |
<resource: #canvas> |
|
115 |
||
116 |
^ |
|
117 |
#(#FullSpec |
|
118 |
#name: #windowSpec |
|
119 |
#window: |
|
120 |
#(#WindowSpec |
|
121 |
#label: 'DirectoryTreeBrowser' |
|
122 |
#name: 'DirectoryTreeBrowser' |
|
123 |
#min: #(#Point 10 10) |
|
124 |
#max: #(#Point 1024 768) |
|
125 |
#bounds: #(#Rectangle 16 42 316 342) |
|
126 |
#menu: #mainMenu |
|
127 |
) |
|
128 |
#component: |
|
129 |
#(#SpecCollection |
|
130 |
#collection: #( |
|
131 |
#(#HierarchicalListViewSpec |
|
132 |
#name: 'HierarchicalListView' |
|
133 |
#layout: #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0) |
|
134 |
#model: #treeSelectionHolder |
|
135 |
#menu: #menu |
|
136 |
#hasHorizontalScrollBar: true |
|
137 |
#hasVerticalScrollBar: true |
|
138 |
#miniScrollerHorizontal: false |
|
139 |
#miniScrollerVertical: false |
|
140 |
#listModel: #fileList |
|
141 |
#multipleSelectOk: true |
|
3982 | 142 |
#useIndex: false |
3906 | 143 |
#highlightMode: #label |
3892 | 144 |
#doubleClickSelector: #doDoubleClick: |
145 |
#indicatorSelector: #doIndicatorClick: |
|
146 |
#postBuildCallback: #postBuildDirBrowser: |
|
147 |
#properties: |
|
148 |
#(#PropertyListDictionary |
|
3982 | 149 |
#overSelector: #dropOver: |
3892 | 150 |
#dragArgument: #directoryTreeBrowser |
151 |
#startDragSelector: #doStartDrag:in: |
|
152 |
#displayObjectSelector: #getDisplayObjects: |
|
153 |
#dropObjectSelector: #getDropObjects: |
|
154 |
#dropArgument: #directoryTreeBrowser |
|
3952 | 155 |
#canDropSelector: #canDrop: |
3892 | 156 |
#leaveSelector: #dropLeave: |
3952 | 157 |
#enterSelector: #dropEnter: |
3982 | 158 |
#dropSelector: #doDrop: |
3892 | 159 |
) |
160 |
) |
|
161 |
) |
|
162 |
||
163 |
) |
|
164 |
) |
|
165 |
! ! |
|
166 |
||
167 |
!DirectoryTreeBrowser class methodsFor:'menu specs'! |
|
168 |
||
169 |
menu |
|
170 |
"This resource specification was automatically generated |
|
171 |
by the MenuEditor of ST/X." |
|
172 |
||
173 |
"Do not manually edit this!! If it is corrupted, |
|
174 |
the MenuEditor may not be able to read the specification." |
|
175 |
||
176 |
" |
|
177 |
MenuEditor new openOnClass:DirectoryTreeBrowser andSelector:#menu |
|
178 |
(Menu new fromLiteralArrayEncoding:(DirectoryTreeBrowser menu)) startUp |
|
179 |
" |
|
180 |
||
181 |
<resource: #menu> |
|
182 |
||
183 |
^ |
|
184 |
#(#Menu |
|
185 |
#( |
|
186 |
#(#MenuItem |
|
187 |
#label: 'Copy' |
|
4080 | 188 |
#itemValue: #doCopy |
3892 | 189 |
#translateLabel: true |
3956 | 190 |
#isVisible: #allowFileOperations |
4162 | 191 |
#shortcutKey: #Copy |
3892 | 192 |
) |
193 |
#(#MenuItem |
|
194 |
#label: 'Cut' |
|
4080 | 195 |
#itemValue: #doCut |
3892 | 196 |
#translateLabel: true |
3956 | 197 |
#isVisible: #allowFileOperations |
4162 | 198 |
#shortcutKey: #Cut |
3892 | 199 |
) |
200 |
#(#MenuItem |
|
4080 | 201 |
#enabled: #canPaste |
3892 | 202 |
#label: 'Paste' |
4080 | 203 |
#itemValue: #pasteFiles |
3892 | 204 |
#translateLabel: true |
3956 | 205 |
#isVisible: #allowFileOperations |
4162 | 206 |
#shortcutKey: #Paste |
3892 | 207 |
) |
208 |
#(#MenuItem |
|
209 |
#label: 'Delete' |
|
4080 | 210 |
#itemValue: #doDelete |
211 |
#nameKey: #delete |
|
3892 | 212 |
#translateLabel: true |
3956 | 213 |
#isVisible: #allowFileOperations |
4162 | 214 |
#shortcutKey: #Delete |
3892 | 215 |
) |
216 |
#(#MenuItem |
|
4383
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
217 |
#label: '-' |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
218 |
#isVisible: #allowFileOperations |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
219 |
) |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
220 |
#(#MenuItem |
4534 | 221 |
#label: 'New' |
222 |
#translateLabel: true |
|
223 |
#isVisible: #newVisibilityHolder |
|
224 |
#submenuChannel: #newMenu |
|
225 |
) |
|
226 |
#(#MenuItem |
|
227 |
#label: '-' |
|
228 |
#isVisible: #newVisibilityHolder |
|
229 |
) |
|
230 |
#(#MenuItem |
|
4383
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
231 |
#enabled: #hasSelection |
3907 | 232 |
#label: 'Rename' |
4080 | 233 |
#itemValue: #treeViewFileRename |
3907 | 234 |
#translateLabel: true |
3956 | 235 |
#isVisible: #allowFileOperations |
4162 | 236 |
#shortcutKey: #Rename |
3907 | 237 |
) |
238 |
#(#MenuItem |
|
4383
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
239 |
#enabled: #hasSelection |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
240 |
#label: 'Properties...' |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
241 |
#itemValue: #doShowProperties |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
242 |
#translateLabel: true |
3892 | 243 |
) |
244 |
#(#MenuItem |
|
4383
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
245 |
#label: '-' |
3892 | 246 |
) |
247 |
#(#MenuItem |
|
4534 | 248 |
#enabled: #enableDirectoryUp |
249 |
#label: 'Directory Up' |
|
250 |
#itemValue: #doGoDirectoryUp |
|
4080 | 251 |
#translateLabel: true |
4383
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
252 |
) |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
253 |
#(#MenuItem |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
254 |
#label: 'View' |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
255 |
#translateLabel: true |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
256 |
#submenu: |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
257 |
#(#Menu |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
258 |
#( |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
259 |
#(#MenuItem |
4410 | 260 |
#enabled: #sortInTreeVisibilityHolder |
4383
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
261 |
#label: 'Sort' |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
262 |
#nameKey: #Sort |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
263 |
#translateLabel: true |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
264 |
#submenuChannel: #sortInTreeMenu |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
265 |
) |
4410 | 266 |
#(#MenuItem |
267 |
#label: 'Show' |
|
268 |
#translateLabel: true |
|
269 |
#submenu: |
|
270 |
#(#Menu |
|
271 |
#( |
|
272 |
#(#MenuItem |
|
273 |
#label: 'Files' |
|
274 |
#translateLabel: true |
|
275 |
#indication: #viewFilesInDirectoryTree |
|
276 |
) |
|
277 |
) |
|
278 |
nil |
|
279 |
nil |
|
280 |
) |
|
281 |
) |
|
4534 | 282 |
#(#MenuItem |
283 |
#label: '-' |
|
284 |
) |
|
285 |
#(#MenuItem |
|
286 |
#enabled: #selectedFilesIncludesNonRootDirectory |
|
287 |
#label: 'Make Selected Directory new Root' |
|
288 |
#itemValue: #doSetSelectionToRoot |
|
289 |
#translateLabel: true |
|
290 |
) |
|
291 |
#(#MenuItem |
|
292 |
#label: 'Re-/ Expand Directory' |
|
293 |
#itemValue: #toggleExpandSelectedItem |
|
294 |
#translateLabel: true |
|
295 |
) |
|
4383
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
296 |
) |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
297 |
nil |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
298 |
nil |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
299 |
) |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
300 |
) |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
301 |
#(#MenuItem |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
302 |
#label: '-' |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
303 |
) |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
304 |
#(#MenuItem |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
305 |
#label: 'Update' |
4422 | 306 |
#itemValue: #updateCurrentDirectory |
4383
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
307 |
#translateLabel: true |
2fc564ad0f70
same menu order as on the right side
Claus Gittinger <cg@exept.de>
parents:
4333
diff
changeset
|
308 |
) |
3892 | 309 |
) |
310 |
nil |
|
311 |
nil |
|
312 |
) |
|
4151 | 313 |
! |
314 |
||
315 |
sortInTreeMenu |
|
316 |
"This resource specification was automatically generated |
|
317 |
by the MenuEditor of ST/X." |
|
318 |
||
319 |
"Do not manually edit this!! If it is corrupted, |
|
320 |
the MenuEditor may not be able to read the specification." |
|
321 |
||
322 |
" |
|
323 |
MenuEditor new openOnClass:DirectoryTreeBrowser andSelector:#sortInTreeMenu |
|
324 |
(Menu new fromLiteralArrayEncoding:(DirectoryTreeBrowser sortInTreeMenu)) startUp |
|
325 |
" |
|
326 |
||
327 |
<resource: #menu> |
|
328 |
||
329 |
^ |
|
330 |
#(#Menu |
|
331 |
#( |
|
332 |
#(#MenuItem |
|
333 |
#label: 'By Filename' |
|
334 |
#translateLabel: true |
|
335 |
#hideMenuOnActivated: false |
|
336 |
#choice: #sortPropertyInTree |
|
337 |
#choiceValue: #baseName |
|
338 |
) |
|
339 |
#(#MenuItem |
|
340 |
#label: 'By Type' |
|
341 |
#translateLabel: true |
|
342 |
#hideMenuOnActivated: false |
|
343 |
#choice: #sortPropertyInTree |
|
344 |
#choiceValue: #suffix |
|
345 |
) |
|
346 |
#(#MenuItem |
|
347 |
#label: 'By Size' |
|
348 |
#translateLabel: true |
|
349 |
#hideMenuOnActivated: false |
|
350 |
#choice: #sortPropertyInTree |
|
351 |
#choiceValue: #fileSize |
|
352 |
) |
|
353 |
#(#MenuItem |
|
354 |
#label: 'By Date && Time' |
|
355 |
#translateLabel: true |
|
356 |
#hideMenuOnActivated: false |
|
357 |
#choice: #sortPropertyInTree |
|
358 |
#choiceValue: #modificationTime |
|
359 |
) |
|
360 |
#(#MenuItem |
|
361 |
#label: '-' |
|
362 |
) |
|
363 |
#(#MenuItem |
|
364 |
#label: 'Ignore Case in Sort' |
|
365 |
#translateLabel: true |
|
366 |
#hideMenuOnActivated: false |
|
367 |
#indication: #sortCaselessInTreeBrowser |
|
368 |
) |
|
369 |
) |
|
370 |
nil |
|
371 |
nil |
|
372 |
) |
|
3892 | 373 |
! ! |
374 |
||
375 |
!DirectoryTreeBrowser class methodsFor:'plugIn spec'! |
|
376 |
||
377 |
aspectSelectors |
|
378 |
"This resource specification was automatically generated |
|
379 |
by the UIPainter of ST/X." |
|
380 |
||
381 |
"Do not manually edit this. If it is corrupted, |
|
382 |
the UIPainter may not be able to read the specification." |
|
383 |
||
384 |
"Return a description of exported aspects; |
|
385 |
these can be connected to aspects of an embedding application |
|
386 |
(if this app is embedded in a subCanvas)." |
|
387 |
||
388 |
^ #( |
|
389 |
#selectedDirectoryModel |
|
390 |
). |
|
391 |
||
392 |
! ! |
|
393 |
||
394 |
!DirectoryTreeBrowser methodsFor:'accessing'! |
|
395 |
||
3952 | 396 |
doubleClickAction |
397 |
||
398 |
^ doubleClickAction |
|
399 |
! |
|
400 |
||
401 |
doubleClickAction:aBlock |
|
402 |
||
403 |
" aBlock is a one arg block with selected index as argument " |
|
404 |
||
405 |
doubleClickAction := aBlock |
|
406 |
! |
|
407 |
||
3892 | 408 |
updateToExternFileHolderLock |
409 |
"return the value of the instance variable 'updateToExternFileHolder' (automatically generated)" |
|
410 |
||
411 |
updateToExternFileHolderLock isNil ifTrue:[ |
|
412 |
updateToExternFileHolderLock := self class newLock. |
|
413 |
]. |
|
414 |
^ updateToExternFileHolderLock |
|
415 |
! |
|
416 |
||
417 |
updateTreeSelection |
|
418 |
"return the value of the instance variable 'updateToExternFileHolder' (automatically generated)" |
|
419 |
||
420 |
updateTreeSelection isNil ifTrue:[ |
|
421 |
updateTreeSelection := self class newLock. |
|
422 |
]. |
|
423 |
^ updateTreeSelection |
|
424 |
! ! |
|
425 |
||
426 |
!DirectoryTreeBrowser methodsFor:'actions'! |
|
427 |
||
428 |
doDoubleClick:anIndex |
|
429 |
"handle a doubleClick on a directory |
|
430 |
" |
|
3952 | 431 |
| item file isDirectory| |
3892 | 432 |
|
3952 | 433 |
self doubleClickAction notNil ifTrue:[ |
434 |
self doubleClickAction value:anIndex. |
|
435 |
]. |
|
3892 | 436 |
item := self fileList at:anIndex ifAbsent:nil. |
437 |
item notNil ifTrue:[ |
|
438 |
isDirectory := item isDirectory. |
|
439 |
file := item fileName. |
|
440 |
isDirectory ifTrue:[ |
|
441 |
(file isReadable and:[file isExecutable]) ifTrue:[ |
|
442 |
self doExpand:item. |
|
443 |
] |
|
444 |
] ifFalse:[ |
|
3952 | 445 |
"/ self openApplByFileItem:item. |
3892 | 446 |
] |
447 |
] |
|
448 |
! |
|
449 |
||
450 |
doExpand:anItem |
|
451 |
" expand the item; return true the item have expanded " |
|
452 |
||
453 |
(anItem notNil and:[anItem isDirectory and:[anItem isExpanded not]]) ifTrue:[ |
|
454 |
anItem toggleExpand. |
|
455 |
^ true. |
|
456 |
]. |
|
457 |
^ false |
|
458 |
! |
|
459 |
||
460 |
doIndicatorClick:anIndex |
|
461 |
"handle a click on the indicator |
|
462 |
" |
|
463 |
||
464 |
|item| |
|
465 |
||
466 |
item := self fileList at:anIndex ifAbsent:nil. |
|
467 |
self toggleExpand:item |
|
468 |
! |
|
469 |
||
4010 | 470 |
doSetSelectionToRoot |
3982 | 471 |
| selDir| |
472 |
||
473 |
selDir := self firstSelectedDirectory. |
|
474 |
selDir notNil ifTrue:[ |
|
475 |
self rootHolder value asFilename = selDir ifTrue:[ ^ self]. |
|
476 |
self rootHolder value:selDir. |
|
477 |
self currentFileNameHolder value:(OrderedCollection with:selDir). |
|
478 |
]. |
|
479 |
! |
|
480 |
||
3892 | 481 |
doUpdate |
4422 | 482 |
"/ DirectoryContents flushCache. |
483 |
self fileList updateList. |
|
3892 | 484 |
"/ self updateSelectedItem |
485 |
! |
|
486 |
||
4151 | 487 |
evaluateSortBlockWith:aBlock |
3989 | 488 |
|
4085
9e58ddfa6969
sort will be triggered from the FileBrowserV2 instance not from AbstractFileBrowser anymore
penk
parents:
4080
diff
changeset
|
489 |
| sel model| |
9e58ddfa6969
sort will be triggered from the FileBrowserV2 instance not from AbstractFileBrowser anymore
penk
parents:
4080
diff
changeset
|
490 |
|
9e58ddfa6969
sort will be triggered from the FileBrowserV2 instance not from AbstractFileBrowser anymore
penk
parents:
4080
diff
changeset
|
491 |
model := self treeSelectionHolder. |
9e58ddfa6969
sort will be triggered from the FileBrowserV2 instance not from AbstractFileBrowser anymore
penk
parents:
4080
diff
changeset
|
492 |
sel := model value. |
9e58ddfa6969
sort will be triggered from the FileBrowserV2 instance not from AbstractFileBrowser anymore
penk
parents:
4080
diff
changeset
|
493 |
model setValue:nil. |
4151 | 494 |
self fileList sortBlock:aBlock. |
4085
9e58ddfa6969
sort will be triggered from the FileBrowserV2 instance not from AbstractFileBrowser anymore
penk
parents:
4080
diff
changeset
|
495 |
model value:sel withoutNotifying:self. |
3989 | 496 |
! |
497 |
||
3892 | 498 |
setMatchBlockForList:list |
499 |
||
4021 | 500 |
| selection matchBlock filterBlock viewFiles| |
3982 | 501 |
|
502 |
selection := self selectedItems. |
|
4011 | 503 |
filterBlock := self filterBlockHolder value. |
504 |
viewFiles := self viewFilesInDirectoryTree value. |
|
505 |
matchBlock := [:fileName :isDir| |
|
506 |
(isDir |
|
507 |
or:[viewFiles |
|
508 |
and:[filterBlock value:fileName baseName]]) |
|
3892 | 509 |
]. |
4011 | 510 |
list matchBlock:matchBlock. |
3892 | 511 |
! |
512 |
||
4151 | 513 |
sortFileListsBy:instanceName |
514 |
||
515 |
| aSymbol cmpOp instanceSortBlock treeSortBlock| |
|
516 |
||
517 |
aSymbol := instanceName asSymbol. |
|
518 |
cmpOp := #'<'. |
|
519 |
instanceSortBlock := [:a :b | |
|
520 |
|entry1 entry2| |
|
521 |
||
522 |
entry1 := (a perform:aSymbol). |
|
523 |
entry2 := (b perform:aSymbol). |
|
524 |
((entry1 isNil) or:[entry2 isNil]) ifTrue:[ |
|
525 |
true |
|
526 |
] ifFalse:[ |
|
527 |
(aSymbol = #baseName) ifTrue:[ |
|
528 |
self sortCaselessInTreeBrowser value ifTrue:[ |
|
529 |
entry1 := entry1 asString asLowercase. |
|
530 |
entry2 := entry2 asString asLowercase. |
|
531 |
] ifFalse:[ |
|
532 |
entry1 := entry1 asString. |
|
533 |
entry2 := entry2 asString. |
|
534 |
]. |
|
535 |
]. |
|
536 |
entry1 perform:cmpOp with:entry2 |
|
537 |
] |
|
538 |
]. |
|
539 |
treeSortBlock := [ :a :b | |
|
540 |
|aIsDir bIsDir res| |
|
541 |
||
542 |
aIsDir := a isDirectory. |
|
543 |
bIsDir := b isDirectory. |
|
544 |
(aIsDir and:[bIsDir]) ifTrue:[ |
|
545 |
| entry1 entry2 | |
|
546 |
entry1 := a baseName. |
|
547 |
entry2 := b baseName. |
|
548 |
res := entry1 < entry2. |
|
549 |
] ifFalse:[ |
|
550 |
(aIsDir or:[bIsDir]) ifTrue:[ |
|
551 |
res := aIsDir |
|
552 |
] ifFalse:[ |
|
553 |
res := instanceSortBlock value:a value:b. |
|
554 |
] |
|
555 |
]. |
|
556 |
res |
|
557 |
]. |
|
558 |
self evaluateSortBlockWith:treeSortBlock. |
|
559 |
! |
|
560 |
||
3892 | 561 |
toggleExpand:anItem |
562 |
||
563 |
(anItem notNil and:[anItem isDirectory]) ifTrue:[ |
|
564 |
anItem toggleExpand |
|
565 |
]. |
|
566 |
! |
|
567 |
||
3982 | 568 |
toggleExpandSelectedItem |
569 |
||
570 |
|selDir| |
|
571 |
||
572 |
selDir := self selectedDirectoryItems. |
|
573 |
selDir do:[:item| |
|
574 |
self toggleExpand:item. |
|
575 |
]. |
|
576 |
! |
|
577 |
||
3892 | 578 |
treeViewFileRename |
3982 | 579 |
|
3906 | 580 |
dirBrowser openEditor. |
3892 | 581 |
! |
582 |
||
583 |
updateSelectedItem |
|
584 |
||
585 |
| sel | |
|
586 |
||
3982 | 587 |
sel := self selectedItems. |
3892 | 588 |
sel isEmpty ifTrue:[ ^ self]. |
589 |
sel do:[:item| |
|
590 |
item invalidateRepairNow:true. |
|
591 |
] |
|
592 |
! ! |
|
593 |
||
594 |
!DirectoryTreeBrowser methodsFor:'aspects'! |
|
595 |
||
3956 | 596 |
allowFileOperations |
597 |
"allowFileOperations |
|
598 |
" |
|
599 |
allowFileOperations isNil ifTrue:[ |
|
600 |
allowFileOperations := true asValue. |
|
601 |
]. |
|
602 |
^ allowFileOperations. |
|
603 |
! |
|
604 |
||
3892 | 605 |
fileList |
606 |
"holder, which keeps the current list of file entries shown by the directory-browser |
|
607 |
" |
|
608 |
||
609 |
|list| |
|
610 |
||
611 |
(list := builder bindingAt:#fileList) isNil ifTrue:[ |
|
612 |
list := DirTreeBrowserHFL new. |
|
613 |
list application:self. |
|
614 |
list showRoot:true. |
|
615 |
self setMatchBlockForList:list. |
|
616 |
list directory:(self rootHolder value). |
|
617 |
builder aspectAt:#fileList put:list. |
|
618 |
list monitoringTaskDelay:2 |
|
619 |
]. |
|
620 |
^ list |
|
621 |
! |
|
622 |
||
3958 | 623 |
multipleSelect |
624 |
||
625 |
multipleSelect isNil ifTrue:[ |
|
626 |
multipleSelect := true. |
|
627 |
]. |
|
628 |
^ multipleSelect |
|
629 |
! |
|
630 |
||
631 |
multipleSelect:aBoolean |
|
632 |
||
633 |
multipleSelect := aBoolean. |
|
634 |
dirBrowser multipleSelectOk:aBoolean. |
|
635 |
! |
|
636 |
||
3956 | 637 |
newVisibilityHolder |
638 |
"newVisibilityHolder |
|
639 |
" |
|
640 |
newVisibilityHolder isNil ifTrue:[ |
|
641 |
newVisibilityHolder := true asValue. |
|
642 |
]. |
|
643 |
^ newVisibilityHolder. |
|
644 |
! |
|
645 |
||
4151 | 646 |
sortCaselessInTreeBrowser |
647 |
||
648 |
sortCaselessInTreeBrowser isNil ifTrue:[ |
|
649 |
sortCaselessInTreeBrowser := (Filename isCaseSensitive not) asValue. |
|
650 |
sortCaselessInTreeBrowser addDependent:self. |
|
651 |
]. |
|
652 |
^ sortCaselessInTreeBrowser. |
|
653 |
! |
|
654 |
||
655 |
sortInTreeVisibilityHolder |
|
656 |
"newVisibilityHolder |
|
657 |
" |
|
658 |
sortInTreeVisibilityHolder isNil ifTrue:[ |
|
659 |
sortInTreeVisibilityHolder := self viewFilesInDirectoryTree value asValue. |
|
660 |
]. |
|
661 |
^ sortInTreeVisibilityHolder. |
|
662 |
! |
|
663 |
||
664 |
sortPropertyInTree |
|
665 |
||
666 |
sortPropertyInTree isNil ifTrue:[ |
|
667 |
sortPropertyInTree := #baseName asValue. |
|
668 |
sortPropertyInTree addDependent:self. |
|
669 |
]. |
|
670 |
^ sortPropertyInTree. |
|
671 |
! |
|
672 |
||
3982 | 673 |
treeSelectionHolder |
674 |
||
675 |
treeSelectionHolder isNil ifTrue:[ |
|
676 |
treeSelectionHolder := ValueHolder new. |
|
677 |
treeSelectionHolder addDependent:self. |
|
678 |
]. |
|
679 |
^ treeSelectionHolder |
|
3892 | 680 |
! ! |
681 |
||
682 |
!DirectoryTreeBrowser methodsFor:'change & update'! |
|
683 |
||
3982 | 684 |
changeMatchBlock |
685 |
||
686 |
|list| |
|
687 |
||
688 |
list := self fileList. |
|
4021 | 689 |
self setMatchBlockForList:list. |
690 |
self currentFileNameHolderChanged. |
|
3982 | 691 |
! |
3892 | 692 |
|
3982 | 693 |
currentFileNameHolderChanged |
694 |
||
695 |
| selectFiles viewFiles| |
|
3892 | 696 |
|
3982 | 697 |
viewFiles:= self viewFilesInDirectoryTree value. |
698 |
viewFiles ifTrue:[ |
|
699 |
selectFiles := self currentFileNameHolder value. |
|
700 |
] ifFalse:[ |
|
701 |
selectFiles := self currentDirectories value. |
|
702 |
]. |
|
4018 | 703 |
self rootHolder notNil ifTrue:[ |
3982 | 704 |
self selectFiles:selectFiles. |
4333 | 705 |
self selectedItems do:[:item| |
706 |
(item isDirectory and:[item isExpanded not]) ifTrue:[ |
|
707 |
item expand. |
|
708 |
] |
|
709 |
]. |
|
710 |
^ self |
|
3982 | 711 |
]. |
712 |
! |
|
713 |
||
4011 | 714 |
rootHolderChanged |
715 |
||
716 |
|list file rootHolder| |
|
717 |
list := self fileList. |
|
718 |
rootHolder := self rootHolder. |
|
719 |
file := rootHolder value. |
|
720 |
file notNil ifTrue:[ |
|
721 |
file := Filename named:(file asString). |
|
722 |
file isDirectory ifTrue:[ |
|
723 |
list directory:file |
|
724 |
] |
|
725 |
]. |
|
4071 | 726 |
self rootHolder value:(list directory asString) withoutNotifying:self. |
4011 | 727 |
! |
728 |
||
3982 | 729 |
selectionChanged |
730 |
||
3995
8341aed594d2
Fix for single values and FileDialog
Stefan Vogel <sv@exept.de>
parents:
3989
diff
changeset
|
731 |
|sel currentFileDir| |
3982 | 732 |
|
3995
8341aed594d2
Fix for single values and FileDialog
Stefan Vogel <sv@exept.de>
parents:
3989
diff
changeset
|
733 |
" if viewFiles is false i can't take my |
8341aed594d2
Fix for single values and FileDialog
Stefan Vogel <sv@exept.de>
parents:
3989
diff
changeset
|
734 |
selection to overwrite currentFileNameHolder" |
8341aed594d2
Fix for single values and FileDialog
Stefan Vogel <sv@exept.de>
parents:
3989
diff
changeset
|
735 |
|
3982 | 736 |
sel := self selectedFiles. |
737 |
(self viewFilesInDirectoryTree value not) ifTrue:[ |
|
3892 | 738 |
(self currentFilesAreInSameDirectory and:[sel size == 1]) ifTrue:[ |
739 |
currentFileDir := self getDirWithoutFileName:(self currentFileNameHolder value first). |
|
740 |
(sel first = currentFileDir) ifTrue:[ |
|
741 |
^ self. |
|
742 |
]. |
|
743 |
]. |
|
744 |
]. |
|
745 |
self currentFileNameHolder value:sel. |
|
746 |
! |
|
747 |
||
748 |
update:something with:aParameter from:aModel |
|
749 |
"one of my models changed |
|
750 |
" |
|
751 |
||
752 |
||
3982 | 753 |
" the execution of selectionChanged and currentFileNameHolderChanged must |
3892 | 754 |
lock against each other because values dont must be the same (e.g. no files |
755 |
in tree view) |
|
756 |
" |
|
757 |
||
758 |
aModel == self currentFileNameHolder ifTrue:[ |
|
4003 | 759 |
super update:something with:aParameter from:aModel. |
3892 | 760 |
self updateTreeSelection doIfUnLocked:[ |
761 |
self updateToExternFileHolderLock doLocked:[ |
|
3982 | 762 |
self currentFileNameHolderChanged. |
3892 | 763 |
]. |
764 |
]. |
|
4003 | 765 |
^ self. |
3892 | 766 |
]. |
767 |
aModel == self treeSelectionHolder ifTrue:[ |
|
768 |
self updateToExternFileHolderLock doIfUnLocked:[ |
|
769 |
self updateTreeSelection doLocked:[ |
|
3982 | 770 |
self selectionChanged. |
3892 | 771 |
] |
772 |
]. |
|
773 |
^ self |
|
774 |
]. |
|
3982 | 775 |
aModel == self rootHolder ifTrue:[ |
4011 | 776 |
self rootHolderChanged. |
3892 | 777 |
^ self. |
778 |
]. |
|
779 |
aModel == self viewFilesInDirectoryTree ifTrue:[ |
|
4151 | 780 |
self sortInTreeVisibilityHolder value:(aModel value). |
3982 | 781 |
self updateToExternFileHolderLock doLocked:[ |
782 |
self changeMatchBlock. |
|
3892 | 783 |
]. |
784 |
^ self. |
|
785 |
]. |
|
4151 | 786 |
aModel == self sortPropertyInTree ifTrue:[ |
787 |
self sortFileListsBy:aModel value. |
|
3989 | 788 |
^ self. |
4151 | 789 |
]. |
790 |
aModel == self sortCaselessInTreeBrowser ifTrue:[ |
|
791 |
self sortPropertyInTree setValue:#baseName. |
|
792 |
self sortPropertyInTree changed. |
|
793 |
]. |
|
4011 | 794 |
aModel == self filterBlockHolder ifTrue:[ |
3982 | 795 |
" filter goes only on fileNames not on directories |
796 |
have to change the matchBlock only if files are shown" |
|
797 |
self viewFilesInDirectoryTree value ifTrue:[ |
|
4018 | 798 |
self changeMatchBlock. |
3982 | 799 |
]. |
800 |
^ self |
|
3892 | 801 |
]. |
802 |
super update:something with:aParameter from:aModel. |
|
803 |
^ self |
|
804 |
! ! |
|
805 |
||
806 |
!DirectoryTreeBrowser methodsFor:'drag & drop'! |
|
807 |
||
3952 | 808 |
canDrop:aContext |
3892 | 809 |
|
3952 | 810 |
^ canDropItem |
3892 | 811 |
! |
812 |
||
813 |
doDrop:aContext |
|
3952 | 814 |
|col destination destinationPath receiver| |
3892 | 815 |
|
3952 | 816 |
destination := self fileList draggedItem. |
817 |
self dropLeave:aContext. |
|
818 |
destination ifNil:[^ false]. |
|
819 |
||
3892 | 820 |
destinationPath := destination fileName. |
3952 | 821 |
|
822 |
aContext dropSource argument == #archivApplication ifTrue:[ |
|
823 |
receiver := aContext dropSource receiver. |
|
3892 | 824 |
receiver extractSelectedFilesTo:destinationPath askForExtractOptions:true. |
825 |
^ true |
|
826 |
]. |
|
827 |
col := OrderedCollection new. |
|
828 |
aContext dropObjects do:[:obj | |
|
829 |
col add:(obj theObject) |
|
830 |
]. |
|
3952 | 831 |
self copyOrMoveFiles:col to:destinationPath. |
3892 | 832 |
^ true |
833 |
! |
|
834 |
||
3952 | 835 |
dropEnter:aContext |
836 |
||
837 |
|dropedObjects| |
|
3892 | 838 |
|
3952 | 839 |
self dropTargetItemChangedTo:nil in:aContext. |
840 |
inDropMode := false. |
|
841 |
||
842 |
dropedObjects := aContext dropObjects. |
|
3892 | 843 |
|
3952 | 844 |
dropedObjects do:[:aObject| |checkObject checkObjectString| |
845 |
aObject isFileObject ifFalse:[^ self]. |
|
846 |
checkObject := aObject theObject. |
|
847 |
checkObject isFilename not ifTrue:[^ self]. |
|
848 |
((aContext dropSource argument == #archivApplication) not) ifTrue:[ |
|
849 |
checkObject isSpecialFile ifTrue:[^ self]. |
|
850 |
checkObject isReadable ifFalse:[^ self]. |
|
851 |
]. |
|
852 |
]. |
|
853 |
inDropMode := true. |
|
3892 | 854 |
! |
855 |
||
856 |
dropLeave:aDropContext |
|
857 |
"send the last time, when leaving the widget |
|
858 |
" |
|
3952 | 859 |
inDropMode ifTrue:[ |
860 |
self dropTargetItemChangedTo:nil in:aDropContext. |
|
861 |
self removeExpandItemTimedBlock. |
|
862 |
inDropMode := false. |
|
863 |
]. |
|
3892 | 864 |
! |
865 |
||
3952 | 866 |
dropOver:aContext |
867 |
"send the last time, when leaving the widget |
|
868 |
" |
|
869 |
|lineNr newDest| |
|
870 |
||
871 |
inDropMode ifFalse:[^ self]. |
|
872 |
||
873 |
lineNr := self getLineNumberFor:aContext. |
|
3892 | 874 |
|
3952 | 875 |
lineNr notNil ifTrue:[ |
876 |
newDest := self fileList at:lineNr ifAbsent:nil. |
|
877 |
]. |
|
4018 | 878 |
(newDest isNil or:[newDest == self fileList draggedItem]) ifTrue:[ |
3952 | 879 |
^ self |
880 |
]. |
|
881 |
newDest isDirectory not ifTrue:[ |
|
882 |
newDest := nil. |
|
883 |
canDropItem := false. |
|
884 |
]. |
|
885 |
self dropTargetItemChangedTo:newDest in:aContext. |
|
886 |
||
887 |
newDest notNil ifTrue:[ |
|
888 |
aContext dropSource argument == #archivApplication ifTrue:[ |
|
889 |
canDropItem := true. |
|
890 |
] ifFalse:[ |
|
891 |
canDropItem := self canDropFiles:(aContext dropObjects) for:newDest fileName. |
|
892 |
]. |
|
893 |
]. |
|
3892 | 894 |
! |
895 |
||
3952 | 896 |
dropTargetItemChangedTo:anItem in:aDropContext |
897 |
|current| |
|
898 |
||
899 |
current := self fileList draggedItem. |
|
900 |
current == anItem ifTrue:[^ self]. |
|
901 |
||
902 |
self fileList draggedItem:anItem. |
|
903 |
||
904 |
aDropContext contentsWillChange. |
|
905 |
current ifNotNil:[ |
|
906 |
current isDirectory ifTrue:[ |
|
907 |
self removeExpandItemTimedBlock. |
|
4440 | 908 |
current makeIconGray:false. |
3952 | 909 |
current changed:#icon. |
910 |
] |
|
911 |
]. |
|
3892 | 912 |
|
3952 | 913 |
anItem ifNotNil:[ |
914 |
anItem isDirectory ifTrue:[ |
|
4440 | 915 |
anItem makeIconGray:true. |
3952 | 916 |
anItem changed:#icon. |
917 |
(anItem notNil and:[anItem isDirectory and:[anItem fileName isWritable]]) ifTrue:[ |
|
918 |
expandItemTimedBlock := [ |
|
919 |
self expandForDrop:anItem with:aDropContext. |
|
920 |
]. |
|
921 |
Processor addTimedBlock:expandItemTimedBlock |
|
922 |
afterMilliseconds:(self class timeForExpandOnDropInMilliseconds). |
|
923 |
] |
|
924 |
]. |
|
925 |
]. |
|
926 |
dirBrowser shown ifTrue:[ |
|
927 |
dirBrowser repairDamage. |
|
928 |
]. |
|
3892 | 929 |
! |
930 |
||
931 |
expandForDrop:item with:aDropContext |
|
932 |
||
933 |
aDropContext saveDraw:[ |
|
934 |
(self doExpand:item) ifTrue:[ |
|
935 |
self windowGroup processExposeEvents |
|
936 |
]. |
|
937 |
] |
|
938 |
! |
|
939 |
||
940 |
getDisplayObjects:anArgument |
|
941 |
||
942 |
| string fnName sel size stream| |
|
3982 | 943 |
sel := self selectedItems. |
3892 | 944 |
size := sel size. |
945 |
size == 0 ifTrue:[^ '']. |
|
946 |
stream := WriteStream on:''. |
|
947 |
stream nextPutAll:sel first baseName. |
|
948 |
size == 1 ifTrue:[ |
|
949 |
fnName := 'ui_menuitem.xpm'. |
|
950 |
] ifFalse:[ |
|
951 |
fnName := 'ui_submenu_open.xpm'. |
|
952 |
stream nextPutAll:' ... '. |
|
953 |
stream nextPutAll:sel last baseName. |
|
954 |
]. |
|
955 |
string := stream contents. |
|
956 |
stream close. |
|
957 |
||
958 |
fnName := 'ui_menuitem.xpm'. |
|
959 |
^ Array with:(LabelAndIcon icon:(Image fromFile:fnName) |
|
960 |
string:(Text string:string emphasis:#bold) |
|
961 |
) |
|
962 |
! |
|
963 |
||
964 |
getDropObjects:anArgument |
|
965 |
||
966 |
| sel ret| |
|
967 |
||
3982 | 968 |
sel := self selectedFiles. |
3892 | 969 |
sel isEmpty ifTrue:[ ^ self ]. |
970 |
ret := sel collect:[:file| |
|
971 |
DropObject newFile:file |
|
972 |
]. |
|
973 |
^ ret |
|
974 |
! |
|
975 |
||
976 |
getLineNumberFor:aDropContext |
|
977 |
| yVisible| |
|
978 |
||
979 |
yVisible := (aDropContext targetPoint y). |
|
980 |
^ dirBrowser yVisibleToLineNr:yVisible. |
|
981 |
! |
|
982 |
||
983 |
removeExpandItemTimedBlock |
|
3952 | 984 |
|
3892 | 985 |
expandItemTimedBlock notNil ifTrue:[ |
986 |
Processor removeTimedBlock:expandItemTimedBlock. |
|
987 |
expandItemTimedBlock := nil |
|
988 |
] |
|
989 |
! ! |
|
990 |
||
991 |
!DirectoryTreeBrowser methodsFor:'event handling'! |
|
992 |
||
993 |
processEvent:anEvent |
|
994 |
"filter keyboard events. |
|
995 |
Return true, if I have eaten the event" |
|
996 |
||
4009 | 997 |
|evView key rawKey| |
3892 | 998 |
|
999 |
anEvent isKeyPressEvent ifTrue:[ |
|
4009 | 1000 |
evView := anEvent targetView. |
1001 |
evView isNil ifTrue:[ ^ false]. |
|
1002 |
evView == dirBrowser ifFalse:[ ^ false]. |
|
1003 |
key := anEvent key. |
|
3892 | 1004 |
rawKey := anEvent rawKey. |
1005 |
||
3906 | 1006 |
|
4009 | 1007 |
(key == #CursorLeft) ifTrue:[ |
1008 |
"go to last selection in selection history" |
|
1009 |
(self rootSelected and:[(self fileList at:1) isExpanded not]) ifTrue:[ |
|
1010 |
self doGoDirectoryUp. |
|
3892 | 1011 |
^ true |
4009 | 1012 |
] ifFalse:[ |
1013 |
^ false |
|
1014 |
] |
|
1015 |
]. |
|
1016 |
(key == #FocusPrevious) ifTrue:[ |
|
1017 |
"go to last selection in selection history" |
|
1018 |
self doBack. |
|
1019 |
^ true |
|
1020 |
]. |
|
1021 |
(key == #FocusNext) ifTrue:[ |
|
1022 |
"go to next selection in selection history" |
|
1023 |
self doForward. |
|
1024 |
^ true |
|
1025 |
]. |
|
1026 |
(key == #Replace) ifTrue:[ |
|
1027 |
self treeViewFileRename. |
|
1028 |
^ true |
|
1029 |
]. |
|
1030 |
(key == #Delete) ifTrue:[ |
|
1031 |
self doDelete. |
|
1032 |
^ true |
|
1033 |
]. |
|
1034 |
(key == #Cut) ifTrue:[ |
|
1035 |
self doCut. |
|
1036 |
^ true |
|
1037 |
]. |
|
1038 |
(key == #Paste) ifTrue:[ |
|
1039 |
self pasteFiles. |
|
1040 |
^ true |
|
1041 |
]. |
|
1042 |
(key == #Copy) ifTrue:[ |
|
1043 |
self doCopy. |
|
1044 |
^ true |
|
1045 |
]. |
|
3892 | 1046 |
]. |
1047 |
^ false |
|
1048 |
! ! |
|
1049 |
||
3982 | 1050 |
!DirectoryTreeBrowser methodsFor:'file actions'! |
3892 | 1051 |
|
3982 | 1052 |
doCopy |
1053 |
"copy current selected files/directories |
|
1054 |
" |
|
1055 |
||
4452 | 1056 |
self copyFilesToClipBoard:self selectedFiles. |
3982 | 1057 |
! |
3892 | 1058 |
|
3982 | 1059 |
doCut |
1060 |
"cut current selected files/directories |
|
1061 |
" |
|
4452 | 1062 |
self cutFilesToClipBoard:self selectedFiles. |
3982 | 1063 |
! |
1064 |
||
1065 |
doDelete |
|
1066 |
"delete current selected files/directories |
|
1067 |
" |
|
1068 |
||
1069 |
self deleteFiles:self selectedFiles. |
|
3892 | 1070 |
! ! |
1071 |
||
1072 |
!DirectoryTreeBrowser methodsFor:'queries'! |
|
1073 |
||
1074 |
masterIsFileBrowser |
|
1075 |
||
1076 |
^ self masterApplication class = FileBrowserV2 |
|
1077 |
! |
|
1078 |
||
3982 | 1079 |
selectedFilesIncludesNonRootDirectory |
1080 |
||
1081 |
| directories| |
|
1082 |
||
1083 |
directories := self selectedDirectories. |
|
1084 |
directories isEmpty ifTrue:[^ false]. |
|
1085 |
directories do:[:aDir| |
|
1086 |
(aDir asString) ~= (self rootHolder value) ifTrue:[ |
|
1087 |
^ true |
|
1088 |
] |
|
1089 |
]. |
|
1090 |
^ false |
|
1091 |
! ! |
|
1092 |
||
1093 |
!DirectoryTreeBrowser methodsFor:'selection'! |
|
1094 |
||
1095 |
firstSelectedDirectory |
|
1096 |
||
1097 |
| selection dirs dirIndices| |
|
1098 |
||
1099 |
selection := self selectedItems. |
|
1100 |
selection isEmpty ifTrue:[ ^ nil ]. |
|
3892 | 1101 |
|
3982 | 1102 |
dirs := selection collect:[:item| item isDirectory]. |
1103 |
dirs isEmpty ifTrue:[^ nil]. |
|
1104 |
dirIndices := selection collect:[:item | |
|
4008 | 1105 |
self fileList identityIndexOf:item. |
3982 | 1106 |
]. |
1107 |
^ (self fileList at:(dirIndices min)) fileName. |
|
1108 |
! |
|
1109 |
||
1110 |
rootSelected |
|
1111 |
||
1112 |
| selectedItems | |
|
1113 |
selectedItems := self selectedItems. |
|
1114 |
selectedItems isEmpty ifTrue:[^ false]. |
|
1115 |
^ selectedItems includesIdentical:self fileList root |
|
1116 |
! |
|
1117 |
||
1118 |
selectFiles:aColOfFileOrDirectory |
|
1119 |
"selects a file; if the file is not included in my |
|
1120 |
root directory, the root will be changed |
|
1121 |
" |
|
1122 |
|items directory item newRoot| |
|
1123 |
||
1124 |
aColOfFileOrDirectory isEmpty ifTrue:[ self selectItems:#()]. |
|
1125 |
||
1126 |
items := OrderedCollection new. |
|
1127 |
aColOfFileOrDirectory do:[:file| |
|
1128 |
file exists ifTrue:[ |
|
1129 |
item := self fileList findLastForFile:file. |
|
1130 |
item isNil ifTrue:[ |
|
1131 |
newRoot := self getCommonForCurrentFiles. |
|
1132 |
newRoot := self getDirWithoutFileName:newRoot. |
|
1133 |
self rootHolder value:newRoot. |
|
1134 |
item := self fileList root. |
|
3892 | 1135 |
|
3982 | 1136 |
file isDirectory ifTrue:[ directory := file ] |
1137 |
ifFalse:[ directory := file directory ] |
|
1138 |
. |
|
1139 |
directory == file ifFalse:[ |
|
1140 |
item := item detect:[:el| el fileName = file ] ifNone:item. |
|
1141 |
]. |
|
1142 |
]. |
|
1143 |
"/ set a new root directory |
|
1144 |
items add:item. |
|
1145 |
]. |
|
1146 |
]. |
|
1147 |
self selectItems:items |
|
1148 |
! |
|
1149 |
||
1150 |
selectItems:aColOfItems |
|
1151 |
||
4011 | 1152 |
|currentSelection newSelection| |
3982 | 1153 |
|
4011 | 1154 |
currentSelection := self selectedItems. |
1155 |
self multipleSelect ifTrue:[ |
|
1156 |
currentSelection notNil ifTrue:[ |
|
1157 |
aColOfItems size == currentSelection size ifTrue:[ |
|
1158 |
(aColOfItems findFirst:[:item | (currentSelection includesIdentical:item) not ]) ~~ 0 ifFalse:[ |
|
1159 |
^ self |
|
1160 |
]. |
|
1161 |
] |
|
1162 |
]. |
|
1163 |
newSelection := aColOfItems. |
|
1164 |
] ifFalse:[ |
|
1165 |
newSelection := aColOfItems isEmpty ifTrue:[nil] ifFalse:[aColOfItems first]. |
|
1166 |
newSelection == currentSelection ifTrue:[ |
|
1167 |
^ self |
|
1168 |
] |
|
1169 |
]. |
|
1170 |
||
3982 | 1171 |
aColOfItems notEmpty ifTrue:[ |
1172 |
aColOfItems first makeVisible. |
|
1173 |
]. |
|
4011 | 1174 |
self updateToExternFileHolderLock doLocked:[ |
1175 |
self treeSelectionHolder value:newSelection. |
|
3989 | 1176 |
]. |
3982 | 1177 |
! |
1178 |
||
1179 |
selectedDirectories |
|
1180 |
||
1181 |
| selItems | |
|
1182 |
||
1183 |
selItems := self selectedDirectoryItems. |
|
1184 |
^ selItems collect:[: el | el fileName ]. |
|
1185 |
! |
|
1186 |
||
1187 |
selectedDirectoryItems |
|
1188 |
||
1189 |
| sel | |
|
1190 |
sel := self selectedItems. |
|
1191 |
^ sel select:[: el | el isDirectory ]. |
|
1192 |
! |
|
1193 |
||
1194 |
selectedFilenameDirectories |
|
1195 |
||
1196 |
| selectedItems setOfDirectories| |
|
1197 |
selectedItems := self selectedItems. |
|
1198 |
setOfDirectories := Set new. |
|
1199 |
selectedItems do:[:item| |
|
1200 |
| filename| |
|
1201 |
filename := self getDirWithoutFileName:(item fileName). |
|
1202 |
setOfDirectories add:filename. |
|
1203 |
]. |
|
1204 |
^ setOfDirectories. |
|
1205 |
! |
|
1206 |
||
1207 |
selectedFiles |
|
1208 |
||
1209 |
^ self selectedItems collect:[:item| item fileName]. |
|
1210 |
! |
|
1211 |
||
1212 |
selectedItems |
|
1213 |
||
1214 |
| selection | |
|
1215 |
||
1216 |
selection := self treeSelectionHolder value. |
|
1217 |
selection isNil ifTrue:[ ^ #() ]. |
|
4002 | 1218 |
multipleSelect ifTrue:[^ selection ]. |
1219 |
^ Array with:selection. "Wrap single value into Array" |
|
3892 | 1220 |
! ! |
1221 |
||
1222 |
!DirectoryTreeBrowser methodsFor:'startup & release'! |
|
1223 |
||
3952 | 1224 |
initialize |
1225 |
||
1226 |
inDropMode := false. |
|
3961 | 1227 |
^ super initialize. |
3952 | 1228 |
! |
1229 |
||
3892 | 1230 |
makeDependent |
1231 |
||
4008 | 1232 |
super makeDependent. |
3892 | 1233 |
self currentFileNameHolder addDependent:self. |
4071 | 1234 |
self rootHolder addDependent:self. |
3892 | 1235 |
self viewFilesInDirectoryTree addDependent:self. |
4011 | 1236 |
self filterBlockHolder addDependent:self. |
3892 | 1237 |
! |
1238 |
||
1239 |
postBuildAsSubcanvasWith:aBuilder |
|
1240 |
||
1241 |
super postBuildAsSubcanvasWith:aBuilder. |
|
1242 |
! |
|
1243 |
||
1244 |
postBuildDirBrowser:aWidget |
|
1245 |
||
1246 |
dirBrowser := aWidget scrolledView. |
|
3968 | 1247 |
dirBrowser hasConstantHeight:true. |
1248 |
||
3892 | 1249 |
dirBrowser openEditorAction:[:ln :aGC| |field item filename newFileString rename newFilename| |
3957 | 1250 |
self allowFileOperations value ifTrue:[ |
1251 |
item := self fileList at:ln. |
|
3892 | 1252 |
|
3957 | 1253 |
item label isString ifFalse:[ |
1254 |
field := nil |
|
1255 |
] ifTrue:[ |
|
1256 |
field := EditField new. |
|
1257 |
field level:0. |
|
1258 |
field acceptOnReturn:true. |
|
4437 | 1259 |
field acceptOnLeave:true. |
3957 | 1260 |
field acceptAction:[:x| |
1261 |
filename := item fileName. |
|
1262 |
newFileString := x at:1. |
|
1263 |
filename baseName = newFileString ifFalse:[ |
|
1264 |
(self renameFile:filename to:newFileString update:false) ifTrue:[ |
|
1265 |
newFilename := filename directory construct:newFileString. |
|
1266 |
self updateAndSelect:(OrderedCollection with:newFilename). |
|
1267 |
]. |
|
3892 | 1268 |
]. |
3957 | 1269 |
aGC closeEditor. |
3892 | 1270 |
]. |
4437 | 1271 |
|
3957 | 1272 |
field font:(aGC font). |
1273 |
field contents:(item label). |
|
3892 | 1274 |
]. |
3957 | 1275 |
field |
3892 | 1276 |
]. |
1277 |
]. |
|
4437 | 1278 |
dirBrowser closeEditorAction:[:ln | |
1279 |
ln acceptAction value:ln list. |
|
1280 |
]. |
|
3892 | 1281 |
! |
1282 |
||
1283 |
postBuildWith:aBuilder |
|
1284 |
||
1285 |
super postBuildWith:aBuilder. |
|
1286 |
! |
|
1287 |
||
4071 | 1288 |
postOpen |
1289 |
||
1290 |
self rootHolderChanged. |
|
1291 |
self abstractCurrentFileNameHolderChanged. |
|
1292 |
self currentFileNameHolderChanged. |
|
4151 | 1293 |
self sortFileListsBy:self sortPropertyInTree value. |
4071 | 1294 |
self windowGroup addPreEventHook:self. |
1295 |
! |
|
1296 |
||
3892 | 1297 |
postOpenAsSubcanvasWith:aBuilder |
1298 |
||
4071 | 1299 |
super postOpenAsSubcanvasWith:aBuilder. |
1300 |
self postOpen. |
|
3892 | 1301 |
! |
1302 |
||
1303 |
postOpenWith:aBuilder |
|
4071 | 1304 |
"only invoked if the application not started from a master" |
3892 | 1305 |
|
4071 | 1306 |
super postOpenWith:aBuilder. |
1307 |
self postOpen. |
|
3892 | 1308 |
! |
1309 |
||
1310 |
preBuildWith:aBuilder |
|
1311 |
||
1312 |
self masterApplication isNil ifTrue:[ |
|
1313 |
self masterApplication:nil. |
|
1314 |
]. |
|
1315 |
^ super preBuildWith:aBuilder. |
|
1316 |
! |
|
1317 |
||
1318 |
release |
|
1319 |
||
1320 |
self fileList stopMonitoringTask. |
|
1321 |
^ super release. |
|
1322 |
! ! |
|
1323 |
||
1324 |
!DirectoryTreeBrowser::DirTreeBrowserHFL methodsFor:'accessing'! |
|
1325 |
||
3952 | 1326 |
draggedItem |
3892 | 1327 |
|
3952 | 1328 |
^ draggedItem |
1329 |
! |
|
3892 | 1330 |
|
3952 | 1331 |
draggedItem:anItemOrNil |
1332 |
||
1333 |
draggedItem := anItemOrNil. |
|
3892 | 1334 |
! ! |
1335 |
||
1336 |
!DirectoryTreeBrowser::DirTreeBrowserHFL methodsFor:'protocol'! |
|
1337 |
||
3969 | 1338 |
grayDirectoryIcon |
1339 |
||
1340 |
grayDirectoryIcon isNil ifTrue:[ |
|
1341 |
grayDirectoryIcon := (FileBrowser iconForKeyMatching:#directoryOpenGray). |
|
1342 |
]. |
|
1343 |
^ grayDirectoryIcon |
|
1344 |
! |
|
1345 |
||
1346 |
iconFor:anItem |
|
1347 |
"returns the icon for an item |
|
1348 |
" |
|
4557 | 1349 |
"/ Transcript showCR:'iconFor:anItem'. |
3892 | 1350 |
draggedItem == anItem ifTrue:[ |
3969 | 1351 |
^ self grayDirectoryIcon. |
3892 | 1352 |
]. |
3969 | 1353 |
^ super iconFor:anItem. |
3892 | 1354 |
! ! |
1355 |
||
1356 |
!DirectoryTreeBrowser class methodsFor:'documentation'! |
|
1357 |
||
1358 |
version |
|
4557 | 1359 |
^ '$Header: /cvs/stx/stx/libtool/DirectoryTreeBrowser.st,v 1.45 2003-02-13 20:53:21 cg Exp $' |
3892 | 1360 |
! ! |