*** empty log message ***
authorClaus Gittinger <cg@exept.de>
Tue, 18 May 2004 16:12:36 +0200
changeset 5862 41b855c4028e
parent 5861 6122b86f2aa6
child 5863 e31e066a41d9
*** empty log message ***
FileOperation.st
--- a/FileOperation.st	Tue May 18 15:31:10 2004 +0200
+++ b/FileOperation.st	Tue May 18 16:12:36 2004 +0200
@@ -100,11 +100,21 @@
 
 !FileOperation methodsFor:'dialogs'!
 
-fileExistDialogForNewFile:newFile oldFile:oldFile withCancel:aBoolean
+fileExistDialogForNewFile:newFile oldFile:oldFile withCancel:withCancel
     "return true, if the file should be moved/copied.
      Ask user if oldFile exists."
 
-    |msg oldSize newSize sameContents|
+    ^ self fileExistDialogForNewFile:newFile oldFile:oldFile withCancel:withCancel withRemoveIfSame:false.
+!
+
+fileExistDialogForNewFile:newFile oldFile:oldFile withCancel:withCancel withRemoveIfSame:withRemoveIfSame
+    "return true, if the file should be moved/copied.
+     If oldFile exists, ask user.
+     If withRemoveIfSame is true, two additional possible values are returned:
+        #removeSource and #removeDestination.
+    "
+
+    |msg oldSize newSize sameContents resources|
 
     newFile exists ifFalse:[ ^ true ].
     oldSize := oldFile fileSize.
@@ -113,12 +123,13 @@
     sameContents := oldSize = newSize and:[oldFile sameContentsAs:newFile].
 
     sameContents ifTrue:[
-        msg := 'Overwrite existing file:\\  %1\    size: %3 of %2\\with (same contents):\\  %4\    size: %6 of %5'.
+        msg := 'Overwrite existing destination file:\\  %1\    size: %3 of %2\\with source (same contents):\\  %4\    size: %6 of %5'.
     ] ifFalse:[
-        msg := 'Overwrite existing file:\\  %1\    size: %3 of %2\\with:\\  %4\    size: %6 of %5'.
+        msg := 'Overwrite existing destination file:\\  %1\    size: %3 of %2\\with source:\\  %4\    size: %6 of %5'.
     ].
 
-    msg := AbstractFileBrowser classResources 
+    resources := AbstractFileBrowser classResources.
+    msg := resources 
             stringWithCRs:msg
             withArgs:(Array
                 with:newFile asString allBold
@@ -128,7 +139,18 @@
                 with:(oldFile modificationTime printStringFormat:'%(Day)-%(mon)-%(year) %h:%m:%s')
                 with:oldSize).
 
-    ^ Dialog confirm:msg withCancel:aBoolean.
+    (sameContents and:[withRemoveIfSame]) ifTrue:[
+        ^ OptionBox  
+                  request:msg
+                  label:(resources string:'Overwrite existing file')
+                  image:(YesNoBox iconBitmap)
+                  buttonLabels:(resources array:( #('No' 'Remove Source' 'Remove Destination' 'Yes' ) , (withCancel ifTrue:[#('Cancel')] ifFalse:[#()])))
+                  values:#( false #removeSource #removeDestination true )
+                  default:#removeSource
+                  onCancel:nil.
+    ] ifFalse:[
+        ^ Dialog confirm:msg withCancel:withCancel.
+    ].
 ! !
 
 !FileOperation::Copy class methodsFor:'actions'!
@@ -202,7 +224,7 @@
 !FileOperation::Copy class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.52 2004-05-17 17:10:31 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.53 2004-05-18 14:12:36 cg Exp $'
 ! !
 
 !FileOperation::Copy methodsFor:'accessing'!
@@ -262,7 +284,7 @@
             ].
         ] ifFalse:[
             overWriteWarning ifTrue:[
-                (self fileExistDialogForNewFile:newFile oldFile:aSourceFile withCancel:false) ifFalse:[ 
+                (self fileExistDialogForNewFile:newFile oldFile:aSourceFile withCancel:false withRemoveIfSame:false) ifFalse:[ 
                     result := false.
                     ^ self.
                 ]
@@ -280,8 +302,7 @@
         ^ self
     ] do:[
         sourceIsDirectory ifTrue:[
-            OperatingSystem recursiveCopyDirectory:(aSourceFile pathName) 
-                                                to:(newFile pathName).
+            OperatingSystem recursiveCopyDirectory:(aSourceFile pathName) to:(newFile pathName).
         ] ifFalse:[
             aSourceFile copyTo:newFile.
         ].
@@ -331,7 +352,7 @@
                 ].
             ] ifFalse:[
                 overWriteWarning ifTrue:[
-                    overWriteExisting := (self fileExistDialogForNewFile:newFile oldFile:filename withCancel:(aColOfSourceFiles size > 1)).
+                    overWriteExisting := (self fileExistDialogForNewFile:newFile oldFile:filename withCancel:(aColOfSourceFiles size > 1) withRemoveIfSame:false).
                     overWriteExisting isNil ifTrue:[
                         " abort pressed "
                         result := false.
@@ -412,7 +433,7 @@
 !FileOperation::Create class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.52 2004-05-17 17:10:31 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.53 2004-05-18 14:12:36 cg Exp $'
 ! !
 
 !FileOperation::Create methodsFor:'accessing'!
@@ -685,7 +706,7 @@
 !FileOperation::Delete class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.52 2004-05-17 17:10:31 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.53 2004-05-18 14:12:36 cg Exp $'
 ! !
 
 !FileOperation::Delete methodsFor:'actions'!
@@ -890,7 +911,7 @@
 !FileOperation::Move class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.52 2004-05-17 17:10:31 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.53 2004-05-18 14:12:36 cg Exp $'
 ! !
 
 !FileOperation::Move methodsFor:'accessing'!
@@ -918,7 +939,7 @@
 
 moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning moveFileIfSame:move
 
-    |newFile fileString targetDirectory targetIsDirectory suffix|
+    |newFile fileString targetDirectory targetIsDirectory suffix doMove|
 
     targetIsDirectory := aDestFile isDirectory.
     targetIsDirectory ifTrue:[
@@ -943,13 +964,25 @@
             ].
         ] ifFalse:[
             overWriteWarning ifTrue:[
-                (self fileExistDialogForNewFile:newFile oldFile:aSourceFile withCancel:false) ifFalse:[ 
+                doMove := self fileExistDialogForNewFile:newFile oldFile:aSourceFile withCancel:false withRemoveIfSame:true.
+                doMove == #removeSource ifTrue:[ 
+                    self halt.
+                    result := false.
+                    ^ self.
+                ].
+                doMove == #removeDestination ifTrue:[ 
+                    self halt.
                     result := false.
                     ^ self.
-                ]
-            ] ifFalse:[
+                ].
+                doMove == true ifFalse:[ 
                     result := false.
                     ^ self.
+                ].
+
+            ] ifFalse:[
+                result := false.
+                ^ self.
             ]
         ].
     ].
