FileOperation.st
changeset 4701 b30d103a8bc9
parent 4674 64a49fadc47e
child 4749 297a154b8cb7
equal deleted inserted replaced
4700:4d211e45f7b4 4701:b30d103a8bc9
    99 ! !
    99 ! !
   100 
   100 
   101 !FileOperation methodsFor:'dialogs'!
   101 !FileOperation methodsFor:'dialogs'!
   102 
   102 
   103 fileExistDialogForNewFile:newFile oldFile:oldFile withCancel:aBoolean
   103 fileExistDialogForNewFile:newFile oldFile:oldFile withCancel:aBoolean
   104     |msg|
   104     "return true, if the file should be moved/copied.
   105 
   105      Ask user if oldFile exists."
   106     newFile exists ifTrue:[
   106 
   107         msg := 'Overwrite %1 of %2 with size %3\with %4 of %5 and with size %6 ?'.
   107     |msg oldSize newSize sameContents|
   108         msg := AbstractFileBrowser classResources 
   108 
   109                 string:msg
   109     newFile exists ifFalse:[ ^ true ].
   110                 withArgs:(Array
   110     oldSize := oldFile fileSize.
   111                     with:newFile asString allBold
   111     newSize := newFile fileSize.
   112                     with:(newFile modificationTime printStringFormat:'%(Day)-%(mon)-%(year) %h:%m:%s')
   112 
   113                     with:newFile fileSize
   113     sameContents := oldSize = newSize and:[oldFile sameContentsAs:newFile].
   114                     with:oldFile asString 
   114 
   115                     with:(oldFile modificationTime printStringFormat:'%(Day)-%(mon)-%(year) %h:%m:%s')
   115     sameContents ifTrue:[
   116                     with:oldFile fileSize).
   116         msg := 'Overwrite existing file:\\  %1\    size: %3 of %2\\with (same contents):\\  %4\    size: %6 of %5'.
   117         msg := msg withCRs.
   117     ] ifFalse:[
   118 
   118         msg := 'Overwrite existing file:\\  %1\    size: %3 of %2\\with:\\  %4\    size: %6 of %5'.
   119         aBoolean ifTrue:[
   119     ].
   120             ^ Dialog confirmWithCancel:msg.
   120 
   121         ] ifFalse:[
   121     msg := AbstractFileBrowser classResources 
   122             ^ Dialog confirm:msg.
   122             stringWithCRs:msg
   123         ].
   123             withArgs:(Array
   124     ].
   124                 with:newFile asString allBold
   125     ^ true
   125                 with:(newFile modificationTime printStringFormat:'%(Day)-%(mon)-%(year) %h:%m:%s')
       
   126                 with:newSize
       
   127                 with:oldFile asString allBold 
       
   128                 with:(oldFile modificationTime printStringFormat:'%(Day)-%(mon)-%(year) %h:%m:%s')
       
   129                 with:oldSize).
       
   130 
       
   131     ^ Dialog confirm:(msg withCRs) withCancel:aBoolean.
   126 ! !
   132 ! !
   127 
   133 
   128 !FileOperation::Copy class methodsFor:'actions'!
   134 !FileOperation::Copy class methodsFor:'actions'!
   129 
   135 
   130 copyFile:aSourceFile to:aDestFile
   136 copyFile:aSourceFile to:aDestFile
   194 ! !
   200 ! !
   195 
   201 
   196 !FileOperation::Copy class methodsFor:'documentation'!
   202 !FileOperation::Copy class methodsFor:'documentation'!
   197 
   203 
   198 version
   204 version
   199     ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.29 2003-03-18 11:26:45 cg Exp $'
   205     ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.30 2003-03-21 13:21:35 cg Exp $'
   200 ! !
   206 ! !
   201 
   207 
   202 !FileOperation::Copy methodsFor:'accessing'!
   208 !FileOperation::Copy methodsFor:'accessing'!
   203 
   209 
   204 colOfCopiedFiles
   210 colOfCopiedFiles
   320                     fileString := newFile withoutSuffix baseName, self class copyMoveIfExistSuffixString, '.', suffix.
   326                     fileString := newFile withoutSuffix baseName, self class copyMoveIfExistSuffixString, '.', suffix.
   321                     newFile := aDirectory construct:fileString.
   327                     newFile := aDirectory construct:fileString.
   322                 ].
   328                 ].
   323             ] ifFalse:[
   329             ] ifFalse:[
   324                 overWriteWarning ifTrue:[
   330                 overWriteWarning ifTrue:[
   325                     askResult := (self fileExistDialogForNewFile:newFile oldFile:filename withCancel:true).
   331                     askResult := (self fileExistDialogForNewFile:newFile oldFile:filename withCancel:(aColOfSourceFiles size > 1)).
   326                     askResult isNil ifTrue:[
   332                     askResult isNil ifTrue:[
   327                         result := false.
   333                         result := false.
   328                         ^ self.
   334                         ^ self.
   329                     ]
   335                     ]
   330                 ]
   336                 ]
   398 ! !
   404 ! !
   399 
   405 
   400 !FileOperation::Create class methodsFor:'documentation'!
   406 !FileOperation::Create class methodsFor:'documentation'!
   401 
   407 
   402 version
   408 version
   403     ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.29 2003-03-18 11:26:45 cg Exp $'
   409     ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.30 2003-03-21 13:21:35 cg Exp $'
   404 ! !
   410 ! !
   405 
   411 
   406 !FileOperation::Create methodsFor:'accessing'!
   412 !FileOperation::Create methodsFor:'accessing'!
   407 
   413 
   408 createdFile
   414 createdFile
   644 ! !
   650 ! !
   645 
   651 
   646 !FileOperation::Delete class methodsFor:'documentation'!
   652 !FileOperation::Delete class methodsFor:'documentation'!
   647 
   653 
   648 version
   654 version
   649     ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.29 2003-03-18 11:26:45 cg Exp $'
   655     ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.30 2003-03-21 13:21:35 cg Exp $'
   650 ! !
   656 ! !
   651 
   657 
   652 !FileOperation::Delete methodsFor:'actions'!
   658 !FileOperation::Delete methodsFor:'actions'!
   653 
   659 
   654 deleteFile:aFileOrDirectory
   660 deleteFile:aFileOrDirectory
   678 !
   684 !
   679 
   685 
   680 deleteFiles:colOfFiles
   686 deleteFiles:colOfFiles
   681     "delete current selected files/directories
   687     "delete current selected files/directories
   682     "
   688     "
   683     |resources retVal ask size labels values fileTypeString|
   689     |resources retVal ask nFilesToDelete labels values fileTypeString|
   684 
   690 
   685     resources := AbstractFileBrowser classResources.
   691     resources := AbstractFileBrowser classResources.
   686 
   692 
   687     ask := true.
   693     ask := true.
   688     size := colOfFiles size.
   694     nFilesToDelete := colOfFiles size.
   689     colOfFiles do:[:filenameOrString |
   695     colOfFiles do:[:filenameOrString |
   690         |filename answer doDelete|
   696         |filename answer doDelete|
   691 
   697 
   692         filename := filenameOrString asFilename.
   698         filename := filenameOrString asFilename.
   693 
   699 
   699                 self warn:('%1 do not exist' bindWith:filename asString allBold).
   705                 self warn:('%1 do not exist' bindWith:filename asString allBold).
   700                 ^ self.
   706                 ^ self.
   701             ]
   707             ]
   702         ].
   708         ].
   703         ask ifTrue:[
   709         ask ifTrue:[
   704             size = 1 ifTrue:[
   710             nFilesToDelete = 1 ifTrue:[
   705                 labels := #('Cancel' 'No' 'Yes').
   711                 labels := #('No' 'Yes').
   706                 values := #(#cancel #no #yes).
   712                 values := #(#no #yes).
   707             ] ifFalse:[
   713             ] ifFalse:[
   708                 labels := #('Cancel' 'No' 'Yes' 'Yes to All' ).
   714                 labels := #('Cancel' 'No' 'Yes' 'Yes to All' ).
   709                 values := #(#cancel #no #yes #yesToAll).
   715                 values := #(#cancel #no #yes #yesToAll).
   710             ].
   716             ].
   711             retVal := Dialog 
   717             retVal := Dialog 
   712                 confirmWithCancel:(resources string:'Really delete %1%2 ?' 
   718                 confirmWithCancel:(resources 
   713                                                with:fileTypeString
   719                                     stringWithCRs:'Really delete\\  %1%2 ?' 
   714                                                with:(filename asString allBold))
   720                                     with:fileTypeString
       
   721                                     with:(filename asString allBold))
   715                            labels:(resources array:labels)
   722                            labels:(resources array:labels)
   716                            values:values
   723                            values:values
   717                           default:3.
   724                           default:(values indexOf:#no).
   718         ].
   725         ].
   719         retVal == #cancel ifTrue:[
   726         retVal == #cancel ifTrue:[
   720             ^ self.
   727             ^ self.
   721         ].
   728         ].
   722 
   729 
   814 ! !
   821 ! !
   815 
   822 
   816 !FileOperation::Move class methodsFor:'documentation'!
   823 !FileOperation::Move class methodsFor:'documentation'!
   817 
   824 
   818 version
   825 version
   819     ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.29 2003-03-18 11:26:45 cg Exp $'
   826     ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.30 2003-03-21 13:21:35 cg Exp $'
   820 ! !
   827 ! !
   821 
   828 
   822 !FileOperation::Move methodsFor:'accessing'!
   829 !FileOperation::Move methodsFor:'accessing'!
   823 
   830 
   824 colOfMovedFiles
   831 colOfMovedFiles
   926                     fileString := newFile baseName withoutSuffix, self class copyMoveIfExistSuffixString, '.', suffix.
   933                     fileString := newFile baseName withoutSuffix, self class copyMoveIfExistSuffixString, '.', suffix.
   927                     newFile := aDirectory construct:fileString.
   934                     newFile := aDirectory construct:fileString.
   928                 ].
   935                 ].
   929             ] ifFalse:[
   936             ] ifFalse:[
   930                 overWriteWarning ifTrue:[
   937                 overWriteWarning ifTrue:[
   931                     askResult := self fileExistDialogForNewFile:newFile oldFile:filename withCancel:true.
   938                     askResult := self fileExistDialogForNewFile:newFile oldFile:filename withCancel:(aColOfSourceFiles size > 1).
   932                     askResult isNil ifTrue:[
   939                     askResult isNil ifTrue:[
   933                         result := false.
   940                         result := false.
   934                         ^ self.
   941                         ^ self.
   935                     ]
   942                     ]
   936                 ]
   943                 ]
   984 ! !
   991 ! !
   985 
   992 
   986 !FileOperation::Rename class methodsFor:'documentation'!
   993 !FileOperation::Rename class methodsFor:'documentation'!
   987 
   994 
   988 version
   995 version
   989     ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.29 2003-03-18 11:26:45 cg Exp $'
   996     ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.30 2003-03-21 13:21:35 cg Exp $'
   990 ! !
   997 ! !
   991 
   998 
   992 !FileOperation::Rename methodsFor:'accessing'!
   999 !FileOperation::Rename methodsFor:'accessing'!
   993 
  1000 
   994 renamedFiles
  1001 renamedFiles
  1076 ! !
  1083 ! !
  1077 
  1084 
  1078 !FileOperation class methodsFor:'documentation'!
  1085 !FileOperation class methodsFor:'documentation'!
  1079 
  1086 
  1080 version
  1087 version
  1081     ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.29 2003-03-18 11:26:45 cg Exp $'
  1088     ^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.30 2003-03-21 13:21:35 cg Exp $'
  1082 ! !
  1089 ! !