3841
|
1 |
"{ Package: 'stx:libtool2' }"
|
|
2 |
|
|
3 |
Object subclass:#FileOperation
|
|
4 |
instanceVariableNames:'errorString result'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Interface-Support'
|
|
8 |
!
|
|
9 |
|
3842
|
10 |
FileOperation subclass:#Copy
|
|
11 |
instanceVariableNames:'colOfCopiedFiles'
|
|
12 |
classVariableNames:''
|
|
13 |
poolDictionaries:''
|
|
14 |
privateIn:FileOperation
|
|
15 |
!
|
|
16 |
|
|
17 |
FileOperation subclass:#Create
|
|
18 |
instanceVariableNames:''
|
|
19 |
classVariableNames:''
|
|
20 |
poolDictionaries:''
|
|
21 |
privateIn:FileOperation
|
|
22 |
!
|
|
23 |
|
|
24 |
FileOperation subclass:#Delete
|
|
25 |
instanceVariableNames:'fileName errorString'
|
|
26 |
classVariableNames:''
|
|
27 |
poolDictionaries:''
|
|
28 |
privateIn:FileOperation
|
|
29 |
!
|
|
30 |
|
|
31 |
FileOperation subclass:#Move
|
|
32 |
instanceVariableNames:'colOfMovedFiles'
|
|
33 |
classVariableNames:''
|
|
34 |
poolDictionaries:''
|
|
35 |
privateIn:FileOperation
|
|
36 |
!
|
|
37 |
|
|
38 |
FileOperation subclass:#Rename
|
|
39 |
instanceVariableNames:'renamedFiles'
|
|
40 |
classVariableNames:''
|
|
41 |
poolDictionaries:''
|
|
42 |
privateIn:FileOperation
|
|
43 |
!
|
|
44 |
|
3841
|
45 |
|
|
46 |
!FileOperation class methodsFor:'defaults'!
|
|
47 |
|
|
48 |
copyMoveIfExistSuffixString
|
|
49 |
|
|
50 |
^ '.copy'
|
|
51 |
! !
|
|
52 |
|
3842
|
53 |
!FileOperation class methodsFor:'private class access'!
|
|
54 |
|
|
55 |
copy
|
|
56 |
^ Copy
|
|
57 |
!
|
|
58 |
|
|
59 |
create
|
|
60 |
^ Create
|
|
61 |
!
|
|
62 |
|
|
63 |
delete
|
|
64 |
^ Delete
|
|
65 |
!
|
|
66 |
|
|
67 |
move
|
|
68 |
^ Move
|
|
69 |
!
|
|
70 |
|
|
71 |
rename
|
|
72 |
^ Rename
|
|
73 |
! !
|
|
74 |
|
3841
|
75 |
!FileOperation methodsFor:'accessing'!
|
|
76 |
|
|
77 |
errorString
|
|
78 |
"return the value of the static variable 'ErrorString' (automatically generated)"
|
|
79 |
|
|
80 |
^ errorString
|
|
81 |
!
|
|
82 |
|
|
83 |
errorString:something
|
|
84 |
"set the value of the static variable 'ErrorString' (automatically generated)"
|
|
85 |
|
|
86 |
errorString := something.
|
|
87 |
!
|
|
88 |
|
|
89 |
result
|
|
90 |
"return the value of the instance variable 'result' (automatically generated)"
|
|
91 |
|
|
92 |
^ result
|
|
93 |
!
|
|
94 |
|
|
95 |
result:something
|
|
96 |
"set the value of the instance variable 'result' (automatically generated)"
|
|
97 |
|
|
98 |
result := something.
|
|
99 |
! !
|
|
100 |
|
|
101 |
!FileOperation methodsFor:'dialogs'!
|
|
102 |
|
|
103 |
fileExistDialogFor:aFile
|
|
104 |
|
|
105 |
^ self fileExistDialogFor:aFile withCancel:false.
|
|
106 |
!
|
|
107 |
|
|
108 |
fileExistDialogFor:aFile withCancel:aBoolean
|
|
109 |
| stream string|
|
|
110 |
|
|
111 |
aFile exists ifTrue:[
|
|
112 |
stream := WriteStream on:''.
|
|
113 |
stream nextPutAll:'overwrite '.
|
|
114 |
stream nextPutAll:(aFile asString).
|
|
115 |
stream nextPutAll:' from '.
|
|
116 |
(aFile modificationTime) printOn:stream format:'%(Day)-%(mon)-%(year) %h:%m:%s'.
|
|
117 |
stream nextPutAll:' with size of '.
|
|
118 |
stream nextPutAll:aFile fileSize asString.
|
|
119 |
stream cr.
|
|
120 |
stream nextPutAll:' with '.
|
|
121 |
stream nextPutAll:aFile asString.
|
|
122 |
stream nextPutAll:' from '.
|
|
123 |
(aFile modificationTime) printOn:stream format:'%(Day)-%(mon)-%(year) %h:%m:%s'.
|
|
124 |
stream nextPutAll:' with size of '.
|
|
125 |
stream nextPutAll:aFile fileSize asString.
|
|
126 |
string := stream contents.
|
|
127 |
stream close.
|
|
128 |
aBoolean ifTrue:[
|
|
129 |
^ (Dialog confirmWithCancel:(string)).
|
|
130 |
] ifFalse:[
|
|
131 |
^ (Dialog confirm:(string)).
|
|
132 |
].
|
|
133 |
].
|
|
134 |
^ true
|
|
135 |
! !
|
|
136 |
|
3842
|
137 |
!FileOperation::Copy class methodsFor:'actions'!
|
|
138 |
|
|
139 |
copyFile:aSourceFile to:aDestFile
|
|
140 |
"delete current selected files/directories
|
|
141 |
"
|
|
142 |
|
|
143 |
|instance|
|
|
144 |
|
|
145 |
instance := self new.
|
|
146 |
instance copyFile:aSourceFile to:aDestFile.
|
|
147 |
^ instance
|
|
148 |
!
|
|
149 |
|
|
150 |
copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning
|
|
151 |
"delete current selected files/directories
|
|
152 |
"
|
|
153 |
|
|
154 |
|instance|
|
|
155 |
|
|
156 |
instance := self new.
|
|
157 |
instance copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning.
|
|
158 |
^ instance
|
|
159 |
!
|
|
160 |
|
|
161 |
copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning copyFileIfSame:copy
|
|
162 |
"delete current selected files/directories
|
|
163 |
"
|
|
164 |
|
|
165 |
|instance|
|
|
166 |
|
|
167 |
instance := self new.
|
|
168 |
instance copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning copyFileIfSame:copy.
|
|
169 |
^ instance
|
|
170 |
!
|
|
171 |
|
|
172 |
copyFiles:aColOfSourceFiles to:aDirectory
|
|
173 |
"delete current selected files/directories
|
|
174 |
"
|
|
175 |
|
|
176 |
|instance|
|
|
177 |
|
|
178 |
instance := self new.
|
|
179 |
instance copyFiles:aColOfSourceFiles to:aDirectory.
|
|
180 |
^ instance
|
|
181 |
!
|
|
182 |
|
|
183 |
copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning
|
|
184 |
"delete current selected files/directories
|
|
185 |
"
|
|
186 |
|
|
187 |
|instance|
|
|
188 |
|
|
189 |
instance := self new.
|
|
190 |
instance copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning.
|
|
191 |
^ instance
|
|
192 |
!
|
|
193 |
|
|
194 |
copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning copyFileIfSame:copy
|
|
195 |
"delete current selected files/directories
|
|
196 |
"
|
|
197 |
|
|
198 |
|instance|
|
|
199 |
|
|
200 |
instance := self new.
|
|
201 |
instance copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning copyFileIfSame:copy.
|
|
202 |
^ instance
|
|
203 |
! !
|
|
204 |
|
|
205 |
!FileOperation::Copy class methodsFor:'documentation'!
|
|
206 |
|
|
207 |
version
|
3848
|
208 |
^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.3 2002-09-05 12:38:22 penk Exp $'
|
3842
|
209 |
! !
|
|
210 |
|
|
211 |
!FileOperation::Copy methodsFor:'accessing'!
|
|
212 |
|
|
213 |
colOfCopiedFiles
|
|
214 |
"return the value of the instance variable 'colOfCopiedFiles' (automatically generated)"
|
|
215 |
|
|
216 |
colOfCopiedFiles isNil ifTrue:[
|
|
217 |
colOfCopiedFiles := OrderedCollection new.
|
|
218 |
].
|
|
219 |
^ colOfCopiedFiles
|
|
220 |
! !
|
|
221 |
|
|
222 |
!FileOperation::Copy methodsFor:'actions'!
|
|
223 |
|
|
224 |
copyFile:aSourceFile to:aDestFile
|
|
225 |
"defete current selected files/directories
|
|
226 |
"
|
|
227 |
|
|
228 |
self copyFile:aSourceFile to:aDestFile withOverWriteWarning:true
|
|
229 |
!
|
|
230 |
|
|
231 |
copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning
|
|
232 |
"copy to
|
|
233 |
"
|
|
234 |
|
|
235 |
self copyFile:aSourceFile to:aDestFile withOverWriteWarning:true copyFileIfSame:true
|
|
236 |
!
|
|
237 |
|
|
238 |
copyFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning copyFileIfSame:copy
|
|
239 |
"copy to
|
|
240 |
"
|
|
241 |
|
|
242 |
|newFile fileString targetDirectory targetIsDirectory sourceIsDirectory suffix|
|
|
243 |
|
|
244 |
sourceIsDirectory := aSourceFile isDirectory.
|
|
245 |
targetIsDirectory := aDestFile isDirectory.
|
|
246 |
targetIsDirectory ifTrue:[
|
|
247 |
targetDirectory := aDestFile.
|
|
248 |
newFile := aDestFile construct:(aSourceFile baseName).
|
|
249 |
] ifFalse:[
|
|
250 |
targetDirectory := aDestFile directory.
|
|
251 |
newFile := aDestFile.
|
|
252 |
].
|
|
253 |
"/ do not copy if destination directory doest exist.
|
|
254 |
(targetDirectory exists not) ifTrue:[
|
|
255 |
DialogBox warn:'cant copy to not existing directory ', targetDirectory asString.
|
|
256 |
result := false.
|
|
257 |
^ self
|
|
258 |
].
|
|
259 |
(newFile exists) ifTrue:[
|
|
260 |
((newFile asString = aSourceFile asString) and:[copy]) ifTrue:[
|
|
261 |
[newFile exists] whileTrue:[
|
|
262 |
suffix := newFile suffix.
|
|
263 |
fileString := newFile baseName withoutSuffix, self class copyMoveIfExistSuffixString, '.', suffix.
|
|
264 |
newFile := targetDirectory construct:fileString.
|
|
265 |
].
|
|
266 |
] ifFalse:[
|
|
267 |
overWriteWarning ifTrue:[
|
|
268 |
(self fileExistDialogFor:newFile) ifFalse:[
|
|
269 |
result := false.
|
|
270 |
^ self.
|
|
271 |
]
|
|
272 |
] ifFalse:[
|
|
273 |
result := false.
|
|
274 |
^ self.
|
|
275 |
]
|
|
276 |
].
|
|
277 |
].
|
|
278 |
Error handle:[:ex|
|
|
279 |
"was not able to copy it"
|
|
280 |
WarningBox warn:'on copy file - ', ex errorString.
|
|
281 |
self errorString:('on copy file - ', ex description asString).
|
|
282 |
result := false.
|
|
283 |
] do:[
|
|
284 |
sourceIsDirectory ifTrue:[
|
|
285 |
OperatingSystem recursiveCopyDirectory:(aSourceFile pathName)
|
|
286 |
to:newFile.
|
|
287 |
] ifFalse:[
|
|
288 |
aSourceFile copyTo:newFile.
|
|
289 |
].
|
|
290 |
DirectoryContents flushCachedDirectory:(aSourceFile directory).
|
|
291 |
result := true.
|
|
292 |
].
|
|
293 |
!
|
|
294 |
|
|
295 |
copyFiles:aColOfSourceFiles to:aDirectory
|
|
296 |
|
|
297 |
^ self copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:true.
|
|
298 |
!
|
|
299 |
|
|
300 |
copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning
|
|
301 |
|
|
302 |
^ self copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning copyFileIfSame:true.
|
|
303 |
!
|
|
304 |
|
|
305 |
copyFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning copyFileIfSame:copy
|
|
306 |
|
|
307 |
|
|
308 |
|newFile suffix fileString sourceIsDirectory askResult|
|
|
309 |
|
|
310 |
(aDirectory exists not) ifTrue:[
|
|
311 |
DialogBox warn:'cant copy to not existing directory ', aDirectory asString.
|
|
312 |
result := false.
|
|
313 |
^ self
|
|
314 |
].
|
|
315 |
(aDirectory isDirectory not) ifTrue:[
|
|
316 |
DialogBox warn:'destination ', aDirectory asString, ' is not a directory'.
|
|
317 |
result := false.
|
|
318 |
^ self
|
|
319 |
].
|
|
320 |
aColOfSourceFiles do:[: filename |
|
|
321 |
newFile := aDirectory construct:(filename baseName).
|
|
322 |
sourceIsDirectory := filename isDirectory.
|
|
323 |
(newFile exists) ifTrue:[
|
|
324 |
askResult := true.
|
|
325 |
((newFile asString = filename asString) and:[copy]) ifTrue:[
|
|
326 |
[newFile exists] whileTrue:[
|
|
327 |
suffix := newFile suffix.
|
|
328 |
fileString := newFile baseName withoutSuffix, self class copyMoveIfExistSuffixString, '.', suffix.
|
|
329 |
newFile := aDirectory construct:fileString.
|
|
330 |
].
|
|
331 |
] ifFalse:[
|
|
332 |
overWriteWarning ifTrue:[
|
|
333 |
askResult := (self fileExistDialogFor:newFile withCancel:true).
|
|
334 |
askResult isNil ifTrue:[
|
|
335 |
result := false.
|
|
336 |
^ self.
|
|
337 |
]
|
|
338 |
]
|
|
339 |
].
|
|
340 |
].
|
|
341 |
askResult ifTrue:[
|
|
342 |
Error handle:[:ex|
|
|
343 |
"was not able to copy it"
|
|
344 |
result := false.
|
|
345 |
self errorString:('on copy file - ', ex description asString).
|
|
346 |
( Dialog
|
|
347 |
confirm:('error on copy file - ', ex description asString)
|
|
348 |
title:'Copy'
|
|
349 |
yesLabel:'Continue'
|
|
350 |
noLabel:'Abort') ifFalse:[
|
|
351 |
^ self.
|
|
352 |
].
|
|
353 |
] do:[
|
|
354 |
sourceIsDirectory ifTrue:[
|
|
355 |
OperatingSystem recursiveCopyDirectory:(filename asString)
|
|
356 |
to:(newFile asString).
|
|
357 |
] ifFalse:[
|
|
358 |
filename copyTo:newFile.
|
|
359 |
].
|
|
360 |
].
|
|
361 |
self colOfCopiedFiles add:filename
|
|
362 |
]
|
|
363 |
].
|
|
364 |
DirectoryContents flushCachedDirectory:aDirectory.
|
|
365 |
result := true.
|
|
366 |
! !
|
|
367 |
|
|
368 |
!FileOperation::Create class methodsFor:'actions'!
|
|
369 |
|
|
370 |
createDirectory:newName
|
|
371 |
|
|
372 |
|instance|
|
|
373 |
|
|
374 |
instance := self new.
|
|
375 |
instance createDirectory:newName.
|
|
376 |
^ instance
|
|
377 |
!
|
|
378 |
|
|
379 |
createFile:newName
|
|
380 |
|
|
381 |
|instance|
|
|
382 |
|
|
383 |
instance := self new.
|
|
384 |
instance createFile:newName.
|
|
385 |
^ instance
|
|
386 |
! !
|
|
387 |
|
|
388 |
!FileOperation::Create class methodsFor:'documentation'!
|
|
389 |
|
|
390 |
version
|
3848
|
391 |
^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.3 2002-09-05 12:38:22 penk Exp $'
|
3842
|
392 |
! !
|
|
393 |
|
|
394 |
!FileOperation::Create methodsFor:'actions'!
|
|
395 |
|
|
396 |
createDirectory:newName
|
|
397 |
|msg|
|
|
398 |
|
|
399 |
newName exists ifTrue:[
|
|
400 |
DialogBox warn:(newName, ' already exists.').
|
|
401 |
result := false.
|
|
402 |
^ self
|
|
403 |
].
|
|
404 |
|
|
405 |
newName makeDirectory ifFalse:[
|
|
406 |
msg := errorString := ('cannot create directory '', newName,'' !!') , '\\(' , (OperatingSystem lastErrorString) , ')'.
|
|
407 |
errorString := msg withCRs.
|
|
408 |
DialogBox warn:errorString.
|
|
409 |
result := false.
|
|
410 |
^ self
|
|
411 |
].
|
|
412 |
result := true.
|
|
413 |
!
|
|
414 |
|
|
415 |
createFile:file
|
|
416 |
"create an empty file"
|
|
417 |
|
|
418 |
|aStream newName msg|
|
|
419 |
|
|
420 |
newName := file baseName.
|
|
421 |
file exists ifTrue:[
|
|
422 |
(Dialog
|
|
423 |
confirm:(newName, ' already exists\\truncate ?') withCRs
|
|
424 |
yesLabel:('Truncate')
|
|
425 |
noLabel:('Cancel'))
|
|
426 |
ifFalse:[^ self].
|
|
427 |
].
|
|
428 |
|
|
429 |
FileStream openErrorSignal handle:[:ex|
|
|
430 |
msg := ('Cannot create file '', newName,'' !!') , '\\(' , (FileStream lastErrorString) , ')'.
|
|
431 |
errorString := msg withCRs.
|
|
432 |
^ DialogBox warn:errorString
|
|
433 |
] do:[
|
|
434 |
aStream := file newReadWriteStream.
|
|
435 |
].
|
|
436 |
aStream notNil ifTrue:[
|
|
437 |
aStream close.
|
|
438 |
] ifFalse:[
|
|
439 |
msg := ('Cannot create file '', newName, '' !!') , '\\(' , (FileStream lastErrorString) , ')'.
|
|
440 |
errorString := msg withCRs.
|
|
441 |
^ DialogBox warn:errorString
|
|
442 |
].
|
|
443 |
! !
|
|
444 |
|
|
445 |
!FileOperation::Delete class methodsFor:'actions'!
|
|
446 |
|
|
447 |
deleteFile:aFileOrDirectory
|
|
448 |
"delete current selected files/directories
|
|
449 |
"
|
|
450 |
|
|
451 |
|instance|
|
|
452 |
|
|
453 |
instance := self new.
|
|
454 |
instance deleteFile:aFileOrDirectory.
|
|
455 |
^ instance
|
|
456 |
!
|
|
457 |
|
|
458 |
deleteFiles:aColOfFiles
|
|
459 |
"delete current selected files/directories
|
|
460 |
"
|
|
461 |
|
|
462 |
|instance|
|
|
463 |
|
|
464 |
instance := self new.
|
|
465 |
instance deleteFiles:aColOfFiles.
|
|
466 |
^ instance
|
|
467 |
! !
|
|
468 |
|
|
469 |
!FileOperation::Delete class methodsFor:'documentation'!
|
|
470 |
|
|
471 |
version
|
3848
|
472 |
^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.3 2002-09-05 12:38:22 penk Exp $'
|
3842
|
473 |
! !
|
|
474 |
|
|
475 |
!FileOperation::Delete methodsFor:'actions'!
|
|
476 |
|
|
477 |
deleteFile:aFileOrDirectory
|
|
478 |
|
|
479 |
| file isDirectory |
|
|
480 |
|
|
481 |
aFileOrDirectory notNil ifTrue:[
|
|
482 |
file := aFileOrDirectory asFilename.
|
|
483 |
|
|
484 |
file exists ifTrue:[
|
|
485 |
isDirectory := file isDirectory.
|
|
486 |
|
|
487 |
Error handle:[:ex|
|
|
488 |
"was not able to remove it"
|
|
489 |
Smalltalk beep.
|
|
490 |
self errorString:((ex description, '\', ex signal notifierString) withCRs).
|
|
491 |
result := false.
|
|
492 |
] do:[
|
|
493 |
isDirectory ifTrue:[file recursiveRemove] ifFalse:[file remove].
|
|
494 |
|
|
495 |
"/ flush parent directory or directory
|
|
496 |
DirectoryContents flushCachedDirectory:(file directory).
|
|
497 |
]
|
|
498 |
]
|
|
499 |
].
|
|
500 |
result := true.
|
|
501 |
!
|
|
502 |
|
|
503 |
deleteFiles:colOfFiles
|
|
504 |
"delete current selected files/directories
|
|
505 |
"
|
|
506 |
| retVal ask size|
|
|
507 |
|
|
508 |
ask := true.
|
|
509 |
size := colOfFiles size.
|
|
510 |
colOfFiles do:[: filename |
|
|
511 |
ask ifTrue:[
|
|
512 |
size = 1 ifTrue:[
|
|
513 |
retVal := Dialog
|
|
514 |
confirmWithCancel:('really delete ', filename asString , ' ?')
|
|
515 |
labels:#('Yes' 'No' 'Cancel')
|
|
516 |
values:#(#yes #no #cancel)
|
|
517 |
default:1.
|
|
518 |
] ifFalse:[
|
|
519 |
retVal := Dialog
|
|
520 |
confirmWithCancel:('really delete ', filename asString , ' ?')
|
|
521 |
labels:#('Yes' 'No' 'Yes to All' 'Cancel')
|
|
522 |
values:#(#yes #no #yesToAll #cancel)
|
|
523 |
default:1.
|
|
524 |
]
|
|
525 |
].
|
|
526 |
retVal == #cancel ifTrue:[
|
|
527 |
^ self.
|
|
528 |
].
|
|
529 |
retVal == #yes ifTrue:[
|
|
530 |
self deleteFile:filename.
|
|
531 |
].
|
|
532 |
retVal == #yesToAll ifTrue:[
|
|
533 |
self deleteFile:filename.
|
|
534 |
ask := false.
|
|
535 |
retVal := #yes.
|
|
536 |
].
|
|
537 |
].
|
|
538 |
! !
|
|
539 |
|
|
540 |
!FileOperation::Move class methodsFor:'actions'!
|
|
541 |
|
|
542 |
moveFile:aSourceFile to:aDestFile
|
|
543 |
"delete current selected files/directories
|
|
544 |
"
|
|
545 |
|
|
546 |
|instance|
|
|
547 |
|
|
548 |
instance := self new.
|
|
549 |
instance moveFile:aSourceFile to:aDestFile.
|
|
550 |
^ instance
|
|
551 |
!
|
|
552 |
|
|
553 |
moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning
|
|
554 |
"delete current selected files/directories
|
|
555 |
"
|
|
556 |
|
|
557 |
|instance|
|
|
558 |
|
|
559 |
instance := self new.
|
|
560 |
instance moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning.
|
|
561 |
^ instance
|
|
562 |
!
|
|
563 |
|
|
564 |
moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning moveFileIfSame:move
|
|
565 |
"delete current selected files/directories
|
|
566 |
"
|
|
567 |
|
|
568 |
|instance|
|
|
569 |
|
|
570 |
instance := self new.
|
|
571 |
instance moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning moveFileIfSame:move.
|
|
572 |
^ instance
|
|
573 |
!
|
|
574 |
|
|
575 |
moveFiles:aColOfSourceFiles to:aDirectory
|
|
576 |
"delete current selected files/directories
|
|
577 |
"
|
|
578 |
|
|
579 |
|instance|
|
|
580 |
|
|
581 |
instance := self new.
|
|
582 |
instance moveFiles:aColOfSourceFiles to:aDirectory.
|
|
583 |
^ instance
|
|
584 |
!
|
|
585 |
|
|
586 |
moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning
|
|
587 |
"delete current selected files/directories
|
|
588 |
"
|
|
589 |
|
|
590 |
|instance|
|
|
591 |
|
|
592 |
instance := self new.
|
|
593 |
instance moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning.
|
|
594 |
^ instance
|
|
595 |
!
|
|
596 |
|
|
597 |
moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning moveFileIfSame:move
|
|
598 |
"delete current selected files/directories
|
|
599 |
"
|
|
600 |
|
|
601 |
|instance|
|
|
602 |
|
|
603 |
instance := self new.
|
|
604 |
instance moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning moveFileIfSame:move.
|
|
605 |
^ instance
|
|
606 |
! !
|
|
607 |
|
|
608 |
!FileOperation::Move class methodsFor:'documentation'!
|
|
609 |
|
|
610 |
version
|
3848
|
611 |
^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.3 2002-09-05 12:38:22 penk Exp $'
|
3842
|
612 |
! !
|
|
613 |
|
|
614 |
!FileOperation::Move methodsFor:'accessing'!
|
|
615 |
|
|
616 |
colOfMovedFiles
|
|
617 |
"return the value of the instance variable 'colOfMovedFiles' (automatically generated)"
|
|
618 |
|
|
619 |
colOfMovedFiles isNil ifTrue:[
|
|
620 |
colOfMovedFiles := OrderedCollection new.
|
|
621 |
].
|
|
622 |
^ colOfMovedFiles
|
|
623 |
! !
|
|
624 |
|
|
625 |
!FileOperation::Move methodsFor:'actions'!
|
|
626 |
|
|
627 |
moveFile:aSourceFile to:aDestFile
|
|
628 |
|
|
629 |
^ self moveFile:aSourceFile to:aDestFile withOverWriteWarning:true.
|
|
630 |
!
|
|
631 |
|
|
632 |
moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning
|
|
633 |
|
|
634 |
^ self moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning moveFileIfSame:true
|
|
635 |
!
|
|
636 |
|
|
637 |
moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning moveFileIfSame:move
|
|
638 |
|
|
639 |
|newFile fileString targetDirectory targetIsDirectory suffix|
|
|
640 |
|
|
641 |
targetIsDirectory := aDestFile isDirectory.
|
|
642 |
targetIsDirectory ifTrue:[
|
|
643 |
targetDirectory := aDestFile.
|
|
644 |
newFile := aDestFile construct:(aSourceFile baseName).
|
|
645 |
] ifFalse:[
|
|
646 |
targetDirectory := aDestFile directory.
|
|
647 |
newFile := aDestFile.
|
|
648 |
].
|
|
649 |
"/ do not copy if destination directory doest exist.
|
|
650 |
(targetDirectory exists not) ifTrue:[
|
|
651 |
DialogBox warn:'cant move to not existing directory ', targetDirectory asString.
|
|
652 |
result := false.
|
|
653 |
^ self
|
|
654 |
].
|
|
655 |
(newFile exists) ifTrue:[
|
|
656 |
((newFile asString = aSourceFile asString) and:[move]) ifTrue:[
|
|
657 |
[newFile exists] whileTrue:[
|
|
658 |
suffix := newFile suffix.
|
|
659 |
fileString := newFile baseName withoutSuffix, self class copyMoveIfExistSuffixString, '.', suffix.
|
|
660 |
newFile := targetDirectory construct:fileString.
|
|
661 |
].
|
|
662 |
] ifFalse:[
|
|
663 |
overWriteWarning ifTrue:[
|
|
664 |
(self fileExistDialogFor:newFile) ifFalse:[
|
|
665 |
result := false.
|
|
666 |
^ self.
|
|
667 |
]
|
|
668 |
] ifFalse:[
|
|
669 |
result := false.
|
|
670 |
^ self.
|
|
671 |
]
|
|
672 |
].
|
|
673 |
].
|
|
674 |
Error handle:[:ex|
|
|
675 |
"was not able to copy it"
|
|
676 |
WarningBox warn:'on copy file - ', ex errorString.
|
|
677 |
self errorString:('on copy file - ', ex description asString).
|
|
678 |
result := false.
|
|
679 |
] do:[
|
|
680 |
aSourceFile moveTo:newFile.
|
|
681 |
DirectoryContents flushCachedDirectory:(aSourceFile directory).
|
|
682 |
result := true.
|
|
683 |
].
|
|
684 |
!
|
|
685 |
|
|
686 |
moveFiles:aColOfSourceFiles to:aDirectory
|
|
687 |
|
|
688 |
^ self moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:true
|
|
689 |
!
|
|
690 |
|
|
691 |
moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning
|
|
692 |
|
|
693 |
^ self moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning moveFileIfSame:true
|
|
694 |
!
|
|
695 |
|
|
696 |
moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning moveFileIfSame:move
|
|
697 |
|
|
698 |
|newFile suffix fileString askResult|
|
|
699 |
|
|
700 |
(aDirectory exists not) ifTrue:[
|
|
701 |
DialogBox warn:'cant move to not existing directory ', aDirectory asString.
|
|
702 |
result := false.
|
|
703 |
^ self
|
|
704 |
].
|
|
705 |
(aDirectory isDirectory not) ifTrue:[
|
|
706 |
DialogBox warn:'destination ', aDirectory asString, ' is not a directory'.
|
|
707 |
result := false.
|
|
708 |
^ self
|
|
709 |
].
|
|
710 |
aColOfSourceFiles do:[: filename |
|
|
711 |
newFile := aDirectory construct:filename baseName.
|
|
712 |
(newFile exists) ifTrue:[
|
|
713 |
askResult := true.
|
|
714 |
((newFile asString = filename asString) and:[move]) ifTrue:[
|
|
715 |
[newFile exists] whileTrue:[
|
|
716 |
suffix := newFile suffix.
|
|
717 |
fileString := newFile baseName withoutSuffix, self class copyMoveIfExistSuffixString, '.', suffix.
|
|
718 |
newFile := aDirectory construct:fileString.
|
|
719 |
].
|
|
720 |
] ifFalse:[
|
|
721 |
overWriteWarning ifTrue:[
|
|
722 |
askResult := (self fileExistDialogFor:newFile withCancel:true).
|
|
723 |
askResult isNil ifTrue:[
|
|
724 |
result := false.
|
|
725 |
^ self.
|
|
726 |
]
|
|
727 |
]
|
|
728 |
].
|
|
729 |
].
|
|
730 |
askResult ifTrue:[
|
|
731 |
Error handle:[:ex|
|
|
732 |
"was not able to copy it"
|
|
733 |
result := false.
|
|
734 |
self errorString:('on move file - ', ex description asString).
|
|
735 |
( Dialog
|
|
736 |
confirm:('error on move file - ', ex description asString)
|
|
737 |
title:'Move'
|
|
738 |
yesLabel:'Continue'
|
|
739 |
noLabel:'Abort') ifFalse:[
|
|
740 |
^ self.
|
|
741 |
].
|
|
742 |
] do:[
|
|
743 |
filename moveTo:newFile.
|
|
744 |
].
|
|
745 |
self colOfMovedFiles add:filename
|
|
746 |
]
|
|
747 |
].
|
|
748 |
DirectoryContents flushCachedDirectory:aDirectory.
|
|
749 |
result := true.
|
|
750 |
! !
|
|
751 |
|
|
752 |
!FileOperation::Rename class methodsFor:'actions'!
|
|
753 |
|
|
754 |
renameFile:oldFile to:newName
|
|
755 |
"move from to
|
|
756 |
"
|
|
757 |
|
|
758 |
|instance|
|
|
759 |
|
|
760 |
instance := self new.
|
|
761 |
instance renameFile:oldFile to:newName.
|
|
762 |
^ instance
|
|
763 |
!
|
|
764 |
|
|
765 |
renameFiles:aColOfFiles
|
|
766 |
"move from to
|
|
767 |
"
|
|
768 |
|
|
769 |
|instance|
|
|
770 |
|
|
771 |
instance := self new.
|
|
772 |
instance renameFiles:aColOfFiles.
|
|
773 |
^ instance
|
|
774 |
! !
|
|
775 |
|
|
776 |
!FileOperation::Rename class methodsFor:'defaults'!
|
|
777 |
|
|
778 |
goodRenameDefaultFor:oldName lastOld:lastOldName lastNew:lastNewName
|
|
779 |
|prefix suffix lastNewSize lastOldSize t
|
|
780 |
lastOldWOSuffix lastNewWOSuffix oldWOSuffix lastOldRest oldRest lastNewRest
|
|
781 |
lastRemoved lastInserted|
|
|
782 |
|
|
783 |
lastNewName isNil ifTrue:[ ^ nil].
|
|
784 |
|
|
785 |
lastNewSize := lastNewName size.
|
|
786 |
lastOldSize := lastOldName size.
|
|
787 |
|
|
788 |
"/ intelligent default ...
|
|
789 |
(lastNewName endsWith:lastOldName) ifTrue:[
|
|
790 |
prefix := lastNewName copyTo:(lastNewSize - lastOldSize).
|
|
791 |
^ (prefix , oldName).
|
|
792 |
].
|
|
793 |
(lastOldName endsWith:lastNewName) ifTrue:[
|
|
794 |
prefix := lastOldName copyTo:(lastOldSize - lastNewSize).
|
|
795 |
^ (oldName copyFrom:prefix size+1).
|
|
796 |
].
|
|
797 |
(lastOldName withoutSeparators = lastNewName) ifTrue:[
|
|
798 |
"/ intelligent default ...
|
|
799 |
^ oldName withoutSeparators.
|
|
800 |
].
|
|
801 |
(lastNewName startsWith:lastOldName) ifTrue:[
|
|
802 |
"/ intelligent default ...
|
|
803 |
suffix := lastNewName copyLast:(lastNewSize - lastOldSize).
|
|
804 |
^ (oldName , suffix).
|
|
805 |
].
|
|
806 |
(lastOldName startsWith:lastNewName) ifTrue:[
|
|
807 |
suffix := lastOldName copyLast:(lastOldSize - lastNewSize).
|
|
808 |
(oldName endsWith:suffix) ifTrue:[
|
|
809 |
^ (oldName copyWithoutLast:suffix size).
|
|
810 |
]
|
|
811 |
].
|
|
812 |
|
|
813 |
lastOldWOSuffix := lastOldName asFilename withoutSuffix name.
|
|
814 |
lastNewWOSuffix := lastNewName asFilename withoutSuffix name.
|
|
815 |
oldWOSuffix := oldName asFilename withoutSuffix name.
|
|
816 |
|
|
817 |
prefix := lastOldWOSuffix commonPrefixWith:oldWOSuffix.
|
|
818 |
(lastNewWOSuffix startsWith:prefix) ifTrue:[
|
|
819 |
lastOldRest := lastOldWOSuffix copyFrom:prefix size + 1.
|
|
820 |
lastNewRest := lastNewWOSuffix copyFrom:prefix size + 1.
|
|
821 |
oldRest := oldWOSuffix copyFrom:prefix size + 1.
|
|
822 |
|
|
823 |
(lastNewRest endsWith:lastOldRest) ifTrue:[
|
|
824 |
t := lastNewRest copyWithoutLast:lastOldRest size.
|
|
825 |
^ ((prefix , t , oldRest) asFilename withSuffix:oldName asFilename suffix) name
|
|
826 |
].
|
|
827 |
].
|
|
828 |
|
|
829 |
suffix := lastOldWOSuffix commonSuffixWith:lastNewWOSuffix.
|
|
830 |
suffix size > 0 ifTrue:[
|
|
831 |
"/ last change changed something at the beginning
|
|
832 |
prefix := oldWOSuffix commonPrefixWith:lastOldWOSuffix.
|
|
833 |
prefix size > 0 ifTrue:[
|
|
834 |
"/ this name starts with the same characters
|
|
835 |
lastRemoved := lastOldWOSuffix copyWithoutLast:suffix size.
|
|
836 |
lastInserted := lastNewWOSuffix copyWithoutLast:suffix size.
|
|
837 |
^ lastInserted , (oldName copyFrom:lastRemoved size + 1)
|
|
838 |
].
|
|
839 |
].
|
|
840 |
|
|
841 |
^ nil
|
|
842 |
! !
|
|
843 |
|
|
844 |
!FileOperation::Rename class methodsFor:'documentation'!
|
|
845 |
|
|
846 |
version
|
3848
|
847 |
^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.3 2002-09-05 12:38:22 penk Exp $'
|
3842
|
848 |
! !
|
|
849 |
|
|
850 |
!FileOperation::Rename methodsFor:'accessing'!
|
|
851 |
|
|
852 |
renamedFiles
|
|
853 |
"return the value of the instance variable 'lastRenamedFile' (automatically generated)"
|
|
854 |
|
|
855 |
renamedFiles isNil ifTrue:[
|
|
856 |
renamedFiles := OrderedCollection new.
|
|
857 |
].
|
|
858 |
^ renamedFiles
|
|
859 |
! !
|
|
860 |
|
|
861 |
!FileOperation::Rename methodsFor:'actions'!
|
|
862 |
|
|
863 |
renameFile:oldFile to:newName
|
|
864 |
"rename a file (or directory)"
|
|
865 |
|
|
866 |
|old new msg|
|
|
867 |
|
|
868 |
(oldFile isNil or:[newName isNil]) ifTrue:[
|
|
869 |
result := false
|
|
870 |
].
|
|
871 |
(oldFile asString isBlank or:[newName isBlank]) ifTrue:[
|
|
872 |
result := false
|
|
873 |
].
|
|
874 |
(oldFile baseName = newName) ifTrue:[
|
|
875 |
result := false
|
|
876 |
].
|
|
877 |
|
|
878 |
old := oldFile.
|
|
879 |
new := oldFile directory construct:newName.
|
|
880 |
|
|
881 |
OperatingSystem errorSignal handle:[:ex|
|
|
882 |
msg := ('Cannot rename file ', old baseName,' to ', newName,' !!'), '\\(' ,(OperatingSystem lastErrorString) , ')'.
|
|
883 |
DialogBox warn:msg withCRs.
|
|
884 |
result := false
|
|
885 |
] do:[
|
|
886 |
new exists ifTrue:[
|
|
887 |
(DialogBox confirm:(new baseName allBold, ' already exists - rename (i.e. overwrite) anyway ?'))
|
|
888 |
ifFalse:[
|
|
889 |
result := false.
|
|
890 |
^ self.
|
|
891 |
]
|
|
892 |
].
|
|
893 |
old renameTo:new.
|
|
894 |
self renamedFiles add:new.
|
|
895 |
].
|
|
896 |
result := true.
|
|
897 |
!
|
|
898 |
|
|
899 |
renameFiles:aColOfFiles
|
|
900 |
"rename the selected file(s)"
|
|
901 |
|
|
902 |
|queryBox b lastNewName lastOldName initialText oldName|
|
|
903 |
|
|
904 |
queryBox := FilenameEnterBox new.
|
|
905 |
queryBox okText:'Rename'.
|
|
906 |
aColOfFiles size > 1 ifTrue:[
|
|
907 |
b := queryBox addAbortButtonLabelled:'Cancel All'.
|
|
908 |
b action:[^ self]
|
|
909 |
].
|
|
910 |
aColOfFiles do:[:oldFile |
|
|
911 |
oldName := oldFile baseName asString.
|
|
912 |
queryBox title:('Rename ' , oldName , ' to:').
|
|
913 |
lastNewName notNil ifTrue:[
|
|
914 |
initialText := self class
|
|
915 |
goodRenameDefaultFor:oldName
|
|
916 |
lastOld:lastOldName
|
|
917 |
lastNew:lastNewName
|
|
918 |
].
|
|
919 |
initialText notNil ifTrue:[
|
|
920 |
queryBox initialText:initialText
|
|
921 |
] ifFalse:[
|
|
922 |
queryBox initialText:oldName
|
|
923 |
].
|
|
924 |
queryBox
|
|
925 |
action:[:newName |
|
|
926 |
(self renameFile:oldFile to:newName asString) ifTrue:[
|
|
927 |
result := true
|
|
928 |
].
|
|
929 |
lastOldName := oldName.
|
|
930 |
lastNewName := newName
|
|
931 |
].
|
|
932 |
queryBox showAtPointer
|
|
933 |
]
|
|
934 |
! !
|
|
935 |
|
3841
|
936 |
!FileOperation class methodsFor:'documentation'!
|
|
937 |
|
|
938 |
version
|
3848
|
939 |
^ '$Header: /cvs/stx/stx/libtool/FileOperation.st,v 1.3 2002-09-05 12:38:22 penk Exp $'
|
3841
|
940 |
! !
|