FileSelectionTree.st
changeset 812 02765a35b0c3
parent 791 59f9fa223b0e
child 836 f746a95f32b5
--- a/FileSelectionTree.st	Mon Mar 09 17:08:44 1998 +0100
+++ b/FileSelectionTree.st	Mon Mar 09 17:09:03 1998 +0100
@@ -70,11 +70,13 @@
     scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top.
     scr := scr scrolledView.
 
-    scr directory:Filename currentDirectory.
+    scr directory:'/'.
+    scr showDirectoryIndicator:true.
+    scr showRoot:false.
+    scr showLines:false.
+    scr allowDrag:true.
+    scr multipleSelectOk:true.
 
-    scr action:[:anIndex| Transcript showCR:anIndex.
-                          Transcript showCR:scr selectedPathname.
-               ].
     top open
                                                                         [exEnd]
 
@@ -285,6 +287,7 @@
                                                                         [exEnd]
 "
 
+
 ! !
 
 !FileSelectionTree class methodsFor:'constants'!
@@ -304,13 +307,17 @@
     "
     |oldSel child loc oldPath oldFile newFile newPath node idx|
 
-    (     aPathname notNil
-     and:[(newFile := aPathname asFilename) isDirectory
-     and:[(oldPath := self directory) notNil]]
-    ) ifFalse:[
-        ^ self directory:aPathname
+    newFile := self makeLegalFilename:aPathname.
+    oldPath := self directory.
+
+    (newFile notNil and:[newFile isDirectory and:[oldPath notNil]]) ifFalse:[
+        ^ self directory:newFile
     ].
-    newPath := newFile pathName.
+
+    (newPath := newFile pathName) = oldPath ifTrue:[
+        ^ self
+    ].
+
     oldFile := oldPath asFilename.
     oldSel  := self selectedNode.
 
@@ -343,7 +350,20 @@
             oldPath := oldFile pathName.
         ]
     ].
-    selection := nil.
+
+    node children size == 0 ifTrue:[
+        oldSel := node.
+
+        (node := node parent) isNil ifTrue:[
+            ^ self directory:newFile
+        ]
+    ] ifFalse:[
+        node isExpandable ifTrue:[
+            ^ self directory:newFile
+        ]
+    ].
+
+    selection := nil.        
     node parent:nil.
     model root:node.
     self  setSelection:(self indexOfNode:oldSel).
@@ -371,8 +391,9 @@
     |root path|
 
     model selection:(selection := nil).
+    path := self makeLegalFilename:aPath.
 
-    (aPath notNil and:[(path := aPath asFilename) isDirectory]) ifTrue:[
+    (path notNil and:[path isDirectory and:[path isExecutable]]) ifTrue:[
         root := self itemClass pathName:path.
         model root:root.
         model expand:root.
@@ -452,6 +473,17 @@
     ]
 ! !
 
+!FileSelectionTree methodsFor:'drag & drop'!
+
+dragObjectForNode:aNode
+    "returns the dragable object for a node; could be redefined in subclass
+    "
+    ^ DropObject new:(aNode contents)
+
+
+
+! !
+
 !FileSelectionTree methodsFor:'initialization'!
 
 destroy
@@ -584,6 +616,41 @@
 
 !FileSelectionTree methodsFor:'private'!
 
+makeLegalFilename:aFile
+    |filename separator sepSize pathName pthSize|
+
+    aFile isNil ifTrue:[
+        ^ nil
+    ].
+
+    (filename := aFile asFilename) exists ifFalse:[
+        ^ nil
+    ].
+
+    filename isDirectory ifFalse:[
+        ^ filename
+    ].
+    separator := Filename separator.
+    pathName  := filename pathName.
+
+    (pathName endsWith:separator) ifFalse:[
+        ^ filename
+    ].
+    sepSize := (separator size) max:1.
+    pthSize := pathName size.
+
+    pthSize == sepSize ifTrue:[
+        ^ filename
+    ].
+    pathName := pathName copyFrom:1 to:(pthSize - sepSize).
+    filename := pathName asFilename.
+
+    filename isDirectory ifTrue:[
+        ^ filename
+    ].
+    ^ aFile asFilename
+!
+
 monitorCycle
     "run monitor cycle
     "
@@ -711,5 +778,5 @@
 !FileSelectionTree class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/FileSelectionTree.st,v 1.12 1998-02-26 02:27:42 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/FileSelectionTree.st,v 1.13 1998-03-09 16:09:03 ca Exp $'
 ! !