3892
|
1 |
"{ Package: 'stx:libtool' }"
|
|
2 |
|
|
3 |
AbstractFileBrowser subclass:#DirectoryTreeBrowser
|
|
4 |
instanceVariableNames:'rootHolder dirBrowser lastResponse updateToExternFileHolderLock
|
|
5 |
oldDropItem expandItemTimedBlock updateTreeSelection'
|
|
6 |
classVariableNames:''
|
|
7 |
poolDictionaries:''
|
|
8 |
category:'Interface-Tools-File'
|
|
9 |
!
|
|
10 |
|
|
11 |
HierarchicalFileList subclass:#DirTreeBrowserHFL
|
|
12 |
instanceVariableNames:'draggedItem'
|
|
13 |
classVariableNames:''
|
|
14 |
poolDictionaries:''
|
|
15 |
privateIn:DirectoryTreeBrowser
|
|
16 |
!
|
|
17 |
|
|
18 |
!DirectoryTreeBrowser class methodsFor:'documentation'!
|
|
19 |
|
|
20 |
documentation
|
|
21 |
"
|
|
22 |
documentation to be added.
|
|
23 |
|
|
24 |
[author:]
|
|
25 |
Christian Penk (penk@bierfix)
|
|
26 |
|
|
27 |
[see also:]
|
|
28 |
|
|
29 |
[instance variables:]
|
|
30 |
|
|
31 |
[class variables:]
|
|
32 |
"
|
|
33 |
!
|
|
34 |
|
|
35 |
examples
|
|
36 |
"
|
|
37 |
Starting the application:
|
|
38 |
[exBegin]
|
|
39 |
DirectoryTreeBrowser open
|
|
40 |
|
|
41 |
[exEnd]
|
|
42 |
|
|
43 |
more examples to be added:
|
|
44 |
[exBegin]
|
|
45 |
... add code fragment for
|
|
46 |
... executable example here ...
|
|
47 |
[exEnd]
|
|
48 |
"
|
|
49 |
! !
|
|
50 |
|
|
51 |
!DirectoryTreeBrowser class methodsFor:'instance creation'!
|
|
52 |
|
|
53 |
open
|
|
54 |
|
|
55 |
^ super open
|
|
56 |
"
|
|
57 |
DirectoryTreeBrowser open
|
|
58 |
"
|
|
59 |
!
|
|
60 |
|
|
61 |
openOn:aFileName
|
|
62 |
|
|
63 |
| file |
|
|
64 |
file := aFileName asFilename.
|
|
65 |
file exists ifTrue:[
|
|
66 |
self openOn:aFileName withFiles:(file isDirectory not)
|
|
67 |
]
|
|
68 |
|
|
69 |
"
|
|
70 |
DirectoryTreeBrowser openOn:Filename homeDirectory
|
|
71 |
DirectoryTreeBrowser openOn:(Filename homeDirectory construct:'.bashrc')
|
|
72 |
"
|
|
73 |
!
|
|
74 |
|
|
75 |
openOn:aFileName withFiles:aBoolean
|
|
76 |
|
|
77 |
| instance|
|
|
78 |
|
|
79 |
instance := DirectoryTreeBrowser new.
|
|
80 |
instance open.
|
|
81 |
instance viewFilesInDirectoryTree value:aBoolean.
|
|
82 |
instance currentFileNameHolder value:(OrderedCollection with:aFileName).
|
|
83 |
"
|
|
84 |
DirectoryTreeBrowser openOn:Filename homeDirectory
|
|
85 |
DirectoryTreeBrowser openOn:(Filename homeDirectory construct:'.bashrc') withFiles:false
|
|
86 |
"
|
|
87 |
! !
|
|
88 |
|
|
89 |
!DirectoryTreeBrowser class methodsFor:'defaults'!
|
|
90 |
|
|
91 |
timeForExpandOnDropInMilliseconds
|
|
92 |
|
|
93 |
^ 1500
|
|
94 |
! !
|
|
95 |
|
|
96 |
!DirectoryTreeBrowser class methodsFor:'interface specs'!
|
|
97 |
|
|
98 |
windowSpec
|
|
99 |
"This resource specification was automatically generated
|
|
100 |
by the UIPainter of ST/X."
|
|
101 |
|
|
102 |
"Do not manually edit this!! If it is corrupted,
|
|
103 |
the UIPainter may not be able to read the specification."
|
|
104 |
|
|
105 |
"
|
|
106 |
UIPainter new openOnClass:DirectoryTreeBrowser andSelector:#windowSpec
|
|
107 |
DirectoryTreeBrowser new openInterface:#windowSpec
|
|
108 |
DirectoryTreeBrowser open
|
|
109 |
"
|
|
110 |
|
|
111 |
<resource: #canvas>
|
|
112 |
|
|
113 |
^
|
|
114 |
#(#FullSpec
|
|
115 |
#name: #windowSpec
|
|
116 |
#window:
|
|
117 |
#(#WindowSpec
|
|
118 |
#label: 'DirectoryTreeBrowser'
|
|
119 |
#name: 'DirectoryTreeBrowser'
|
|
120 |
#min: #(#Point 10 10)
|
|
121 |
#max: #(#Point 1024 768)
|
|
122 |
#bounds: #(#Rectangle 16 42 316 342)
|
|
123 |
#menu: #mainMenu
|
|
124 |
)
|
|
125 |
#component:
|
|
126 |
#(#SpecCollection
|
|
127 |
#collection: #(
|
|
128 |
#(#HierarchicalListViewSpec
|
|
129 |
#name: 'HierarchicalListView'
|
|
130 |
#layout: #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
|
|
131 |
#model: #treeSelectionHolder
|
|
132 |
#menu: #menu
|
|
133 |
#hasHorizontalScrollBar: true
|
|
134 |
#hasVerticalScrollBar: true
|
|
135 |
#miniScrollerHorizontal: false
|
|
136 |
#miniScrollerVertical: false
|
|
137 |
#listModel: #fileList
|
|
138 |
#multipleSelectOk: true
|
3906
|
139 |
#highlightMode: #label
|
3892
|
140 |
#doubleClickSelector: #doDoubleClick:
|
|
141 |
#indicatorSelector: #doIndicatorClick:
|
|
142 |
#postBuildCallback: #postBuildDirBrowser:
|
|
143 |
#properties:
|
|
144 |
#(#PropertyListDictionary
|
|
145 |
#dragArgument: #directoryTreeBrowser
|
|
146 |
#startDragSelector: #doStartDrag:in:
|
|
147 |
#displayObjectSelector: #getDisplayObjects:
|
|
148 |
#dropObjectSelector: #getDropObjects:
|
|
149 |
#dropArgument: #directoryTreeBrowser
|
|
150 |
#canDropSelector: #canDrop:argument:
|
|
151 |
#leaveSelector: #dropLeave:
|
|
152 |
#dropSelector: #doDrop:argument:
|
|
153 |
)
|
|
154 |
)
|
|
155 |
)
|
|
156 |
|
|
157 |
)
|
|
158 |
)
|
|
159 |
! !
|
|
160 |
|
|
161 |
!DirectoryTreeBrowser class methodsFor:'menu specs'!
|
|
162 |
|
|
163 |
menu
|
|
164 |
"This resource specification was automatically generated
|
|
165 |
by the MenuEditor of ST/X."
|
|
166 |
|
|
167 |
"Do not manually edit this!! If it is corrupted,
|
|
168 |
the MenuEditor may not be able to read the specification."
|
|
169 |
|
|
170 |
"
|
|
171 |
MenuEditor new openOnClass:DirectoryTreeBrowser andSelector:#menu
|
|
172 |
(Menu new fromLiteralArrayEncoding:(DirectoryTreeBrowser menu)) startUp
|
|
173 |
"
|
|
174 |
|
|
175 |
<resource: #menu>
|
|
176 |
|
|
177 |
^
|
|
178 |
#(#Menu
|
|
179 |
#(
|
|
180 |
#(#MenuItem
|
|
181 |
#label: 'Copy'
|
|
182 |
#translateLabel: true
|
|
183 |
#value: #doCopy
|
|
184 |
#shortcutKeyCharacter: #Copy
|
|
185 |
)
|
|
186 |
#(#MenuItem
|
|
187 |
#label: 'Cut'
|
|
188 |
#translateLabel: true
|
|
189 |
#value: #doCut
|
|
190 |
#shortcutKeyCharacter: #Cut
|
|
191 |
)
|
|
192 |
#(#MenuItem
|
|
193 |
#label: 'Paste'
|
|
194 |
#translateLabel: true
|
|
195 |
#value: #pasteFiles
|
|
196 |
#enabled: #canPaste
|
|
197 |
#shortcutKeyCharacter: #Paste
|
|
198 |
)
|
|
199 |
#(#MenuItem
|
|
200 |
#label: 'Delete'
|
|
201 |
#translateLabel: true
|
|
202 |
#nameKey: #delete
|
|
203 |
#value: #doDelete
|
|
204 |
#shortcutKeyCharacter: #Delete
|
|
205 |
)
|
|
206 |
#(#MenuItem
|
|
207 |
#label: '-'
|
|
208 |
)
|
|
209 |
#(#MenuItem
|
|
210 |
#label: 'Directory Up'
|
|
211 |
#translateLabel: true
|
|
212 |
#value: #doGoDirectoryUp
|
|
213 |
#enabled: #enableDirectoryUp
|
|
214 |
#shortcutKeyCharacter: #CursorLeft
|
|
215 |
)
|
|
216 |
#(#MenuItem
|
|
217 |
#label: 'Set Selection Top'
|
|
218 |
#translateLabel: true
|
|
219 |
#value: #doSetSelectionToTop
|
|
220 |
#enabled: #selectedFileIsDirectoryAndNotRoot
|
|
221 |
)
|
|
222 |
#(#MenuItem
|
|
223 |
#label: 'Re-/ Expand Directory'
|
|
224 |
#translateLabel: true
|
|
225 |
#value: #expandSelectedItem
|
|
226 |
#shortcutKeyCharacter: #CursorRight
|
|
227 |
)
|
|
228 |
#(#MenuItem
|
|
229 |
#label: '-'
|
|
230 |
)
|
|
231 |
#(#MenuItem
|
|
232 |
#label: 'View Directory Tree'
|
|
233 |
#translateLabel: true
|
|
234 |
#isVisible: #masterIsFileBrowser
|
|
235 |
#indication: #showDirectoryTreeHolder
|
|
236 |
)
|
|
237 |
#(#MenuItem
|
|
238 |
#label: 'View Files in Directory Tree'
|
|
239 |
#translateLabel: true
|
|
240 |
#indication: #viewFilesInDirectoryTree
|
|
241 |
)
|
|
242 |
#(#MenuItem
|
|
243 |
#label: '-'
|
|
244 |
)
|
|
245 |
#(#MenuItem
|
|
246 |
#label: 'New'
|
|
247 |
#translateLabel: true
|
|
248 |
#submenuChannel: #newMenu
|
|
249 |
)
|
|
250 |
#(#MenuItem
|
|
251 |
#label: 'Rename...'
|
|
252 |
#translateLabel: true
|
|
253 |
#value: #treeViewFileRename
|
|
254 |
#shortcutKeyCharacter: #Replace
|
|
255 |
)
|
|
256 |
)
|
|
257 |
nil
|
|
258 |
nil
|
|
259 |
)
|
|
260 |
! !
|
|
261 |
|
|
262 |
!DirectoryTreeBrowser class methodsFor:'plugIn spec'!
|
|
263 |
|
|
264 |
aspectSelectors
|
|
265 |
"This resource specification was automatically generated
|
|
266 |
by the UIPainter of ST/X."
|
|
267 |
|
|
268 |
"Do not manually edit this. If it is corrupted,
|
|
269 |
the UIPainter may not be able to read the specification."
|
|
270 |
|
|
271 |
"Return a description of exported aspects;
|
|
272 |
these can be connected to aspects of an embedding application
|
|
273 |
(if this app is embedded in a subCanvas)."
|
|
274 |
|
|
275 |
^ #(
|
|
276 |
#selectedDirectoryModel
|
|
277 |
).
|
|
278 |
|
|
279 |
! !
|
|
280 |
|
|
281 |
!DirectoryTreeBrowser methodsFor:'accessing'!
|
|
282 |
|
|
283 |
updateToExternFileHolderLock
|
|
284 |
"return the value of the instance variable 'updateToExternFileHolder' (automatically generated)"
|
|
285 |
|
|
286 |
updateToExternFileHolderLock isNil ifTrue:[
|
|
287 |
updateToExternFileHolderLock := self class newLock.
|
|
288 |
].
|
|
289 |
^ updateToExternFileHolderLock
|
|
290 |
!
|
|
291 |
|
|
292 |
updateTreeSelection
|
|
293 |
"return the value of the instance variable 'updateToExternFileHolder' (automatically generated)"
|
|
294 |
|
|
295 |
updateTreeSelection isNil ifTrue:[
|
|
296 |
updateTreeSelection := self class newLock.
|
|
297 |
].
|
|
298 |
^ updateTreeSelection
|
|
299 |
! !
|
|
300 |
|
|
301 |
!DirectoryTreeBrowser methodsFor:'actions'!
|
|
302 |
|
|
303 |
doDoubleClick:anIndex
|
|
304 |
"handle a doubleClick on a directory
|
|
305 |
"
|
|
306 |
|
|
307 |
|item file isDirectory|
|
|
308 |
|
|
309 |
item := self fileList at:anIndex ifAbsent:nil.
|
|
310 |
item notNil ifTrue:[
|
|
311 |
isDirectory := item isDirectory.
|
|
312 |
file := item fileName.
|
|
313 |
isDirectory ifTrue:[
|
|
314 |
(file isReadable and:[file isExecutable]) ifTrue:[
|
|
315 |
self doExpand:item.
|
|
316 |
]
|
|
317 |
] ifFalse:[
|
|
318 |
"/ self openApplByFileItem:item.
|
|
319 |
]
|
|
320 |
]
|
|
321 |
!
|
|
322 |
|
|
323 |
doExpand:anItem
|
|
324 |
" expand the item; return true the item have expanded "
|
|
325 |
|
|
326 |
(anItem notNil and:[anItem isDirectory and:[anItem isExpanded not]]) ifTrue:[
|
|
327 |
anItem toggleExpand.
|
|
328 |
^ true.
|
|
329 |
].
|
|
330 |
^ false
|
|
331 |
!
|
|
332 |
|
|
333 |
doIndicatorClick:anIndex
|
|
334 |
"handle a click on the indicator
|
|
335 |
"
|
|
336 |
|
|
337 |
|item|
|
|
338 |
|
|
339 |
item := self fileList at:anIndex ifAbsent:nil.
|
|
340 |
self toggleExpand:item
|
|
341 |
!
|
|
342 |
|
|
343 |
doUpdate
|
|
344 |
|
|
345 |
self fileList monitoringCycle.
|
|
346 |
"/ self updateSelectedItem
|
|
347 |
!
|
|
348 |
|
|
349 |
expandSelectedItem
|
|
350 |
|
|
351 |
|selDir|
|
|
352 |
|
|
353 |
selDir := self getFirstDirectoryItemOfSelection.
|
|
354 |
selDir isNil ifTrue:[^ self ].
|
|
355 |
self toggleExpand:selDir.
|
|
356 |
!
|
|
357 |
|
|
358 |
setMatchBlock
|
|
359 |
|
|
360 |
|list|
|
|
361 |
|
|
362 |
list := self fileList.
|
|
363 |
self setMatchBlockForList:list
|
|
364 |
!
|
|
365 |
|
|
366 |
setMatchBlockForList:list
|
|
367 |
|
|
368 |
self viewFilesInDirectoryTree value ifTrue:[
|
|
369 |
list matchBlock:[:fn :isDir| isDir or:[
|
|
370 |
(self showHiddenFiles value ifFalse:[
|
|
371 |
(fn baseName startsWith:'.') not])
|
|
372 |
and:[self filterModel value match:fn baseName]]]
|
|
373 |
] ifFalse:[
|
|
374 |
list matchBlock:[:fn :isDir| isDir ].
|
|
375 |
].
|
|
376 |
!
|
|
377 |
|
|
378 |
toggleExpand:anItem
|
|
379 |
|
|
380 |
(anItem notNil and:[anItem isDirectory]) ifTrue:[
|
|
381 |
anItem toggleExpand
|
|
382 |
].
|
|
383 |
!
|
|
384 |
|
|
385 |
treeViewFileRename
|
3906
|
386 |
||
|
3892
|
387 |
|
3906
|
388 |
dirBrowser openEditor.
|
|
389 |
"/ selectedFiles := self getFilesForSelection.
|
|
390 |
"/ self renameFiles:selectedFiles.
|
3892
|
391 |
!
|
|
392 |
|
|
393 |
updateSelectedItem
|
|
394 |
|
|
395 |
| sel |
|
|
396 |
|
|
397 |
sel := self getItemsForSelection.
|
|
398 |
sel isEmpty ifTrue:[ ^ self].
|
|
399 |
sel do:[:item|
|
|
400 |
self doExpand:item.
|
|
401 |
item invalidateRepairNow:true.
|
|
402 |
]
|
|
403 |
! !
|
|
404 |
|
|
405 |
!DirectoryTreeBrowser methodsFor:'aspects'!
|
|
406 |
|
|
407 |
fileList
|
|
408 |
"holder, which keeps the current list of file entries shown by the directory-browser
|
|
409 |
"
|
|
410 |
|
|
411 |
|list|
|
|
412 |
|
|
413 |
(list := builder bindingAt:#fileList) isNil ifTrue:[
|
|
414 |
list := DirTreeBrowserHFL new.
|
|
415 |
list application:self.
|
|
416 |
list showRoot:true.
|
|
417 |
self setMatchBlockForList:list.
|
|
418 |
list directory:(self rootHolder value).
|
|
419 |
builder aspectAt:#fileList put:list.
|
|
420 |
list monitoringTaskDelay:2
|
|
421 |
].
|
|
422 |
^ list
|
|
423 |
!
|
|
424 |
|
|
425 |
rootHolder
|
|
426 |
"holder, which keeps the current root directory
|
|
427 |
"
|
|
428 |
rootHolder isNil ifTrue:[
|
|
429 |
rootHolder := ValueHolder new.
|
|
430 |
rootHolder addDependent:self.
|
|
431 |
].
|
|
432 |
^ rootHolder.
|
|
433 |
! !
|
|
434 |
|
|
435 |
!DirectoryTreeBrowser methodsFor:'change & update'!
|
|
436 |
|
|
437 |
changeCurrentFileNameHolder
|
|
438 |
|
|
439 |
| viewFiles curFiles sel currentFileDir|
|
|
440 |
|
|
441 |
viewFiles := self viewFilesInDirectoryTree value.
|
|
442 |
curFiles := self currentFileNameHolder value.
|
|
443 |
" if i cant select the files because viewFiles is false i cant take my
|
|
444 |
selction to overwrite currentFileNameHolder
|
|
445 |
"
|
|
446 |
sel := self getFilesForSelection.
|
|
447 |
viewFiles not ifTrue:[
|
|
448 |
(self currentFilesAreInSameDirectory and:[sel size == 1]) ifTrue:[
|
|
449 |
currentFileDir := self getDirWithoutFileName:(self currentFileNameHolder value first).
|
|
450 |
(sel first = currentFileDir) ifTrue:[
|
|
451 |
^ self.
|
|
452 |
].
|
|
453 |
].
|
|
454 |
].
|
|
455 |
self currentFileNameHolder value:sel.
|
|
456 |
!
|
|
457 |
|
|
458 |
changeSelection
|
|
459 |
|
|
460 |
|currentHolder newItem directoryName directory oldSel index viewFiles newSel newColOfItems bestFile dir|
|
|
461 |
|
|
462 |
newSel := OrderedCollection new.
|
|
463 |
currentHolder := self currentFileNameHolder value.
|
|
464 |
currentHolder isEmpty ifTrue:[
|
|
465 |
self treeSelectionHolder value:newSel withoutNotifying:self.
|
|
466 |
^ self
|
|
467 |
].
|
|
468 |
bestFile := self getBestFile.
|
|
469 |
directory := self getDirWithoutFileName:bestFile.
|
|
470 |
directoryName := directory asString.
|
|
471 |
viewFiles := self viewFilesInDirectoryTree value.
|
|
472 |
|
|
473 |
|
|
474 |
((rootHolder value isNil) or:[((self fileName:directoryName startsWith:rootHolder value)) not]) ifTrue:[
|
|
475 |
self setNewRoot:directory.
|
|
476 |
].
|
|
477 |
newColOfItems := Set new.
|
|
478 |
oldSel := self getItemsForSelection.
|
|
479 |
currentHolder do:[ : file |
|
|
480 |
oldSel notEmpty ifTrue:[
|
|
481 |
newItem := oldSel detect:[: item| item fileName = file] ifNone:[nil].
|
|
482 |
].
|
|
483 |
newItem isNil ifTrue:[
|
|
484 |
((viewFiles not) and:[file isDirectory not]) ifTrue:[
|
|
485 |
"/ select directory because cant select filename - if is not in tree
|
|
486 |
dir := self getDirWithoutFileName:file.
|
|
487 |
newItem := self recursiveGetItemFor:dir.
|
|
488 |
] ifFalse:[
|
|
489 |
newItem := self recursiveGetItemFor:file.
|
|
490 |
].
|
|
491 |
].
|
|
492 |
newItem notNil ifTrue:[
|
|
493 |
newColOfItems add:newItem.
|
|
494 |
].
|
|
495 |
].
|
|
496 |
newSel := OrderedCollection new.
|
|
497 |
newColOfItems do:[ : item |
|
|
498 |
index := self fileList indexOf:item.
|
|
499 |
newSel add:index.
|
|
500 |
].
|
|
501 |
self treeSelectionHolder value:newSel.
|
|
502 |
newColOfItems size == 1 ifTrue:[
|
|
503 |
| item |
|
|
504 |
item := newColOfItems first.
|
|
505 |
item isDirectory ifTrue:[
|
|
506 |
self doExpand:item.
|
|
507 |
]
|
|
508 |
]
|
|
509 |
!
|
|
510 |
|
|
511 |
recursiveGetItemFor:aDirectory
|
|
512 |
|
|
513 |
^ self recursiveGetItemFor:aDirectory fromIndex:1
|
|
514 |
!
|
|
515 |
|
|
516 |
recursiveGetItemFor:aFile fromIndex:aStartIndex
|
|
517 |
|list aFileNameString startIndex retItem|
|
|
518 |
|
|
519 |
list := self fileList.
|
|
520 |
aFileNameString := aFile asString.
|
|
521 |
retItem := nil.
|
|
522 |
list from:aStartIndex
|
|
523 |
do:[:item |
|
|
524 |
|filename |
|
|
525 |
|
|
526 |
filename := item fileName asString.
|
|
527 |
(self fileName:aFileNameString startsWith:filename) ifTrue:[
|
|
528 |
(filename asFilename pathName = aFileNameString asFilename pathName) ifTrue:[
|
|
529 |
^ item
|
|
530 |
].
|
|
531 |
(item isExpanded not and:[item canExpand]) ifTrue:[
|
|
532 |
item toggleExpand.
|
|
533 |
startIndex := list indexOf:item.
|
|
534 |
retItem := self recursiveGetItemFor:aFile fromIndex:startIndex.
|
|
535 |
^ retItem
|
|
536 |
]
|
|
537 |
]
|
|
538 |
].
|
|
539 |
^ retItem
|
|
540 |
!
|
|
541 |
|
|
542 |
setNewRoot:directoryPath
|
|
543 |
|
3906
|
544 |
| rootItem|
|
3892
|
545 |
|
|
546 |
"/ EXPAND THE ROOT DIR
|
|
547 |
self rootHolder value:directoryPath.
|
3906
|
548 |
rootItem := self fileList root.
|
|
549 |
rootItem notNil ifTrue:[
|
|
550 |
rootItem expand.
|
3892
|
551 |
].
|
|
552 |
!
|
|
553 |
|
|
554 |
update:something with:aParameter from:aModel
|
|
555 |
"one of my models changed
|
|
556 |
"
|
|
557 |
|
|
558 |
|list file|
|
|
559 |
|
|
560 |
" the execution of changeSelection and changeCurrentFileNameHolder must
|
|
561 |
lock against each other because values dont must be the same (e.g. no files
|
|
562 |
in tree view)
|
|
563 |
"
|
|
564 |
|
|
565 |
aModel == self currentFileNameHolder ifTrue:[
|
|
566 |
self updateTreeSelection doIfUnLocked:[
|
|
567 |
self updateToExternFileHolderLock doLocked:[
|
|
568 |
self changeSelection.
|
|
569 |
].
|
|
570 |
].
|
|
571 |
" do not return here because the AbstractFileBrowserComponent have to do something
|
|
572 |
for every application "
|
|
573 |
"/ ^ self.
|
|
574 |
].
|
|
575 |
aModel == self treeSelectionHolder ifTrue:[
|
|
576 |
self updateToExternFileHolderLock doIfUnLocked:[
|
|
577 |
self updateTreeSelection doLocked:[
|
|
578 |
self changeCurrentFileNameHolder.
|
|
579 |
]
|
|
580 |
].
|
|
581 |
^ self
|
|
582 |
].
|
|
583 |
aModel == rootHolder ifTrue:[
|
|
584 |
list := self fileList.
|
|
585 |
file := aModel value.
|
|
586 |
file notNil ifTrue:[
|
|
587 |
file := Filename named:(file asString).
|
|
588 |
(file isDirectory and:[file isReadable and:[file isExecutable]]) ifTrue:[
|
|
589 |
list directory:file
|
|
590 |
]
|
|
591 |
].
|
|
592 |
aModel value:(list directory asString) withoutNotifying:self.
|
|
593 |
^ self.
|
|
594 |
].
|
|
595 |
aModel == self viewFilesInDirectoryTree ifTrue:[
|
|
596 |
self setMatchBlock.
|
|
597 |
"/ if changed to true select the files in currentFilenameHolder in treeview
|
|
598 |
aModel value ifTrue:[
|
|
599 |
self changeSelection.
|
|
600 |
].
|
|
601 |
^ self.
|
|
602 |
].
|
|
603 |
aModel == self filterModel ifTrue:[
|
|
604 |
self setMatchBlock.
|
|
605 |
].
|
|
606 |
super update:something with:aParameter from:aModel.
|
|
607 |
^ self
|
|
608 |
! !
|
|
609 |
|
|
610 |
!DirectoryTreeBrowser methodsFor:'drag & drop'!
|
|
611 |
|
|
612 |
canDrop:aContext argument:arg2
|
|
613 |
|source lineNr archivListDrop destinationItem dropToFile|
|
|
614 |
|
|
615 |
source := aContext dropSource.
|
|
616 |
source isNil ifTrue:[^ false ].
|
|
617 |
archivListDrop := (source argument == #archivApplication).
|
|
618 |
lineNr := self getLineNumberFor:aContext.
|
|
619 |
lineNr notNil ifTrue:[
|
|
620 |
destinationItem := self fileList at:lineNr ifAbsent:nil.
|
|
621 |
].
|
|
622 |
destinationItem isNil ifTrue:[
|
|
623 |
oldDropItem notNil ifTrue:[
|
|
624 |
self removeExpandItemTimedBlock.
|
|
625 |
self enqueueChangeDraggedItem:nil with:aContext.
|
|
626 |
oldDropItem := nil.
|
|
627 |
].
|
|
628 |
^ false
|
|
629 |
].
|
|
630 |
(destinationItem ~~ oldDropItem) ifTrue:[
|
|
631 |
oldDropItem := destinationItem.
|
|
632 |
self enqueueChangeDraggedItem:nil with:aContext.
|
|
633 |
destinationItem isDirectory ifTrue:[
|
|
634 |
self enqueueChangeDraggedItem:destinationItem with:aContext.
|
|
635 |
].
|
|
636 |
self removeExpandItemTimedBlock.
|
|
637 |
(destinationItem notNil and:[destinationItem isDirectory and:[destinationItem fileName isWritable]]) ifTrue:[
|
|
638 |
expandItemTimedBlock := [
|
|
639 |
self enqueueExpandForDrop:destinationItem with:aContext
|
|
640 |
].
|
|
641 |
Processor addTimedBlock:expandItemTimedBlock
|
|
642 |
afterMilliseconds:(self class timeForExpandOnDropInMilliseconds).
|
|
643 |
dropToFile := destinationItem fileName.
|
|
644 |
archivListDrop ifTrue:[
|
|
645 |
lastResponse := self canDropArchiv:(aContext dropObjects) for:dropToFile
|
|
646 |
] ifFalse:[
|
|
647 |
lastResponse := self canDropFiles:(aContext dropObjects) for:dropToFile
|
|
648 |
]
|
|
649 |
] ifFalse:[
|
|
650 |
lastResponse := false
|
|
651 |
]
|
|
652 |
].
|
|
653 |
^ lastResponse
|
|
654 |
!
|
|
655 |
|
|
656 |
changeDraggedItem:anItem with:aDropContext
|
|
657 |
|
|
658 |
self changeDraggedItem:anItem with:aDropContext saveDraw:true
|
|
659 |
!
|
|
660 |
|
|
661 |
changeDraggedItem:anItem with:aDropContext saveDraw:saveDraw
|
|
662 |
|
|
663 |
saveDraw ifTrue:[
|
|
664 |
aDropContext saveDraw:[
|
|
665 |
self fileList draggedItem:anItem.
|
|
666 |
self windowGroup processExposeEvents.
|
|
667 |
]
|
|
668 |
] ifFalse:[
|
|
669 |
self fileList draggedItem:anItem.
|
|
670 |
self windowGroup processExposeEvents.
|
|
671 |
]
|
|
672 |
!
|
|
673 |
|
|
674 |
doDrop:aContext
|
|
675 |
|col destination destinationPath lineNr source receiver|
|
|
676 |
|
|
677 |
source := aContext dropSource.
|
|
678 |
lineNr := self getLineNumberFor:aContext.
|
|
679 |
lineNr isNil ifTrue:[
|
|
680 |
^ false
|
|
681 |
].
|
|
682 |
destination := self fileList at:lineNr.
|
|
683 |
destinationPath := destination fileName.
|
|
684 |
source argument == #archivApplication ifTrue:[
|
|
685 |
receiver := source receiver.
|
|
686 |
receiver extractSelectedFilesTo:destinationPath askForExtractOptions:true.
|
|
687 |
^ true
|
|
688 |
].
|
|
689 |
col := OrderedCollection new.
|
|
690 |
aContext dropObjects do:[:obj |
|
|
691 |
col add:(obj theObject)
|
|
692 |
].
|
|
693 |
self enqueueCopyOrMoveFiles:col to:destinationPath.
|
|
694 |
^ true
|
|
695 |
!
|
|
696 |
|
|
697 |
doDrop:aContext argument:arg2
|
|
698 |
|
|
699 |
| aBoolean |
|
|
700 |
|
|
701 |
aBoolean := self doDrop:aContext.
|
|
702 |
self dropLeave:aContext.
|
|
703 |
^ aBoolean.
|
|
704 |
!
|
|
705 |
|
|
706 |
dropLeave:aDropContext
|
|
707 |
"send the last time, when leaving the widget
|
|
708 |
"
|
|
709 |
self removeExpandItemTimedBlock.
|
|
710 |
oldDropItem := nil.
|
|
711 |
self changeDraggedItem:nil with:aDropContext saveDraw:false.
|
|
712 |
lastResponse := nil.
|
|
713 |
!
|
|
714 |
|
|
715 |
enqueueChangeDraggedItem:anItem with:aContext
|
|
716 |
|
|
717 |
self enqueueMessage:#'changeDraggedItem:with:' for:self arguments:(Array with:anItem with:aContext)
|
|
718 |
!
|
|
719 |
|
|
720 |
enqueueCopyOrMoveFiles:col to:destinationPath
|
|
721 |
|
|
722 |
self enqueueMessage:#'copyOrMoveFiles:to:' for:self arguments:(Array with:col with:destinationPath)
|
|
723 |
!
|
|
724 |
|
|
725 |
enqueueExpandForDrop:item with:aDropContext
|
|
726 |
|
|
727 |
self enqueueMessage:#'expandForDrop:with:' for:self arguments:(Array with:item with:aDropContext)
|
|
728 |
!
|
|
729 |
|
|
730 |
expandForDrop:item with:aDropContext
|
|
731 |
|
|
732 |
aDropContext saveDraw:[
|
|
733 |
(self doExpand:item) ifTrue:[
|
|
734 |
self windowGroup processExposeEvents
|
|
735 |
].
|
|
736 |
]
|
|
737 |
!
|
|
738 |
|
|
739 |
getDisplayObjects:anArgument
|
|
740 |
|
|
741 |
| string fnName sel size stream|
|
|
742 |
sel := self getFilesForSelection.
|
|
743 |
size := sel size.
|
|
744 |
size == 0 ifTrue:[^ ''].
|
|
745 |
stream := WriteStream on:''.
|
|
746 |
stream nextPutAll:sel first baseName.
|
|
747 |
size == 1 ifTrue:[
|
|
748 |
fnName := 'ui_menuitem.xpm'.
|
|
749 |
] ifFalse:[
|
|
750 |
fnName := 'ui_submenu_open.xpm'.
|
|
751 |
stream nextPutAll:' ... '.
|
|
752 |
stream nextPutAll:sel last baseName.
|
|
753 |
].
|
|
754 |
string := stream contents.
|
|
755 |
stream close.
|
|
756 |
|
|
757 |
fnName := 'ui_menuitem.xpm'.
|
|
758 |
^ Array with:(LabelAndIcon icon:(Image fromFile:fnName)
|
|
759 |
string:(Text string:string emphasis:#bold)
|
|
760 |
)
|
|
761 |
!
|
|
762 |
|
|
763 |
getDropObjects:anArgument
|
|
764 |
|
|
765 |
| sel ret|
|
|
766 |
|
|
767 |
sel := self getFilesForSelection.
|
|
768 |
sel isEmpty ifTrue:[ ^ self ].
|
|
769 |
ret := sel collect:[:file|
|
|
770 |
DropObject newFile:file
|
|
771 |
].
|
|
772 |
^ ret
|
|
773 |
!
|
|
774 |
|
|
775 |
getLineNumberFor:aDropContext
|
|
776 |
| yVisible|
|
|
777 |
|
|
778 |
yVisible := (aDropContext targetPoint y).
|
|
779 |
^ dirBrowser yVisibleToLineNr:yVisible.
|
|
780 |
!
|
|
781 |
|
|
782 |
removeExpandItemTimedBlock
|
|
783 |
expandItemTimedBlock notNil ifTrue:[
|
|
784 |
Processor removeTimedBlock:expandItemTimedBlock.
|
|
785 |
expandItemTimedBlock := nil
|
|
786 |
]
|
|
787 |
! !
|
|
788 |
|
|
789 |
!DirectoryTreeBrowser methodsFor:'event handling'!
|
|
790 |
|
|
791 |
processEvent:anEvent
|
|
792 |
"filter keyboard events.
|
|
793 |
Return true, if I have eaten the event"
|
|
794 |
|
|
795 |
|focusView key rawKey|
|
|
796 |
|
|
797 |
anEvent isKeyPressEvent ifTrue:[
|
|
798 |
focusView := anEvent targetView.
|
|
799 |
key := anEvent key.
|
|
800 |
rawKey := anEvent rawKey.
|
|
801 |
|
|
802 |
(focusView isSameOrComponentOf:self window) ifTrue:[
|
3906
|
803 |
|
3892
|
804 |
focusView name = 'editField' ifTrue:[ ^ false].
|
3906
|
805 |
|
|
806 |
(key == #FocusPrevious) ifTrue:[
|
|
807 |
"go to last selection in selection history"
|
|
808 |
self doBack.
|
3892
|
809 |
^ true
|
|
810 |
].
|
3906
|
811 |
(key == #FocusNext) ifTrue:[
|
|
812 |
"go to next selection in selection history"
|
|
813 |
self doForward.
|
3892
|
814 |
^ true
|
|
815 |
].
|
|
816 |
(key == #Replace) ifTrue:[
|
|
817 |
self treeViewFileRename.
|
|
818 |
^ true
|
|
819 |
].
|
|
820 |
(key == #Delete) ifTrue:[
|
|
821 |
self doDelete.
|
|
822 |
^ true
|
|
823 |
].
|
|
824 |
(key == #Cut) ifTrue:[
|
|
825 |
self doCut.
|
|
826 |
^ true
|
|
827 |
].
|
|
828 |
(key == #Paste) ifTrue:[
|
|
829 |
self pasteFiles.
|
|
830 |
^ true
|
|
831 |
].
|
|
832 |
(key == #Copy) ifTrue:[
|
|
833 |
self doCopy.
|
|
834 |
^ true
|
|
835 |
].
|
|
836 |
]
|
|
837 |
].
|
|
838 |
^ false
|
|
839 |
! !
|
|
840 |
|
|
841 |
!DirectoryTreeBrowser methodsFor:'menu - actions'!
|
|
842 |
|
|
843 |
doSetSelectionToTop
|
|
844 |
| selDir|
|
|
845 |
|
|
846 |
selDir := self getFirstDirectoryOfSelection.
|
|
847 |
selDir notNil ifTrue:[
|
|
848 |
self rootHolder value asFilename = selDir ifTrue:[ ^ self].
|
|
849 |
self setNewRoot:selDir.
|
|
850 |
self currentFileNameHolder value:(OrderedCollection with:selDir).
|
|
851 |
].
|
|
852 |
! !
|
|
853 |
|
|
854 |
!DirectoryTreeBrowser methodsFor:'queries'!
|
|
855 |
|
|
856 |
getFilesForSelection
|
|
857 |
|
|
858 |
| list sel colOfFiles|
|
|
859 |
|
|
860 |
list := self fileList.
|
|
861 |
colOfFiles := OrderedCollection new.
|
|
862 |
list isEmpty ifTrue:[ ^ colOfFiles].
|
|
863 |
sel := self treeSelectionHolder value.
|
|
864 |
sel isNil ifTrue:[ ^ colOfFiles].
|
|
865 |
|
|
866 |
sel do:[: index |
|
|
867 |
colOfFiles add:((list at:index) fileName)
|
|
868 |
].
|
|
869 |
^ colOfFiles.
|
|
870 |
!
|
|
871 |
|
|
872 |
getFirstDirectoryItemOfSelection
|
|
873 |
|
|
874 |
| sel dir |
|
|
875 |
sel := self getItemsForSelection.
|
|
876 |
sel isEmpty ifTrue:[ ^ nil].
|
|
877 |
^ dir := sel detect:[: el | el isDirectory ] ifNone:[nil].
|
|
878 |
!
|
|
879 |
|
|
880 |
getFirstDirectoryOfSelection
|
|
881 |
|
|
882 |
| sel dirItem |
|
|
883 |
sel := self getItemsForSelection.
|
|
884 |
sel isEmpty ifTrue:[ ^ nil].
|
|
885 |
dirItem := sel detect:[: el | el isDirectory ] ifNone:[nil].
|
|
886 |
dirItem isNil ifTrue:[^ nil].
|
|
887 |
^ dirItem fileName.
|
|
888 |
!
|
|
889 |
|
|
890 |
getItemsForSelection
|
|
891 |
|
|
892 |
| list sel colOfItems|
|
|
893 |
|
|
894 |
list := self fileList.
|
|
895 |
colOfItems := OrderedCollection new.
|
|
896 |
list isEmpty ifTrue:[ ^ colOfItems].
|
|
897 |
sel := self treeSelectionHolder value.
|
|
898 |
sel isNil ifTrue:[ ^ colOfItems].
|
|
899 |
|
|
900 |
sel do:[: index |
|
|
901 |
colOfItems add:(list at:index)
|
|
902 |
].
|
|
903 |
^ colOfItems.
|
|
904 |
!
|
|
905 |
|
|
906 |
masterIsFileBrowser
|
|
907 |
|
|
908 |
^ self masterApplication class = FileBrowserV2
|
|
909 |
!
|
|
910 |
|
|
911 |
selectedFileIsDirectoryAndNotRoot
|
|
912 |
|
|
913 |
| dir|
|
|
914 |
|
|
915 |
dir := self getFirstDirectoryOfSelection.
|
|
916 |
dir isNil ifTrue:[^ false].
|
|
917 |
^ [(dir asString) ~= (self rootHolder value)]
|
|
918 |
! !
|
|
919 |
|
|
920 |
!DirectoryTreeBrowser methodsFor:'startup & release'!
|
|
921 |
|
|
922 |
makeDependent
|
|
923 |
|
|
924 |
self currentFileNameHolder addDependent:self.
|
|
925 |
self notifyChannel addDependent:self.
|
|
926 |
self viewFilesInDirectoryTree addDependent:self.
|
|
927 |
self treeSelectionHolder addDependent:self.
|
|
928 |
self filterModel addDependent:self.
|
|
929 |
!
|
|
930 |
|
|
931 |
postBuildAsSubcanvasWith:aBuilder
|
|
932 |
|
|
933 |
super postBuildAsSubcanvasWith:aBuilder.
|
|
934 |
!
|
|
935 |
|
|
936 |
postBuildDirBrowser:aWidget
|
|
937 |
|
|
938 |
dirBrowser := aWidget scrolledView.
|
|
939 |
dirBrowser openEditorAction:[:ln :aGC| |field item filename newFileString rename newFilename|
|
|
940 |
item := self fileList at:ln.
|
|
941 |
|
|
942 |
item label isString ifFalse:[
|
|
943 |
field := nil
|
|
944 |
] ifTrue:[
|
|
945 |
field := EditField new.
|
|
946 |
field level:0.
|
|
947 |
field acceptOnReturn:true.
|
|
948 |
field acceptAction:[:x|
|
|
949 |
filename := item fileName.
|
|
950 |
newFileString := x at:1.
|
|
951 |
filename baseName = newFileString ifFalse:[
|
|
952 |
(self renameFile:filename to:newFileString update:false) ifTrue:[
|
|
953 |
newFilename := filename directory construct:newFileString.
|
|
954 |
item fileName:newFilename.
|
|
955 |
self updateAndSelect:(OrderedCollection with:newFilename).
|
|
956 |
].
|
|
957 |
].
|
|
958 |
aGC closeEditor.
|
|
959 |
].
|
|
960 |
field font:(aGC font).
|
|
961 |
field contents:(item label).
|
|
962 |
].
|
|
963 |
field
|
|
964 |
].
|
|
965 |
!
|
|
966 |
|
|
967 |
postBuildWith:aBuilder
|
|
968 |
|
|
969 |
super postBuildWith:aBuilder.
|
|
970 |
!
|
|
971 |
|
|
972 |
postOpenAsSubcanvasWith:aBuilder
|
|
973 |
|
|
974 |
self currentFileNameHolder changed.
|
|
975 |
self windowGroup addPreEventHook:self.
|
|
976 |
^ super postOpenAsSubcanvasWith:aBuilder.
|
|
977 |
!
|
|
978 |
|
|
979 |
postOpenWith:aBuilder
|
|
980 |
|
|
981 |
"
|
|
982 |
only invoked if the application not started from a master
|
|
983 |
"
|
|
984 |
self currentFileNameHolder changed.
|
|
985 |
self windowGroup addPreEventHook:self.
|
|
986 |
^ super postOpenWith:aBuilder
|
|
987 |
!
|
|
988 |
|
|
989 |
preBuildWith:aBuilder
|
|
990 |
|
|
991 |
self masterApplication isNil ifTrue:[
|
|
992 |
self masterApplication:nil.
|
|
993 |
].
|
|
994 |
^ super preBuildWith:aBuilder.
|
|
995 |
!
|
|
996 |
|
|
997 |
release
|
|
998 |
|
|
999 |
self fileList stopMonitoringTask.
|
|
1000 |
^ super release.
|
|
1001 |
! !
|
|
1002 |
|
|
1003 |
!DirectoryTreeBrowser methodsFor:'user actions'!
|
|
1004 |
|
|
1005 |
doCopy
|
|
1006 |
"copy current selected files/directories
|
|
1007 |
"
|
|
1008 |
|
|
1009 |
self copyFilesToClipBoard:self getFilesForSelection.
|
|
1010 |
!
|
|
1011 |
|
|
1012 |
doCut
|
|
1013 |
"cut current selected files/directories
|
|
1014 |
"
|
|
1015 |
self cutFilesToClipBoard:self getFilesForSelection.
|
|
1016 |
!
|
|
1017 |
|
|
1018 |
doDelete
|
|
1019 |
"delete current selected files/directories
|
|
1020 |
"
|
|
1021 |
|
|
1022 |
self deleteFiles:self getFilesForSelection.
|
|
1023 |
! !
|
|
1024 |
|
|
1025 |
!DirectoryTreeBrowser::DirTreeBrowserHFL methodsFor:'accessing'!
|
|
1026 |
|
|
1027 |
draggedItem:anItemOrNil
|
|
1028 |
" change the item icon ; return true if changed otherwise false"
|
|
1029 |
|
|
1030 |
|oldItem|
|
|
1031 |
|
|
1032 |
(anItemOrNil isNil or:[draggedItem ~~ anItemOrNil]) ifTrue:[
|
|
1033 |
oldItem := draggedItem.
|
|
1034 |
draggedItem := anItemOrNil.
|
|
1035 |
|
|
1036 |
oldItem ifNotNil:[ oldItem iconChanged ].
|
|
1037 |
draggedItem ifNotNil:[ draggedItem iconChanged ].
|
|
1038 |
^ true
|
|
1039 |
].
|
|
1040 |
^ false
|
|
1041 |
! !
|
|
1042 |
|
|
1043 |
!DirectoryTreeBrowser::DirTreeBrowserHFL methodsFor:'protocol'!
|
|
1044 |
|
|
1045 |
validateIcon:icon for:anItem
|
|
1046 |
|
|
1047 |
draggedItem == anItem ifTrue:[
|
|
1048 |
^ (FileBrowser iconForKeyMatching:#directoryOpenGray) ? icon.
|
|
1049 |
].
|
|
1050 |
^ icon
|
|
1051 |
! !
|
|
1052 |
|
|
1053 |
!DirectoryTreeBrowser class methodsFor:'documentation'!
|
|
1054 |
|
|
1055 |
version
|
3906
|
1056 |
^ '$Header: /cvs/stx/stx/libtool/DirectoryTreeBrowser.st,v 1.2 2002-09-27 12:04:22 penk Exp $'
|
3892
|
1057 |
! !
|