@@ -978,7 +1011,7 @@
 
 moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning moveFileIfSame:move
 
-    |newFile suffix fileString doMove|
+    |newFile suffix fileString doMove doRemoveSource doRemoveDestination|
 
     aDirectory exists ifFalse:[
         (Dialog confirm:(FileBrowser classResources 
@@ -1005,6 +1038,9 @@
         newFile := aDirectory construct:filename baseName.
 
         doMove := true.
+        doRemoveSource := false.
+        doRemoveDestination := false.
+
         (newFile exists) ifTrue:[
             ((newFile asString = filename asString) and:[move]) ifTrue:[
                 [newFile exists] whileTrue:[
@@ -1014,29 +1050,50 @@
                 ].
             ] ifFalse:[
                 overWriteWarning ifTrue:[
-                    doMove := self fileExistDialogForNewFile:newFile oldFile:filename withCancel:(aColOfSourceFiles size > 1).
-                    doMove isNil ifTrue:[
+                    doMove := self fileExistDialogForNewFile:newFile oldFile:filename withCancel:(aColOfSourceFiles size > 1) withRemoveIfSame:true.
+                    doMove isNil ifTrue:[   "/ cancel
                         result := false.
                         ^ self.
+                    ].
+                    (doMove == #removeSource) ifTrue:[
+                        doRemoveSource := true.
+                        doMove := false
+                    ] ifFalse:[ 
+                        (doMove == #removeDestination) ifTrue:[
+                            doRemoveDestination := true.
+                            doMove := false
+                        ]
                     ]
                 ]
             ].
         ].
 
-        doMove ifTrue:[
+        (doMove or:[doRemoveSource or:[doRemoveDestination]]) ifTrue:[
             Error handle:[:ex|
                 "was not able to copy it"
+                |descriptionString|
+
                 result := false.
-                self errorString:(' Error in Move-File Operation:', ex description asString).
+                descriptionString := ex description asString.
+                self errorString:(' Error in Move-File Operation:', descriptionString).
                 ( Dialog 
-                    confirm:(' Error in Move-File Operation: ', ex description asString) 
+                    confirm:(' Error in Move-File Operation: ', descriptionString) 
                     title:'Move'
                     yesLabel:'Continue' 
-                    noLabel:'Abort') ifFalse:[
+                    noLabel:'Abort'
+                ) ifFalse:[
                     ^ self.
                 ].
             ] do:[
-                filename moveTo:newFile.
+                doRemoveSource ifTrue:[
+                    filename remove
+                ] ifFalse:[
+                    doRemoveDestination ifTrue:[
+                        newFile remove
+                    ] ifFalse:[
+                        filename moveTo:newFile.
+                    ]
+                ]
             ].
             self colOfMovedFiles add:filename
         ]
@@ -1072,7 +1129,7 @@
 !FileOperation::Rename class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.52 2004-05-17 17:10:31 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.53 2004-05-18 14:12:36 cg Exp $'
 ! !
 
 !FileOperation::Rename methodsFor:'accessing'!
@@ -1187,5 +1244,5 @@
 !FileOperation class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.52 2004-05-17 17:10:31 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.53 2004-05-18 14:12:36 cg Exp $'
 ! !