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