author | Claus Gittinger <cg@exept.de> |
Mon, 13 Dec 2004 11:46:46 +0100 | |
changeset 6150 | 5028485a29c6 |
parent 6088 | 486567591821 |
child 6151 | baba7a7d54b6 |
permissions | -rw-r--r-- |
3841 | 1 |
"{ Package: 'stx:libtool2' }" |
2 |
||
3 |
Object subclass:#FileOperation |
|
3975
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
4 |
instanceVariableNames:'errorString result' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
5 |
classVariableNames:'' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
6 |
poolDictionaries:'' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
7 |
category:'Interface-Support' |
3841 | 8 |
! |
9 |
||
3842 | 10 |
FileOperation subclass:#Copy |
3975
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
11 |
instanceVariableNames:'colOfCopiedFiles' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
12 |
classVariableNames:'' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
13 |
poolDictionaries:'' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
14 |
privateIn:FileOperation |
3842 | 15 |
! |
16 |
||
17 |
FileOperation subclass:#Create |
|
3975
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
18 |
instanceVariableNames:'createdFile' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
19 |
classVariableNames:'LastCreatedDirectory LastCreatedFile' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
20 |
poolDictionaries:'' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
21 |
privateIn:FileOperation |
3842 | 22 |
! |
23 |
||
24 |
FileOperation subclass:#Delete |
|
3975
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
25 |
instanceVariableNames:'fileName' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
26 |
classVariableNames:'' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
27 |
poolDictionaries:'' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
28 |
privateIn:FileOperation |
3842 | 29 |
! |
30 |
||
31 |
FileOperation subclass:#Move |
|
3975
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
32 |
instanceVariableNames:'colOfMovedFiles' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
33 |
classVariableNames:'' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
34 |
poolDictionaries:'' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
35 |
privateIn:FileOperation |
3842 | 36 |
! |
37 |
||
38 |
FileOperation subclass:#Rename |
|
3975
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
39 |
instanceVariableNames:'renamedFiles' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
40 |
classVariableNames:'' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
41 |
poolDictionaries:'' |
dcaac82381dc
share goodRenameDefault code with FileBrowser
Claus Gittinger <cg@exept.de>
parents:
3877
diff
changeset
|
42 |
privateIn:FileOperation |
3842 | 43 |
! |
44 |
||
3841 | 45 |
|
5961 | 46 |
!FileOperation class methodsFor:'actions'! |
47 |
||
48 |
copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarningBoolean copyFileIfSame:copyIfSameBoolean |
|
49 |
^ Copy |
|
50 |
copyFile:aSourceFile to:aDestFile |
|
51 |
withOverWriteWarning:overWriteWarningBoolean |
|
52 |
copyFileIfSame:copyIfSameBoolean |
|
53 |
! |
|
54 |
||
55 |
copyFiles:aColOfSourceFiles to:aDirectory |
|
56 |
^ Copy copyFiles:aColOfSourceFiles to:aDirectory |
|
57 |
! |
|
58 |
||
59 |
createDirectoryIn:aDirectory |
|
60 |
^ Create createDirectoryIn:aDirectory |
|
61 |
! |
|
62 |
||
63 |
createDirectoryIn:aDirectory initialAnswer:defaultAnswer |
|
64 |
^ Create createDirectoryIn:aDirectory initialAnswer:defaultAnswer |
|
65 |
! |
|
66 |
||
67 |
createFileIn:aDirectory |
|
68 |
^ Create createFileIn:aDirectory |
|
69 |
! |
|
70 |
||
71 |
createHardLinkIn:dir |
|
72 |
^ Create createHardLinkIn:dir |
|
73 |
! |
|
74 |
||
75 |
createSoftLinkIn:dir |
|
76 |
^ Create createSoftLinkIn:dir |
|
77 |
! |
|
78 |
||
79 |
deleteFiles:colOfFiles confirm:confirm |
|
80 |
^ Delete deleteFiles:colOfFiles confirm:confirm |
|
81 |
! |
|
82 |
||
83 |
moveFile:aSourceFile to:aDestFile |
|
84 |
^ Move |
|
85 |
moveFile:aSourceFile to:aDestFile |
|
86 |
! |
|
87 |
||
88 |
moveFiles:aCollectionOfFiles to:aDestDirectory |
|
89 |
^ Move |
|
90 |
moveFiles:aCollectionOfFiles to:aDestDirectory |
|
91 |
! |
|
92 |
||
93 |
renameFile:filename to:newFileString |
|
94 |
^ Rename |
|
95 |
renameFile:filename to:newFileString |
|
96 |
! |
|
97 |
||
98 |
renameFiles:aCollectionofFilenames |
|
99 |
^ Rename |
|
100 |
renameFiles:aCollectionofFilenames |
|
101 |
! ! |
|
102 |
||
3841 | 103 |
!FileOperation class methodsFor:'defaults'! |
104 |
||
105 |
copyMoveIfExistSuffixString |
|
106 |
||
107 |
^ '.copy' |
|
108 |
! ! |
|
109 |
||
110 |
!FileOperation methodsFor:'accessing'! |
|
111 |
||
112 |
errorString |
|
113 |
"return the value of the static variable 'ErrorString' (automatically generated)" |
|
114 |
||
115 |
^ errorString |
|
116 |
! |
|
117 |
||
118 |
errorString:something |
|
119 |
"set the value of the static variable 'ErrorString' (automatically generated)" |
|
120 |
||
121 |
errorString := something. |
|
122 |
! |
|
123 |
||
124 |
result |
|
125 |
"return the value of the instance variable 'result' (automatically generated)" |
|
126 |
||
127 |
^ result |
|
128 |
! |
|
129 |
||
130 |
result:something |
|
131 |
"set the value of the instance variable 'result' (automatically generated)" |
|
132 |
||
133 |
result := something. |
|
134 |
! ! |
|
135 |
||
136 |
!FileOperation methodsFor:'dialogs'! |
|
137 |
||
5862 | 138 |
fileExistDialogForNewFile:newFile oldFile:oldFile withCancel:withCancel |
4701 | 139 |
"return true, if the file should be moved/copied. |
140 |
Ask user if oldFile exists." |
|
141 |
||
5862 | 142 |
^ self fileExistDialogForNewFile:newFile oldFile:oldFile withCancel:withCancel withRemoveIfSame:false. |
143 |
! |
|
144 |
||
145 |
fileExistDialogForNewFile:newFile oldFile:oldFile withCancel:withCancel withRemoveIfSame:withRemoveIfSame |
|
146 |
"return true, if the file should be moved/copied. |
|
147 |
If oldFile exists, ask user. |
|
148 |
If withRemoveIfSame is true, two additional possible values are returned: |
|
149 |
#removeSource and #removeDestination. |
|
150 |
" |
|
151 |
||
5888 | 152 |
|msg oldSize newSize sameContents resources sourceType destType| |
4701 | 153 |
|
154 |
newFile exists ifFalse:[ ^ true ]. |
|
155 |
oldSize := oldFile fileSize. |
|
156 |
newSize := newFile fileSize. |
|
157 |
||
5888 | 158 |
sameContents := false. |
159 |
||
160 |
newFile isDirectory ifTrue:[ |
|
161 |
oldFile isDirectory ifTrue:[ |
|
162 |
"/ could (should?) recursively look for same contents here... |
|
163 |
]. |
|
164 |
] ifFalse:[ |
|
165 |
oldFile isDirectory ifFalse:[ |
|
166 |
sameContents := oldSize = newSize and:[oldFile sameContentsAs:newFile]. |
|
167 |
] |
|
168 |
]. |
|
169 |
||
170 |
"/ for now: |
|
171 |
oldFile isDirectory ~~ newFile isDirectory ifTrue:[ |
|
172 |
Dialog warn:(resources string:'Will not overwrite directory with file and vice versa.'). |
|
173 |
^ false. |
|
174 |
]. |
|
175 |
||
176 |
sourceType := newFile isDirectory ifTrue:'directory' ifFalse:'file'. |
|
177 |
destType := oldFile isDirectory ifTrue:'directory' ifFalse:'file'. |
|
3841 | 178 |
|
4701 | 179 |
sameContents ifTrue:[ |
5888 | 180 |
msg := 'Overwrite existing destination %7:\\ %1\ size: %3 of %2\\with source (same contents):\\ %4\ size: %6 of %5'. |
4701 | 181 |
] ifFalse:[ |
5888 | 182 |
msg := 'Overwrite existing destination %7:\\ %1\ size: %3 of %2\\with source:\\ %4\ size: %6 of %5'. |
4701 | 183 |
]. |
4587 | 184 |
|
5862 | 185 |
resources := AbstractFileBrowser classResources. |
186 |
msg := resources |
|
4701 | 187 |
stringWithCRs:msg |
188 |
withArgs:(Array |
|
189 |
with:newFile asString allBold |
|
190 |
with:(newFile modificationTime printStringFormat:'%(Day)-%(mon)-%(year) %h:%m:%s') |
|
191 |
with:newSize |
|
192 |
with:oldFile asString allBold |
|
193 |
with:(oldFile modificationTime printStringFormat:'%(Day)-%(mon)-%(year) %h:%m:%s') |
|
5888 | 194 |
with:oldSize |
195 |
with:destType). |
|
4701 | 196 |
|
5862 | 197 |
(sameContents and:[withRemoveIfSame]) ifTrue:[ |
198 |
^ OptionBox |
|
199 |
request:msg |
|
200 |
label:(resources string:'Overwrite existing file') |
|
201 |
image:(YesNoBox iconBitmap) |
|
202 |
buttonLabels:(resources array:( #('No' 'Remove Source' 'Remove Destination' 'Yes' ) , (withCancel ifTrue:[#('Cancel')] ifFalse:[#()]))) |
|
203 |
values:#( false #removeSource #removeDestination true ) |
|
204 |
default:#removeSource |
|
205 |
onCancel:nil. |
|
206 |
] ifFalse:[ |
|
207 |
^ Dialog confirm:msg withCancel:withCancel. |
|
208 |
]. |
|
3841 | 209 |
! ! |
210 |
||
3842 | 211 |
!FileOperation::Copy class methodsFor:'actions'! |
212 |
||
213 |
copyFile:aSourceFile to:aDestFile |
|
214 |
"delete current selected files/directories |
|
215 |
" |
|
216 |
||
217 |
|instance| |
|
218 |
||
219 |
instance := self new. |
|
220 |
instance copyFile:aSourceFile to:aDestFile. |
|
221 |
^ instance |
|
222 |
! |
|
223 |
||
224 |
copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning |
|
225 |
"delete current selected files/directories |
|
226 |
" |
|
227 |
||
228 |
|instance| |
|
229 |
||
230 |
instance := self new. |
|
231 |
instance copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning. |
|
232 |
^ instance |
|
233 |
! |
|
234 |
||
5961 | 235 |
copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarningBoolean copyFileIfSame:copyIfSameBoolean |
3842 | 236 |
"delete current selected files/directories |
237 |
" |
|
238 |
||
239 |
|instance| |
|
240 |
||
241 |
instance := self new. |
|
5961 | 242 |
instance copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarningBoolean copyFileIfSame:copyIfSameBoolean. |
3842 | 243 |
^ instance |
244 |
! |
|
245 |
||
246 |
copyFiles:aColOfSourceFiles to:aDirectory |
|
247 |
"delete current selected files/directories |
|
248 |
" |
|
249 |
||
250 |
|instance| |
|
251 |
||
252 |
instance := self new. |
|
253 |
instance copyFiles:aColOfSourceFiles to:aDirectory. |
|
254 |
^ instance |
|
255 |
! |
|
256 |
||
257 |
copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning |
|
258 |
"delete current selected files/directories |
|
259 |
" |
|
260 |
||
261 |
|instance| |
|
262 |
||
263 |
instance := self new. |
|
264 |
instance copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning. |
|
265 |
^ instance |
|
266 |
! |
|
267 |
||
268 |
copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning copyFileIfSame:copy |
|
269 |
"delete current selected files/directories |
|
270 |
" |
|
271 |
||
272 |
|instance| |
|
273 |
||
274 |
instance := self new. |
|
275 |
instance copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning copyFileIfSame:copy. |
|
276 |
^ instance |
|
277 |
! ! |
|
278 |
||
279 |
!FileOperation::Copy methodsFor:'accessing'! |
|
280 |
||
281 |
colOfCopiedFiles |
|
282 |
"return the value of the instance variable 'colOfCopiedFiles' (automatically generated)" |
|
283 |
||
284 |
colOfCopiedFiles isNil ifTrue:[ |
|
285 |
colOfCopiedFiles := OrderedCollection new. |
|
286 |
]. |
|
287 |
^ colOfCopiedFiles |
|
288 |
! ! |
|
289 |
||
290 |
!FileOperation::Copy methodsFor:'actions'! |
|
291 |
||
292 |
copyFile:aSourceFile to:aDestFile |
|
293 |
"defete current selected files/directories |
|
294 |
" |
|
295 |
||
296 |
self copyFile:aSourceFile to:aDestFile withOverWriteWarning:true |
|
297 |
! |
|
298 |
||
299 |
copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning |
|
300 |
"copy to |
|
301 |
" |
|
302 |
||
303 |
self copyFile:aSourceFile to:aDestFile withOverWriteWarning:true copyFileIfSame:true |
|
304 |
! |
|
305 |
||
5961 | 306 |
copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarningBoolean copyFileIfSame:copyIfSameBoolean |
3842 | 307 |
"copy to |
308 |
" |
|
309 |
||
310 |
|newFile fileString targetDirectory targetIsDirectory sourceIsDirectory suffix| |
|
311 |
||
312 |
sourceIsDirectory := aSourceFile isDirectory. |
|
313 |
targetIsDirectory := aDestFile isDirectory. |
|
314 |
targetIsDirectory ifTrue:[ |
|
315 |
targetDirectory := aDestFile. |
|
316 |
newFile := aDestFile construct:(aSourceFile baseName). |
|
317 |
] ifFalse:[ |
|
318 |
targetDirectory := aDestFile directory. |
|
319 |
newFile := aDestFile. |
|
320 |
]. |
|
321 |
"/ do not copy if destination directory doest exist. |
|
322 |
(targetDirectory exists not) ifTrue:[ |
|
3863 | 323 |
Dialog warn:'cant copy to not existing directory ', targetDirectory asString. |
3842 | 324 |
result := false. |
325 |
^ self |
|
326 |
]. |
|
327 |
(newFile exists) ifTrue:[ |
|
5961 | 328 |
((newFile asString = aSourceFile asString) and:[copyIfSameBoolean]) ifTrue:[ |
3842 | 329 |
[newFile exists] whileTrue:[ |
330 |
suffix := newFile suffix. |
|
331 |
fileString := newFile baseName withoutSuffix, self class copyMoveIfExistSuffixString, '.', suffix. |
|
332 |
newFile := targetDirectory construct:fileString. |
|
333 |
]. |
|
334 |
] ifFalse:[ |
|
5961 | 335 |
overWriteWarningBoolean ifTrue:[ |
5862 | 336 |
(self fileExistDialogForNewFile:newFile oldFile:aSourceFile withCancel:false withRemoveIfSame:false) ifFalse:[ |
3842 | 337 |
result := false. |
338 |
^ self. |
|
339 |
] |
|
340 |
] ifFalse:[ |
|
341 |
result := false. |
|
342 |
^ self. |
|
343 |
] |
|
344 |
]. |
|
345 |
]. |
|
346 |
Error handle:[:ex| |
|
347 |
"was not able to copy it" |
|
348 |
WarningBox warn:'on copy file - ', ex errorString. |
|
349 |
self errorString:('on copy file - ', ex description asString). |
|
350 |
result := false. |
|
4006
8c706ba8b3b5
change flushCachedDirectory: senders to flushCachedDirectoryFor:
penk
parents:
3977
diff
changeset
|
351 |
^ self |
3842 | 352 |
] do:[ |
353 |
sourceIsDirectory ifTrue:[ |
|
5862 | 354 |
OperatingSystem recursiveCopyDirectory:(aSourceFile pathName) to:(newFile pathName). |
3842 | 355 |
] ifFalse:[ |
356 |
aSourceFile copyTo:newFile. |
|
357 |
]. |
|
358 |
]. |
|
4006
8c706ba8b3b5
change flushCachedDirectory: senders to flushCachedDirectoryFor:
penk
parents:
3977
diff
changeset
|
359 |
DirectoryContents flushCachedDirectoryFor:(aSourceFile directory). |
8c706ba8b3b5
change flushCachedDirectory: senders to flushCachedDirectoryFor:
penk
parents:
3977
diff
changeset
|
360 |
result := true. |
3842 | 361 |
! |
362 |
||
363 |
copyFiles:aColOfSourceFiles to:aDirectory |
|
364 |
||
365 |
^ self copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:true. |
|
366 |
! |
|
367 |
||
368 |
copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning |
|
369 |
||
370 |
^ self copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning copyFileIfSame:true. |
|
371 |
! |
|
372 |
||
373 |
copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning copyFileIfSame:copy |
|
374 |
||
375 |
||
5819 | 376 |
|newFile suffix fileString sourceIsDirectory overWriteExisting| |
3842 | 377 |
|
378 |
(aDirectory exists not) ifTrue:[ |
|
3863 | 379 |
Dialog warn:'cant copy to not existing directory ', aDirectory asString. |
3842 | 380 |
result := false. |
381 |
^ self |
|
382 |
]. |
|
383 |
(aDirectory isDirectory not) ifTrue:[ |
|
3863 | 384 |
Dialog warn:'destination ', aDirectory asString, ' is not a directory'. |
3842 | 385 |
result := false. |
386 |
^ self |
|
387 |
]. |
|
388 |
aColOfSourceFiles do:[: filename | |
|
389 |
newFile := aDirectory construct:(filename baseName). |
|
390 |
sourceIsDirectory := filename isDirectory. |
|
5819 | 391 |
overWriteExisting := true. |
3842 | 392 |
(newFile exists) ifTrue:[ |
393 |
((newFile asString = filename asString) and:[copy]) ifTrue:[ |
|
394 |
[newFile exists] whileTrue:[ |
|
395 |
suffix := newFile suffix. |
|
5081 | 396 |
fileString := newFile withoutSuffix baseName, self class copyMoveIfExistSuffixString. |
397 |
suffix notEmpty ifTrue:[ |
|
398 |
fileString := fileString, '.', suffix. |
|
399 |
]. |
|
3842 | 400 |
newFile := aDirectory construct:fileString. |
401 |
]. |
|
402 |
] ifFalse:[ |
|
403 |
overWriteWarning ifTrue:[ |
|
5862 | 404 |
overWriteExisting := (self fileExistDialogForNewFile:newFile oldFile:filename withCancel:(aColOfSourceFiles size > 1) withRemoveIfSame:false). |
5819 | 405 |
overWriteExisting isNil ifTrue:[ |
406 |
" abort pressed " |
|
3842 | 407 |
result := false. |
408 |
^ self. |
|
409 |
] |
|
410 |
] |
|
411 |
]. |
|
412 |
]. |
|
5819 | 413 |
overWriteExisting ifTrue:[ |
3842 | 414 |
Error handle:[:ex| |
415 |
"was not able to copy it" |
|
416 |
result := false. |
|
417 |
self errorString:('on copy file - ', ex description asString). |
|
418 |
( Dialog |
|
419 |
confirm:('error on copy file - ', ex description asString) |
|
420 |
title:'Copy' |
|
421 |
yesLabel:'Continue' |
|
5820 | 422 |
noLabel:'Abort') ifTrue:[ |
423 |
ex proceed. |
|
424 |
] ifFalse:[ |
|
425 |
^ self. |
|
426 |
]. |
|
3842 | 427 |
] do:[ |
428 |
sourceIsDirectory ifTrue:[ |
|
429 |
OperatingSystem recursiveCopyDirectory:(filename asString) |
|
430 |
to:(newFile asString). |
|
431 |
] ifFalse:[ |
|
432 |
filename copyTo:newFile. |
|
433 |
]. |
|
434 |
]. |
|
435 |
self colOfCopiedFiles add:filename |
|
436 |
] |
|
437 |
]. |
|
4006
8c706ba8b3b5
change flushCachedDirectory: senders to flushCachedDirectoryFor:
penk
parents:
3977
diff
changeset
|
438 |
DirectoryContents flushCachedDirectoryFor:aDirectory. |
3842 | 439 |
result := true. |
440 |
! ! |
|
441 |
||
442 |
!FileOperation::Create class methodsFor:'actions'! |
|
443 |
||
3863 | 444 |
createDirectoryIn:aDirectory |
3842 | 445 |
|
446 |
|instance| |
|
447 |
||
448 |
instance := self new. |
|
3863 | 449 |
instance createDirectoryIn:aDirectory. |
3842 | 450 |
^ instance |
451 |
! |
|
452 |
||
5961 | 453 |
createDirectoryIn:aDirectory initialAnswer:defaultAnswer |
454 |
||
455 |
|instance| |
|
456 |
||
457 |
instance := self new. |
|
458 |
instance createDirectoryIn:aDirectory initialAnswer:defaultAnswer. |
|
459 |
^ instance |
|
460 |
! |
|
461 |
||
3863 | 462 |
createFileIn:aFile |
3842 | 463 |
|
464 |
|instance| |
|
465 |
||
466 |
instance := self new. |
|
3863 | 467 |
instance createFileIn:aFile. |
3842 | 468 |
^ instance |
3877 | 469 |
! |
470 |
||
471 |
createHardLinkIn:aFile |
|
472 |
"create an new hard link in a files directory" |
|
473 |
||
474 |
|instance| |
|
475 |
||
476 |
instance := self new. |
|
477 |
instance createHardLinkIn:aFile. |
|
478 |
^ instance |
|
479 |
! |
|
480 |
||
481 |
createSoftLinkIn:aFile |
|
482 |
"create an new soft link in a files directory" |
|
483 |
||
484 |
|instance| |
|
485 |
||
486 |
instance := self new. |
|
487 |
instance createSoftLinkIn:aFile. |
|
488 |
^ instance |
|
3842 | 489 |
! ! |
490 |
||
3863 | 491 |
!FileOperation::Create methodsFor:'accessing'! |
492 |
||
493 |
createdFile |
|
494 |
"return the value of the instance variable 'createdFile' (automatically generated)" |
|
495 |
||
496 |
^ createdFile |
|
497 |
! |
|
498 |
||
499 |
createdFile:something |
|
500 |
"set the value of the instance variable 'createdFile' (automatically generated)" |
|
501 |
||
502 |
createdFile := something. |
|
3842 | 503 |
! ! |
504 |
||
505 |
!FileOperation::Create methodsFor:'actions'! |
|
506 |
||
3863 | 507 |
createDirectoryIn:startDirectory |
4522 | 508 |
|defaultDirectory| |
3863 | 509 |
|
4522 | 510 |
"/ stupid - that one already exists |
511 |
"/ LastCreatedDirectory notNil ifTrue:[ |
|
512 |
"/ defaultDirectory := LastCreatedDirectory baseName. |
|
513 |
"/ ]. |
|
514 |
||
515 |
^ self createDirectoryIn:startDirectory initialAnswer:defaultDirectory |
|
516 |
! |
|
517 |
||
518 |
createDirectoryIn:startDirectory initialAnswer:initialAnswerArg |
|
4584 | 519 |
|resources initialAnswer msg startBaseName newName newDir| |
520 |
||
521 |
resources := AbstractFileBrowser classResources. |
|
3842 | 522 |
|
3863 | 523 |
startBaseName := startDirectory baseName. |
4522 | 524 |
initialAnswer := initialAnswerArg. |
525 |
(startDirectory construct:initialAnswer) exists ifTrue:[ |
|
526 |
initialAnswer := nil. |
|
3863 | 527 |
]. |
6055 | 528 |
Dialog aboutToOpenBoxNotificationSignal ignoreIn:[ |
529 |
newName := Dialog |
|
530 |
request:(resources string:'Create New Directory in %1:' with:startBaseName allBold) |
|
531 |
initialAnswer:initialAnswer |
|
532 |
okLabel:(resources string:'Create') |
|
533 |
title:(resources string:'Create Directory') |
|
534 |
onCancel:[ |
|
535 |
self result:false. |
|
536 |
^ self |
|
537 |
]. |
|
538 |
]. |
|
3863 | 539 |
newName isEmpty ifTrue:[ |
540 |
self result:false. |
|
541 |
^ self |
|
542 |
]. |
|
4522 | 543 |
newDir := startDirectory construct:newName. |
544 |
newDir exists ifTrue:[ |
|
3863 | 545 |
Dialog warn:(newName, ' already exists.'). |
3842 | 546 |
result := false. |
547 |
^ self |
|
548 |
]. |
|
549 |
||
4522 | 550 |
newDir makeDirectory ifFalse:[ |
3850 | 551 |
msg := errorString := ('cannot create directory '', newName,'' !!') , '(', (OperatingSystem lastErrorString) , ')'. |
552 |
errorString := msg. |
|
3863 | 553 |
Dialog warn:errorString. |
3842 | 554 |
result := false. |
555 |
^ self |
|
556 |
]. |
|
4522 | 557 |
self createdFile:newDir. |
558 |
LastCreatedDirectory := newDir. |
|
3842 | 559 |
result := true. |
560 |
! |
|
561 |
||
3863 | 562 |
createFileIn:aFile |
3842 | 563 |
"create an empty file" |
564 |
||
4584 | 565 |
|resources aStream msg file directory newName defaultFile| |
566 |
||
567 |
resources := AbstractFileBrowser classResources. |
|
3842 | 568 |
|
3863 | 569 |
aFile isDirectory ifTrue:[ |
570 |
directory := aFile |
|
571 |
] ifFalse:[ |
|
572 |
directory := aFile directory. |
|
573 |
file := aFile |
|
574 |
]. |
|
575 |
LastCreatedFile isNil ifTrue:[ |
|
576 |
defaultFile := aFile baseName. |
|
577 |
] ifFalse:[ |
|
578 |
defaultFile := LastCreatedFile baseName. |
|
3842 | 579 |
]. |
3863 | 580 |
newName := Dialog |
4585 | 581 |
request:(resources string:'Create New File in %1:' with:directory baseName allBold) |
3863 | 582 |
initialAnswer:defaultFile |
4584 | 583 |
okLabel:(resources string:'Create') |
584 |
title:(resources string:'Create File') |
|
3863 | 585 |
onCancel:[ |
586 |
self result:false. |
|
587 |
^ self |
|
588 |
]. |
|
589 |
newName isEmpty ifTrue:[ |
|
590 |
self result:false. |
|
3842 | 591 |
] ifFalse:[ |
3863 | 592 |
| newFile | |
593 |
newFile := directory construct:newName. |
|
594 |
newFile exists ifTrue:[ |
|
595 |
(Dialog |
|
596 |
confirm:(newName, ' already exists truncate ?') |
|
597 |
yesLabel:('Truncate') |
|
598 |
noLabel:('Cancel')) |
|
599 |
ifFalse:[ |
|
600 |
self result:false. |
|
601 |
^ self |
|
602 |
]. |
|
603 |
]. |
|
604 |
FileStream openErrorSignal handle:[:ex| |
|
605 |
msg := ('Cannot create file '', newName,'' !!') , '(' , (FileStream lastErrorString) , ')'. |
|
606 |
errorString := msg. |
|
607 |
self result:false. |
|
608 |
^ Dialog warn:errorString |
|
609 |
] do:[ |
|
610 |
aStream := newFile newReadWriteStream. |
|
611 |
]. |
|
4637
46517dedc503
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
4627
diff
changeset
|
612 |
aStream close. |
46517dedc503
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
4627
diff
changeset
|
613 |
self createdFile:newFile. |
46517dedc503
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
4627
diff
changeset
|
614 |
LastCreatedFile := newFile. |
46517dedc503
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
4627
diff
changeset
|
615 |
self result:true. |
3842 | 616 |
]. |
3877 | 617 |
! |
618 |
||
619 |
createHardLinkIn:aFile |
|
620 |
"create an new hard link in a files directory" |
|
621 |
||
622 |
self createLinkIn:aFile soft:false. |
|
623 |
! |
|
624 |
||
625 |
createLinkIn:aFile soft:symbolic |
|
4788 | 626 |
"ask for the link target; |
627 |
then, create an new soft or hard link in aFile's directory" |
|
3877 | 628 |
|
4788 | 629 |
|resources newPath oldPath box string if1 if2| |
4584 | 630 |
|
631 |
resources := AbstractFileBrowser classResources. |
|
3877 | 632 |
|
633 |
aFile isDirectory ifTrue:[ |
|
634 |
newPath := aFile asValue. |
|
635 |
oldPath := aFile asValue. |
|
636 |
] ifFalse:[ |
|
637 |
newPath := aFile directory asValue. |
|
638 |
oldPath := aFile asValue. |
|
639 |
]. |
|
640 |
||
641 |
box := Dialog new. |
|
4585 | 642 |
box label:'Create Link'. |
643 |
||
644 |
string := 'Create ', (symbolic ifTrue:['Symbolic'] ifFalse:['Hard']) ,' Link from:'. |
|
4584 | 645 |
(box addTextLabel:(resources string:string)) adjust:#left. |
6150
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
646 |
if1 := box addFilenameInputFieldOn:oldPath in:nil tabable:true. |
4584 | 647 |
(box addTextLabel:(resources string:'to:')) adjust:#left. |
6150
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
648 |
if2 := box addFilenameInputFieldOn:newPath in:nil value tabable:true. |
3877 | 649 |
|
650 |
box addAbortAndOkButtons. |
|
651 |
||
652 |
aFile isDirectory not ifTrue:[ |
|
653 |
box focusOnField:if1. |
|
654 |
]. |
|
655 |
box showAtPointer. |
|
656 |
||
4788 | 657 |
box accepted ifFalse:[ |
658 |
self result:false. |
|
659 |
] ifTrue:[ |
|
660 |
self doCreateLinkFrom:(oldPath value) to:(newPath value) soft:symbolic. |
|
3877 | 661 |
]. |
662 |
! |
|
663 |
||
664 |
createSoftLinkIn:aFile |
|
665 |
"create an new soft link in a files directory" |
|
666 |
||
667 |
self createLinkIn:aFile soft:true. |
|
4788 | 668 |
! |
669 |
||
6150
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
670 |
doCreateLinkFrom:oldPath to:newPathArg soft:symbolic |
4788 | 671 |
"actually create a soft or hard link" |
672 |
||
6150
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
673 |
|resources err newPath newPathFile oldPathFile| |
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
674 |
|
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
675 |
newPath := newPathArg. |
4788 | 676 |
|
677 |
resources := AbstractFileBrowser classResources. |
|
678 |
||
679 |
(oldPath size == 0) ifTrue:[ |
|
6150
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
680 |
self operationError:'Missing source'. |
4788 | 681 |
^ self. |
682 |
]. |
|
683 |
(newPath size == 0) ifTrue:[ |
|
6150
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
684 |
self operationError:'Missing link name (target)'. |
4788 | 685 |
^ self. |
686 |
]. |
|
687 |
||
688 |
newPathFile := newPath asFilename. |
|
6150
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
689 |
oldPathFile := oldPath asFilename. |
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
690 |
|
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
691 |
newPathFile exists ifTrue:[ |
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
692 |
newPathFile isDirectory ifTrue:[ |
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
693 |
newPathFile := newPathFile construct:(oldPathFile baseName). |
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
694 |
newPath := newPathFile name. |
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
695 |
]. |
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
696 |
]. |
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
697 |
|
4788 | 698 |
newPathFile exists ifTrue:[ |
699 |
self operationError:(resources string:'%1 already exists' with:newPath allBold). |
|
700 |
^ self. |
|
701 |
]. |
|
6150
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
702 |
oldPathFile exists ifFalse:[ |
4788 | 703 |
symbolic ifTrue:[ |
704 |
oldPathFile isAbsolute ifTrue:[ |
|
705 |
self operationError:(resources string:'%1 does not exist' with:oldPath allBold). |
|
706 |
^ self. |
|
707 |
]. |
|
708 |
(newPathFile directory construct:oldPath) exists ifFalse:[ |
|
709 |
Dialog warn:(resources string:'%1 does not exist (Warning only)' with:oldPath allBold). |
|
710 |
]. |
|
711 |
] ifFalse:[ |
|
712 |
self operationError:(resources string:'%1 does not exist' with:oldPath allBold). |
|
713 |
^ self. |
|
714 |
]. |
|
715 |
]. |
|
716 |
((symbolic not) and:[oldPathFile isDirectory]) ifTrue:[ |
|
717 |
self operationError:(resources string:'%1 is a directory' with:oldPath allBold). |
|
718 |
^ self. |
|
719 |
]. |
|
720 |
ErrorSignal handle:[:ex | |
|
721 |
err := ex errorString. |
|
722 |
self operationError:err. |
|
723 |
] do:[ |
|
724 |
symbolic ifTrue:[ |
|
725 |
OperatingSystem createSymbolicLinkFrom:oldPath to:newPath. |
|
726 |
] ifFalse:[ |
|
727 |
OperatingSystem createHardLinkFrom:oldPath to:newPath |
|
728 |
]. |
|
729 |
self createdFile:newPathFile. |
|
730 |
self result:true. |
|
731 |
]. |
|
732 |
! |
|
733 |
||
734 |
operationError:msg |
|
735 |
self result:false. |
|
736 |
Dialog warn:msg. |
|
737 |
self errorString:msg. |
|
3842 | 738 |
! ! |
739 |
||
740 |
!FileOperation::Delete class methodsFor:'actions'! |
|
741 |
||
742 |
deleteFile:aFileOrDirectory |
|
743 |
"delete current selected files/directories |
|
744 |
" |
|
745 |
||
746 |
|instance| |
|
747 |
||
748 |
instance := self new. |
|
749 |
instance deleteFile:aFileOrDirectory. |
|
750 |
^ instance |
|
751 |
! |
|
752 |
||
753 |
deleteFiles:aColOfFiles |
|
754 |
"delete current selected files/directories |
|
755 |
" |
|
5081 | 756 |
^ self deleteFiles:aColOfFiles confirm:true |
757 |
! |
|
758 |
||
759 |
deleteFiles:aColOfFiles confirm:confirm |
|
760 |
"delete current selected files/directories |
|
761 |
" |
|
3842 | 762 |
|
763 |
|instance| |
|
764 |
||
765 |
instance := self new. |
|
5081 | 766 |
instance deleteFiles:aColOfFiles confirm:confirm. |
3842 | 767 |
^ instance |
768 |
! ! |
|
769 |
||
770 |
!FileOperation::Delete methodsFor:'actions'! |
|
771 |
||
772 |
deleteFile:aFileOrDirectory |
|
773 |
||
774 |
| file isDirectory | |
|
775 |
||
776 |
aFileOrDirectory notNil ifTrue:[ |
|
777 |
file := aFileOrDirectory asFilename. |
|
778 |
||
4665
cd7e02bf5d85
fixed to allow deleting bad symbolic links
Claus Gittinger <cg@exept.de>
parents:
4664
diff
changeset
|
779 |
isDirectory := file isDirectory. |
3842 | 780 |
|
4665
cd7e02bf5d85
fixed to allow deleting bad symbolic links
Claus Gittinger <cg@exept.de>
parents:
4664
diff
changeset
|
781 |
Error handle:[:ex| |
cd7e02bf5d85
fixed to allow deleting bad symbolic links
Claus Gittinger <cg@exept.de>
parents:
4664
diff
changeset
|
782 |
"was not able to remove it" |
5746
a505fc181e11
warning string (backslash in pc-filename)
Claus Gittinger <cg@exept.de>
parents:
5687
diff
changeset
|
783 |
Dialog warn:(ex description, '\' withCRs, ex signal notifierString). |
4411 | 784 |
"/ Smalltalk beep. |
5746
a505fc181e11
warning string (backslash in pc-filename)
Claus Gittinger <cg@exept.de>
parents:
5687
diff
changeset
|
785 |
self errorString:(ex description, ' - ', ex signal notifierString). |
4665
cd7e02bf5d85
fixed to allow deleting bad symbolic links
Claus Gittinger <cg@exept.de>
parents:
4664
diff
changeset
|
786 |
result := false. |
cd7e02bf5d85
fixed to allow deleting bad symbolic links
Claus Gittinger <cg@exept.de>
parents:
4664
diff
changeset
|
787 |
^ self. |
cd7e02bf5d85
fixed to allow deleting bad symbolic links
Claus Gittinger <cg@exept.de>
parents:
4664
diff
changeset
|
788 |
] do:[ |
cd7e02bf5d85
fixed to allow deleting bad symbolic links
Claus Gittinger <cg@exept.de>
parents:
4664
diff
changeset
|
789 |
isDirectory ifTrue:[file recursiveRemove] ifFalse:[file remove]. |
3842 | 790 |
|
4665
cd7e02bf5d85
fixed to allow deleting bad symbolic links
Claus Gittinger <cg@exept.de>
parents:
4664
diff
changeset
|
791 |
]. |
cd7e02bf5d85
fixed to allow deleting bad symbolic links
Claus Gittinger <cg@exept.de>
parents:
4664
diff
changeset
|
792 |
"/ flush parent directory or directory |
3842 | 793 |
]. |
4006
8c706ba8b3b5
change flushCachedDirectory: senders to flushCachedDirectoryFor:
penk
parents:
3977
diff
changeset
|
794 |
DirectoryContents flushCachedDirectoryFor:(file directory). |
3842 | 795 |
result := true. |
5746
a505fc181e11
warning string (backslash in pc-filename)
Claus Gittinger <cg@exept.de>
parents:
5687
diff
changeset
|
796 |
|
a505fc181e11
warning string (backslash in pc-filename)
Claus Gittinger <cg@exept.de>
parents:
5687
diff
changeset
|
797 |
"Modified: / 17-03-2004 / 12:42:02 / cg" |
3842 | 798 |
! |
799 |
||
800 |
deleteFiles:colOfFiles |
|
801 |
"delete current selected files/directories |
|
802 |
" |
|
5081 | 803 |
^ self deleteFiles:colOfFiles confirm:true. |
804 |
! |
|
4584 | 805 |
|
5081 | 806 |
deleteFiles:colOfFiles confirm:confirm |
807 |
"delete current selected files/directories |
|
808 |
" |
|
5805 | 809 |
|resources answer nFilesToDelete ask labels values fileTypeString msg lbls vals| |
5081 | 810 |
|
811 |
ask := confirm. |
|
4584 | 812 |
resources := AbstractFileBrowser classResources. |
3842 | 813 |
|
4701 | 814 |
nFilesToDelete := colOfFiles size. |
4408
8c0c80b68ae7
ask again, if dir is not empty
Claus Gittinger <cg@exept.de>
parents:
4395
diff
changeset
|
815 |
colOfFiles do:[:filenameOrString | |
5673 | 816 |
|filename askForNonEmptyDirectory skip| |
4408
8c0c80b68ae7
ask again, if dir is not empty
Claus Gittinger <cg@exept.de>
parents:
4395
diff
changeset
|
817 |
|
8c0c80b68ae7
ask again, if dir is not empty
Claus Gittinger <cg@exept.de>
parents:
4395
diff
changeset
|
818 |
filename := filenameOrString asFilename. |
4665
cd7e02bf5d85
fixed to allow deleting bad symbolic links
Claus Gittinger <cg@exept.de>
parents:
4664
diff
changeset
|
819 |
|
5673 | 820 |
skip := false. |
4665
cd7e02bf5d85
fixed to allow deleting bad symbolic links
Claus Gittinger <cg@exept.de>
parents:
4664
diff
changeset
|
821 |
fileTypeString := ''. |
cd7e02bf5d85
fixed to allow deleting bad symbolic links
Claus Gittinger <cg@exept.de>
parents:
4664
diff
changeset
|
822 |
filename isSymbolicLink ifTrue:[ |
cd7e02bf5d85
fixed to allow deleting bad symbolic links
Claus Gittinger <cg@exept.de>
parents:
4664
diff
changeset
|
823 |
fileTypeString := 'symbolic link '. |
cd7e02bf5d85
fixed to allow deleting bad symbolic links
Claus Gittinger <cg@exept.de>
parents:
4664
diff
changeset
|
824 |
] ifFalse:[ |
5673 | 825 |
filename exists ifFalse:[ |
826 |
(Dialog |
|
5846 | 827 |
confirm:('%1 does not exist.' bindWith:filename asString allBold) |
828 |
yesLabel:(resources string:'Proceed') |
|
5673 | 829 |
noLabel:(resources string:'Cancel')) |
830 |
ifFalse:[ |
|
831 |
^ self. |
|
832 |
]. |
|
833 |
skip := true. |
|
4665
cd7e02bf5d85
fixed to allow deleting bad symbolic links
Claus Gittinger <cg@exept.de>
parents:
4664
diff
changeset
|
834 |
] |
4423 | 835 |
]. |
5673 | 836 |
skip ifFalse:[ |
837 |
ask ifTrue:[ |
|
838 |
nFilesToDelete = 1 ifTrue:[ |
|
839 |
labels := #('No' 'Yes'). |
|
840 |
values := #(#no #yes). |
|
841 |
] ifFalse:[ |
|
842 |
labels := #('Cancel' 'No' 'Yes' 'Yes to All' ). |
|
843 |
values := #(#cancel #no #yes #yesToAll). |
|
844 |
]. |
|
5805 | 845 |
msg := nFilesToDelete = 1 |
846 |
ifTrue:'Really delete\\%1%2 ?' |
|
847 |
ifFalse:'Really delete\\%1%2 \\(%3 files alltogether)'. |
|
6088 | 848 |
Dialog aboutToOpenBoxNotificationSignal handle:[:ex | ex proceed] |
849 |
do:[ |
|
850 |
answer := Dialog |
|
851 |
confirmWithCancel:(resources |
|
852 |
stringWithCRs:msg |
|
853 |
with:fileTypeString |
|
854 |
with:(filename asString allBold) |
|
855 |
with:nFilesToDelete) |
|
856 |
labels:(resources array:labels) |
|
857 |
values:values |
|
858 |
default:(values indexOf:#yes). |
|
859 |
] |
|
3842 | 860 |
] ifFalse:[ |
5673 | 861 |
answer := #yesToAll. |
3977 | 862 |
]. |
5673 | 863 |
|
864 |
answer == #cancel ifTrue:[ |
|
865 |
^ self. |
|
866 |
]. |
|
867 |
||
868 |
answer == #yesToAll ifTrue:[ |
|
869 |
ask := false. |
|
870 |
answer := #yes. |
|
871 |
]. |
|
4408
8c0c80b68ae7
ask again, if dir is not empty
Claus Gittinger <cg@exept.de>
parents:
4395
diff
changeset
|
872 |
|
5673 | 873 |
answer == #yes ifTrue:[ |
874 |
askForNonEmptyDirectory := true. |
|
875 |
filename isSymbolicLink ifFalse:[ |
|
876 |
filename isNonEmptyDirectory ifTrue:[ |
|
5805 | 877 |
colOfFiles size == 1 ifTrue:[ |
878 |
lbls := #('Cancel' 'Remove'). |
|
879 |
vals := #(false true). |
|
880 |
] ifFalse:[ |
|
881 |
lbls := #('Cancel All' 'Keep' 'Remove'). |
|
882 |
vals := #(nil false true). |
|
883 |
]. |
|
5673 | 884 |
askForNonEmptyDirectory := Dialog |
5805 | 885 |
confirmWithCancel:(resources |
886 |
stringWithCRs:'Directory ''%1'' is not empty\remove anyway ?' |
|
887 |
with:filename pathName allBold) |
|
888 |
labels:( resources array:lbls ) |
|
889 |
values:vals |
|
890 |
default:vals size. |
|
5673 | 891 |
askForNonEmptyDirectory == nil ifTrue:[ |
892 |
^ self |
|
893 |
]. |
|
5342
4ea3ee096611
deletion of symbolic links pointing to a directory
Claus Gittinger <cg@exept.de>
parents:
5081
diff
changeset
|
894 |
]. |
4637
46517dedc503
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
4627
diff
changeset
|
895 |
]. |
5673 | 896 |
askForNonEmptyDirectory ifTrue:[ |
897 |
self deleteFile:filename. |
|
898 |
] |
|
4408
8c0c80b68ae7
ask again, if dir is not empty
Claus Gittinger <cg@exept.de>
parents:
4395
diff
changeset
|
899 |
]. |
8c0c80b68ae7
ask again, if dir is not empty
Claus Gittinger <cg@exept.de>
parents:
4395
diff
changeset
|
900 |
]. |
3842 | 901 |
]. |
902 |
! ! |
|
903 |
||
904 |
!FileOperation::Move class methodsFor:'actions'! |
|
905 |
||
906 |
moveFile:aSourceFile to:aDestFile |
|
907 |
"delete current selected files/directories |
|
908 |
" |
|
909 |
||
910 |
|instance| |
|
911 |
||
912 |
instance := self new. |
|
913 |
instance moveFile:aSourceFile to:aDestFile. |
|
914 |
^ instance |
|
915 |
! |
|
916 |
||
917 |
moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning |
|
918 |
"delete current selected files/directories |
|
919 |
" |
|
920 |
||
921 |
|instance| |
|
922 |
||
923 |
instance := self new. |
|
924 |
instance moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning. |
|
925 |
^ instance |
|
926 |
! |
|
927 |
||
928 |
moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning moveFileIfSame:move |
|
929 |
"delete current selected files/directories |
|
930 |
" |
|
931 |
||
932 |
|instance| |
|
933 |
||
934 |
instance := self new. |
|
935 |
instance moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning moveFileIfSame:move. |
|
936 |
^ instance |
|
937 |
! |
|
938 |
||
939 |
moveFiles:aColOfSourceFiles to:aDirectory |
|
940 |
"delete current selected files/directories |
|
941 |
" |
|
942 |
||
943 |
|instance| |
|
944 |
||
945 |
instance := self new. |
|
946 |
instance moveFiles:aColOfSourceFiles to:aDirectory. |
|
947 |
^ instance |
|
948 |
! |
|
949 |
||
950 |
moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning |
|
951 |
"delete current selected files/directories |
|
952 |
" |
|
953 |
||
954 |
|instance| |
|
955 |
||
956 |
instance := self new. |
|
957 |
instance moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning. |
|
958 |
^ instance |
|
959 |
! |
|
960 |
||
961 |
moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning moveFileIfSame:move |
|
962 |
"delete current selected files/directories |
|
963 |
" |
|
964 |
||
965 |
|instance| |
|
966 |
||
967 |
instance := self new. |
|
968 |
instance moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning moveFileIfSame:move. |
|
969 |
^ instance |
|
970 |
! ! |
|
971 |
||
972 |
!FileOperation::Move methodsFor:'accessing'! |
|
973 |
||
974 |
colOfMovedFiles |
|
975 |
"return the value of the instance variable 'colOfMovedFiles' (automatically generated)" |
|
976 |
||
977 |
colOfMovedFiles isNil ifTrue:[ |
|
978 |
colOfMovedFiles := OrderedCollection new. |
|
979 |
]. |
|
980 |
^ colOfMovedFiles |
|
981 |
! ! |
|
982 |
||
983 |
!FileOperation::Move methodsFor:'actions'! |
|
984 |
||
985 |
moveFile:aSourceFile to:aDestFile |
|
986 |
||
987 |
^ self moveFile:aSourceFile to:aDestFile withOverWriteWarning:true. |
|
988 |
! |
|
989 |
||
990 |
moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning |
|
991 |
||
992 |
^ self moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning moveFileIfSame:true |
|
993 |
! |
|
994 |
||
995 |
moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning moveFileIfSame:move |
|
996 |
||
5862 | 997 |
|newFile fileString targetDirectory targetIsDirectory suffix doMove| |
3842 | 998 |
|
999 |
targetIsDirectory := aDestFile isDirectory. |
|
1000 |
targetIsDirectory ifTrue:[ |
|
1001 |
targetDirectory := aDestFile. |
|
1002 |
newFile := aDestFile construct:(aSourceFile baseName). |
|
1003 |
] ifFalse:[ |
|
1004 |
targetDirectory := aDestFile directory. |
|
1005 |
newFile := aDestFile. |
|
1006 |
]. |
|
1007 |
"/ do not copy if destination directory doest exist. |
|
1008 |
(targetDirectory exists not) ifTrue:[ |
|
4522 | 1009 |
Dialog warn:'Cannot move to non-existing directory ', targetDirectory asString. |
3842 | 1010 |
result := false. |
1011 |
^ self |
|
1012 |
]. |
|
1013 |
(newFile exists) ifTrue:[ |
|
1014 |
((newFile asString = aSourceFile asString) and:[move]) ifTrue:[ |
|
1015 |
[newFile exists] whileTrue:[ |
|
1016 |
suffix := newFile suffix. |
|
1017 |
fileString := newFile baseName withoutSuffix, self class copyMoveIfExistSuffixString, '.', suffix. |
|
1018 |
newFile := targetDirectory construct:fileString. |
|
1019 |
]. |
|
1020 |
] ifFalse:[ |
|
1021 |
overWriteWarning ifTrue:[ |
|
5862 | 1022 |
doMove := self fileExistDialogForNewFile:newFile oldFile:aSourceFile withCancel:false withRemoveIfSame:true. |
1023 |
doMove == #removeSource ifTrue:[ |
|
1024 |
self halt. |
|
1025 |
result := false. |
|
1026 |
^ self. |
|
1027 |
]. |
|
1028 |
doMove == #removeDestination ifTrue:[ |
|
1029 |
self halt. |
|
3842 | 1030 |
result := false. |
1031 |
^ self. |
|
5862 | 1032 |
]. |
1033 |
doMove == true ifFalse:[ |
|
3842 | 1034 |
result := false. |
1035 |
^ self. |
|
5862 | 1036 |
]. |
1037 |
||
1038 |
] ifFalse:[ |
|
1039 |
result := false. |
|
1040 |
^ self. |
|
3842 | 1041 |
] |
1042 |
]. |
|
1043 |
]. |
|
1044 |
Error handle:[:ex| |
|
1045 |
"was not able to copy it" |
|
4522 | 1046 |
WarningBox warn:'Error in copy file Operation: ', ex errorString. |
1047 |
self errorString:('Error in copy file Operation- ', ex description asString). |
|
3842 | 1048 |
result := false. |
4006
8c706ba8b3b5
change flushCachedDirectory: senders to flushCachedDirectoryFor:
penk
parents:
3977
diff
changeset
|
1049 |
^ self |
3842 | 1050 |
] do:[ |
1051 |
aSourceFile moveTo:newFile. |
|
1052 |
]. |
|
4006
8c706ba8b3b5
change flushCachedDirectory: senders to flushCachedDirectoryFor:
penk
parents:
3977
diff
changeset
|
1053 |
DirectoryContents flushCachedDirectoryFor:(aSourceFile directory). |
8c706ba8b3b5
change flushCachedDirectory: senders to flushCachedDirectoryFor:
penk
parents:
3977
diff
changeset
|
1054 |
result := true. |
3842 | 1055 |
! |
1056 |
||
1057 |
moveFiles:aColOfSourceFiles to:aDirectory |
|
1058 |
||
1059 |
^ self moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:true |
|
1060 |
! |
|
1061 |
||
1062 |
moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning |
|
1063 |
||
1064 |
^ self moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning moveFileIfSame:true |
|
1065 |
! |
|
1066 |
||
1067 |
moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning moveFileIfSame:move |
|
1068 |
||
5862 | 1069 |
|newFile suffix fileString doMove doRemoveSource doRemoveDestination| |
3842 | 1070 |
|
5854
8c6042ba7495
ask if non-existing directory should be created
Claus Gittinger <cg@exept.de>
parents:
5846
diff
changeset
|
1071 |
aDirectory exists ifFalse:[ |
8c6042ba7495
ask if non-existing directory should be created
Claus Gittinger <cg@exept.de>
parents:
5846
diff
changeset
|
1072 |
(Dialog confirm:(FileBrowser classResources |
8c6042ba7495
ask if non-existing directory should be created
Claus Gittinger <cg@exept.de>
parents:
5846
diff
changeset
|
1073 |
stringWithCRs:'Non-existing directory "%1" .\Create ?' |
8c6042ba7495
ask if non-existing directory should be created
Claus Gittinger <cg@exept.de>
parents:
5846
diff
changeset
|
1074 |
with:aDirectory asString allBold)) ifFalse:[ |
8c6042ba7495
ask if non-existing directory should be created
Claus Gittinger <cg@exept.de>
parents:
5846
diff
changeset
|
1075 |
result := false. |
8c6042ba7495
ask if non-existing directory should be created
Claus Gittinger <cg@exept.de>
parents:
5846
diff
changeset
|
1076 |
^ self |
8c6042ba7495
ask if non-existing directory should be created
Claus Gittinger <cg@exept.de>
parents:
5846
diff
changeset
|
1077 |
]. |
8c6042ba7495
ask if non-existing directory should be created
Claus Gittinger <cg@exept.de>
parents:
5846
diff
changeset
|
1078 |
aDirectory makeDirectory. |
8c6042ba7495
ask if non-existing directory should be created
Claus Gittinger <cg@exept.de>
parents:
5846
diff
changeset
|
1079 |
aDirectory exists ifFalse:[ |
8c6042ba7495
ask if non-existing directory should be created
Claus Gittinger <cg@exept.de>
parents:
5846
diff
changeset
|
1080 |
Dialog warn:(FileBrowser classResources |
8c6042ba7495
ask if non-existing directory should be created
Claus Gittinger <cg@exept.de>
parents:
5846
diff
changeset
|
1081 |
stringWithCRs:'Cannot create directory "%1" !!\Create ?.' |
8c6042ba7495
ask if non-existing directory should be created
Claus Gittinger <cg@exept.de>
parents:
5846
diff
changeset
|
1082 |
with:aDirectory asString allBold). |
8c6042ba7495
ask if non-existing directory should be created
Claus Gittinger <cg@exept.de>
parents:
5846
diff
changeset
|
1083 |
result := false. |
8c6042ba7495
ask if non-existing directory should be created
Claus Gittinger <cg@exept.de>
parents:
5846
diff
changeset
|
1084 |
^ self |
8c6042ba7495
ask if non-existing directory should be created
Claus Gittinger <cg@exept.de>
parents:
5846
diff
changeset
|
1085 |
] |
3842 | 1086 |
]. |
5788 | 1087 |
(aDirectory isDirectory) ifFalse:[ |
4522 | 1088 |
Dialog warn:('Destination %1 is not a directory.' bindWith:aDirectory asString allBold). |
3842 | 1089 |
result := false. |
1090 |
^ self |
|
1091 |
]. |
|
1092 |
aColOfSourceFiles do:[: filename | |
|
1093 |
newFile := aDirectory construct:filename baseName. |
|
5790 | 1094 |
|
1095 |
doMove := true. |
|
5862 | 1096 |
doRemoveSource := false. |
1097 |
doRemoveDestination := false. |
|
1098 |
||
3842 | 1099 |
(newFile exists) ifTrue:[ |
1100 |
((newFile asString = filename asString) and:[move]) ifTrue:[ |
|
1101 |
[newFile exists] whileTrue:[ |
|
1102 |
suffix := newFile suffix. |
|
6011 | 1103 |
fileString := newFile withoutSuffix baseName , self class copyMoveIfExistSuffixString, '.', suffix. |
3842 | 1104 |
newFile := aDirectory construct:fileString. |
1105 |
]. |
|
1106 |
] ifFalse:[ |
|
1107 |
overWriteWarning ifTrue:[ |
|
5862 | 1108 |
doMove := self fileExistDialogForNewFile:newFile oldFile:filename withCancel:(aColOfSourceFiles size > 1) withRemoveIfSame:true. |
1109 |
doMove isNil ifTrue:[ "/ cancel |
|
3842 | 1110 |
result := false. |
1111 |
^ self. |
|
5862 | 1112 |
]. |
1113 |
(doMove == #removeSource) ifTrue:[ |
|
1114 |
doRemoveSource := true. |
|
1115 |
doMove := false |
|
1116 |
] ifFalse:[ |
|
1117 |
(doMove == #removeDestination) ifTrue:[ |
|
1118 |
doRemoveDestination := true. |
|
1119 |
doMove := false |
|
1120 |
] |
|
3842 | 1121 |
] |
1122 |
] |
|
1123 |
]. |
|
1124 |
]. |
|
4522 | 1125 |
|
5862 | 1126 |
(doMove or:[doRemoveSource or:[doRemoveDestination]]) ifTrue:[ |
3842 | 1127 |
Error handle:[:ex| |
1128 |
"was not able to copy it" |
|
5862 | 1129 |
|descriptionString| |
1130 |
||
3842 | 1131 |
result := false. |
5862 | 1132 |
descriptionString := ex description asString. |
1133 |
self errorString:(' Error in Move-File Operation:', descriptionString). |
|
3842 | 1134 |
( Dialog |
5862 | 1135 |
confirm:(' Error in Move-File Operation: ', descriptionString) |
3842 | 1136 |
title:'Move' |
1137 |
yesLabel:'Continue' |
|
5862 | 1138 |
noLabel:'Abort' |
1139 |
) ifFalse:[ |
|
3842 | 1140 |
^ self. |
1141 |
]. |
|
1142 |
] do:[ |
|
5862 | 1143 |
doRemoveSource ifTrue:[ |
1144 |
filename remove |
|
1145 |
] ifFalse:[ |
|
1146 |
doRemoveDestination ifTrue:[ |
|
1147 |
newFile remove |
|
1148 |
] ifFalse:[ |
|
1149 |
filename moveTo:newFile. |
|
1150 |
] |
|
1151 |
] |
|
3842 | 1152 |
]. |
1153 |
self colOfMovedFiles add:filename |
|
1154 |
] |
|
1155 |
]. |
|
4006
8c706ba8b3b5
change flushCachedDirectory: senders to flushCachedDirectoryFor:
penk
parents:
3977
diff
changeset
|
1156 |
DirectoryContents flushCachedDirectoryFor:aDirectory. |
3842 | 1157 |
result := true. |
1158 |
! ! |
|
1159 |
||
1160 |
!FileOperation::Rename class methodsFor:'actions'! |
|
1161 |
||
1162 |
renameFile:oldFile to:newName |
|
1163 |
"move from to |
|
1164 |
" |
|
1165 |
||
1166 |
|instance| |
|
1167 |
||
1168 |
instance := self new. |
|
1169 |
instance renameFile:oldFile to:newName. |
|
1170 |
^ instance |
|
1171 |
! |
|
1172 |
||
1173 |
renameFiles:aColOfFiles |
|
1174 |
"move from to |
|
1175 |
" |
|
1176 |
||
1177 |
|instance| |
|
1178 |
||
1179 |
instance := self new. |
|
1180 |
instance renameFiles:aColOfFiles. |
|
1181 |
^ instance |
|
1182 |
! ! |
|
1183 |
||
1184 |
!FileOperation::Rename methodsFor:'accessing'! |
|
1185 |
||
1186 |
renamedFiles |
|
1187 |
"return the value of the instance variable 'lastRenamedFile' (automatically generated)" |
|
1188 |
||
1189 |
renamedFiles isNil ifTrue:[ |
|
1190 |
renamedFiles := OrderedCollection new. |
|
1191 |
]. |
|
1192 |
^ renamedFiles |
|
1193 |
! ! |
|
1194 |
||
1195 |
!FileOperation::Rename methodsFor:'actions'! |
|
1196 |
||
1197 |
renameFile:oldFile to:newName |
|
1198 |
"rename a file (or directory)" |
|
1199 |
||
5656 | 1200 |
|newFile msg resources| |
3842 | 1201 |
|
1202 |
(oldFile isNil or:[newName isNil]) ifTrue:[ |
|
5656 | 1203 |
result := false. |
1204 |
^ self. |
|
3842 | 1205 |
]. |
1206 |
(oldFile asString isBlank or:[newName isBlank]) ifTrue:[ |
|
5656 | 1207 |
result := false. |
1208 |
^ self. |
|
3842 | 1209 |
]. |
5656 | 1210 |
newName asFilename isAbsolute ifTrue:[ |
1211 |
newFile := newName asFilename. |
|
1212 |
] ifFalse:[ |
|
1213 |
(oldFile baseName = newName) ifTrue:[ |
|
1214 |
result := false |
|
1215 |
]. |
|
1216 |
newFile := oldFile directory construct:newName. |
|
3842 | 1217 |
]. |
1218 |
||
5656 | 1219 |
oldFile pathName = newFile pathName ifTrue:[ |
4674
64a49fadc47e
do op if newName is same as old in a rename operation
Claus Gittinger <cg@exept.de>
parents:
4665
diff
changeset
|
1220 |
^ self. |
64a49fadc47e
do op if newName is same as old in a rename operation
Claus Gittinger <cg@exept.de>
parents:
4665
diff
changeset
|
1221 |
]. |
64a49fadc47e
do op if newName is same as old in a rename operation
Claus Gittinger <cg@exept.de>
parents:
4665
diff
changeset
|
1222 |
|
5656 | 1223 |
resources := Dialog classResources. |
1224 |
||
3842 | 1225 |
OperatingSystem errorSignal handle:[:ex| |
5656 | 1226 |
msg := resources |
1227 |
stringWithCRs:'Cannot rename file %1 to %2 !!\\(%3)' |
|
1228 |
with:oldFile baseName |
|
1229 |
with:newName |
|
1230 |
with:(OperatingSystem lastErrorString). |
|
3863 | 1231 |
Dialog warn:msg withCRs. |
4882 | 1232 |
result := false. |
1233 |
^ self. |
|
3842 | 1234 |
] do:[ |
5656 | 1235 |
newFile exists ifTrue:[ |
1236 |
(newFile sameContentsAs:oldFile) ifTrue:[ |
|
1237 |
msg := '%1 exists [with same contents] - rename (i.e. overwrite) anyway ?' |
|
1238 |
] ifFalse:[ |
|
1239 |
msg := '%1 exists - rename (i.e. overwrite) anyway ?' |
|
1240 |
]. |
|
1241 |
(Dialog confirmWithCancel:(resources string:msg with:newName allBold) default:false) ifFalse:[ |
|
3842 | 1242 |
result := false. |
1243 |
^ self. |
|
1244 |
] |
|
1245 |
]. |
|
5656 | 1246 |
oldFile renameTo:newFile. |
1247 |
self renamedFiles add:newFile. |
|
3842 | 1248 |
]. |
1249 |
result := true. |
|
1250 |
! |
|
1251 |
||
1252 |
renameFiles:aColOfFiles |
|
1253 |
"rename the selected file(s)" |
|
1254 |
||
5827 | 1255 |
|resources queryBox b lastNewName lastOldName initialText oldName newName renameAll doRename| |
4584 | 1256 |
|
1257 |
resources := AbstractFileBrowser classResources. |
|
5827 | 1258 |
renameAll := false. |
3842 | 1259 |
|
1260 |
queryBox := FilenameEnterBox new. |
|
4584 | 1261 |
queryBox okText:(resources string:'Rename'). |
5827 | 1262 |
|
3842 | 1263 |
aColOfFiles size > 1 ifTrue:[ |
4584 | 1264 |
b := queryBox addAbortButtonLabelled:(resources string:'Cancel All'). |
5827 | 1265 |
b action:[^ self]. |
1266 |
queryBox addButton:(Button label:(resources string:'Rename All') action:[renameAll := true. queryBox okPressed]) before:(queryBox okButton). |
|
3842 | 1267 |
]. |
5827 | 1268 |
aColOfFiles do:[:oldFile | |
3842 | 1269 |
oldName := oldFile baseName asString. |
1270 |
lastNewName notNil ifTrue:[ |
|
4273
df4ed96689cd
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
4016
diff
changeset
|
1271 |
initialText := FileBrowser goodRenameDefaultForFile:oldName lastOld:lastOldName lastNew:lastNewName |
3842 | 1272 |
]. |
5827 | 1273 |
doRename := false. |
1274 |
renameAll ifTrue:[ |
|
1275 |
doRename := true. |
|
1276 |
newName := initialText. |
|
1277 |
] ifFalse:[ |
|
1278 |
queryBox title:(resources string:'Rename %1 to:' with:(oldName allBold)). |
|
1279 |
queryBox initialText:(initialText ? oldName). |
|
1280 |
queryBox action:[:newEnteredName | newName := newEnteredName. doRename := true.]. |
|
1281 |
queryBox show "showAtPointer". |
|
1282 |
]. |
|
1283 |
doRename ifTrue:[ |
|
1284 |
(self renameFile:oldFile to:newName asString) ifTrue:[ |
|
1285 |
result := true |
|
3842 | 1286 |
]. |
5827 | 1287 |
lastOldName := oldName. |
1288 |
lastNewName := newName. |
|
1289 |
]. |
|
3842 | 1290 |
] |
1291 |
! ! |
|
1292 |
||
3841 | 1293 |
!FileOperation class methodsFor:'documentation'! |
1294 |
||
1295 |
version |
|
6150
5028485a29c6
fixed new-symbolic link operation
Claus Gittinger <cg@exept.de>
parents:
6088
diff
changeset
|
1296 |
^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.60 2004-12-13 10:46:46 cg Exp $' |
3841 | 1297 |
! ! |