AbstractFileBrowser.st
changeset 6114 36fb19194510
parent 6113 74c98d26f00c
child 6116 acc7f6b44b4f
--- a/AbstractFileBrowser.st	Mon Oct 25 13:27:23 2004 +0200
+++ b/AbstractFileBrowser.st	Mon Oct 25 14:24:20 2004 +0200
@@ -144,12 +144,14 @@
 !AbstractFileBrowser class methodsFor:'accessing-bookmarks'!
 
 addBookmark:aDirectoryPath
-    |bookmarks idx|
+    "add aDirectoryPath to the list of our known bookmarks.
+     Do not add duplicates."
+
+    |bookmarks|
 
     bookmarks := self directoryBookmarks.
-    idx := bookmarks indexOf:aDirectoryPath.
-    idx == 0 ifTrue:[
-        bookmarks addLast:aDirectoryPath asFilename.
+    (bookmarks includes:aDirectoryPath) ifFalse:[
+        bookmarks add:aDirectoryPath asFilename.
     ].
 !
 
@@ -187,20 +189,15 @@
     |bookmarks s fileName|
 
     fileName := aFileNameOrString asFilename.
-    FileStream openErrorSignal catch:[
+    [
         s := fileName readStream.
-    ].
-    s isNil ifTrue:[
+    ] on:OpenError do:[:ex|
         ^ self.
     ].
 
     bookmarks := OrderedCollection new.
     [s atEnd] whileFalse:[
-        |line path|
-
-        line := s nextLine.
-        path := (Base64Coder decodingOf:line) asString.
-        bookmarks add:path.
+        bookmarks add:(Base64Coder decode:s nextLine) asString.
     ].
     s close.
 
@@ -232,23 +229,27 @@
 !
 
 saveBookmarksIn:aFileNameOrString
-    |bookmarks s fileName|
+    "save the bokmarks in aFileNameOrString.
+     Use Base64 coding"
+
+    |bookmarks bookmarkStream fileName coder|
 
     bookmarks := self directoryBookmarks.
-    bookmarks isEmptyOrNil ifTrue:[ ^ self].
 
     fileName := aFileNameOrString asFilename.
     fileName exists ifTrue:[
         fileName renameTo:(fileName withSuffix:'sav').
     ].
-    s := fileName writeStream.
+    bookmarkStream := fileName writeStream.
+
+    "save each bookmark in one line"
+    coder := (Base64Coder on:bookmarkStream) lineLimit:nil.
     bookmarks do:[:eachPath |
-        |absolutePath|
-
-        absolutePath := eachPath asFilename pathName.
-        s nextPutLine:(Base64Coder new lineLimit:nil; encodingOf:absolutePath).
-    ].
-    s close.
+        eachPath asFilename pathName acceptVisitor:coder.
+        coder flush.
+        bookmarkStream cr.
+    ].
+    bookmarkStream close.
 !
 
 saveBookmarksInDefaultBookmarksFile
@@ -6570,5 +6571,5 @@
 !AbstractFileBrowser class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/AbstractFileBrowser.st,v 1.270 2004-10-25 11:27:23 penk Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/AbstractFileBrowser.st,v 1.271 2004-10-25 12:24:20 stefan Exp $'
 ! !