diff -r 51c53d6656f4 -r 91ec771207a2 Create.st --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Create.st Tue Sep 03 17:23:22 2002 +0200 @@ -0,0 +1,86 @@ +"{ Package: 'stx:libtool2' }" + +FileOperations subclass:#Create + instanceVariableNames:'' + classVariableNames:'' + poolDictionaries:'' + category:'Interface-Support' +! + + +!Create class methodsFor:'actions'! + +createDirectory:newName + + |instance| + + instance := self new. + instance createDirectory:newName. + ^ instance +! + +createFile:newName + + |instance| + + instance := self new. + instance createFile:newName. + ^ instance +! ! + +!Create methodsFor:'actions'! + +createDirectory:newName + |msg| + + newName exists ifTrue:[ + DialogBox warn:(newName, ' already exists.'). + result := false. + ^ self + ]. + + newName makeDirectory ifFalse:[ + msg := errorString := ('cannot create directory '', newName,'' !!') , '\\(' , (OperatingSystem lastErrorString) , ')'. + errorString := msg withCRs. + DialogBox warn:errorString. + result := false. + ^ self + ]. + result := true. +! + +createFile:file + "create an empty file" + + |aStream newName msg| + + newName := file baseName. + file exists ifTrue:[ + (Dialog + confirm:(newName, ' already exists\\truncate ?') withCRs + yesLabel:('Truncate') + noLabel:('Cancel')) + ifFalse:[^ self]. + ]. + + FileStream openErrorSignal handle:[:ex| + msg := ('Cannot create file '', newName,'' !!') , '\\(' , (FileStream lastErrorString) , ')'. + errorString := msg withCRs. + ^ DialogBox warn:errorString + ] do:[ + aStream := file newReadWriteStream. + ]. + aStream notNil ifTrue:[ + aStream close. + ] ifFalse:[ + msg := ('Cannot create file '', newName, '' !!') , '\\(' , (FileStream lastErrorString) , ')'. + errorString := msg withCRs. + ^ DialogBox warn:errorString + ]. +! ! + +!Create class methodsFor:'documentation'! + +version + ^ '$Header$' +! !