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 |
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 ] |
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 |
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 ] |