FilenameWidgetWithHistory.st
changeset 3594 8bdad6d9c51a
parent 3593 f11c5a41d4a9
child 3700 fada057195d0
--- a/FilenameWidgetWithHistory.st	Wed Nov 12 14:11:36 2008 +0100
+++ b/FilenameWidgetWithHistory.st	Wed Nov 12 14:44:10 2008 +0100
@@ -13,7 +13,7 @@
 
 SimpleView subclass:#FilenameWidgetWithHistory
 	instanceVariableNames:'fileNameEntryField browseButton history directoriesOnly filesOnly
-		dialogTitle'
+		dialogTitle initialDirectoryHolder'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Views-Interactors'
@@ -115,6 +115,12 @@
     history := aList
 !
 
+initialDirectoryHolder
+    "can be used to force the file-dialog into some initial directory"
+
+    ^ initialDirectoryHolder
+!
+
 model
     ^ fileNameEntryField model
 !
@@ -178,6 +184,7 @@
     super initialize.
 
     directoriesOnly := filesOnly := false.
+    initialDirectoryHolder := nil asValue.
 
     fileNameEntryField := FilenameComboBoxView in:self.
     fileNameEntryField layout:(LayoutFrame
@@ -225,7 +232,7 @@
 !
 
 browseForFileOrDirectory
-    |dir|
+    |path |
 
     Dialog aboutToOpenBoxNotificationSignal handle:[:ex |
         |dialog|
@@ -234,7 +241,7 @@
         dialog perform:#browseVisibleHolder with:true ifNotUnderstood:[].
         ex proceed.
     ] do:[
-        |title|
+        |title defaultPath defaultDir|
 
         title := dialogTitle notNil 
                     ifTrue:[ dialogTitle ]
@@ -246,13 +253,22 @@
                                     ifTrue:[ resources string:'Select File' ]
                                     ifFalse:[ resources string:'Select Path' ]]].
 
-        dir := Dialog 
+        defaultPath := self model value.
+        defaultPath notNil ifTrue:[
+            defaultDir := defaultPath asFilename directory.
+        ] ifFalse:[     
+            defaultDir := initialDirectoryHolder value.
+        ].
+        path := Dialog 
                 requestFileName:title
-                default:(self model value ? '.' asFilename pathName).
+                default:defaultPath
+                fromDirectory:defaultDir.
     ].
-    dir isEmptyOrNil ifTrue:[ ^ self ].
+    path isEmptyOrNil ifTrue:[ ^ self ].
 
-    self model value:dir.
+    initialDirectoryHolder value:path asFilename directory.
+    "/ lastDirectoryHolder value:path directory.
+    self model value:path.
 
     "Modified: / 02-10-2006 / 14:45:54 / cg"
 ! !
@@ -260,5 +276,5 @@
 !FilenameWidgetWithHistory class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/FilenameWidgetWithHistory.st,v 1.11 2008-11-12 13:11:36 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/FilenameWidgetWithHistory.st,v 1.12 2008-11-12 13:44:10 cg Exp $'
 ! !