Eliot Miranda uploaded a new version of Morphic to project The Trunk:
http://source.squeak.org/trunk/Morphic-eem.1705.mcz ==================== Summary ==================== Name: Morphic-eem.1705 Author: eem Time: 19 October 2020, 5:56:07.299121 pm UUID: bc2b5ee7-0019-4440-8a9e-0ff595cde4ff Ancestors: Morphic-eem.1704 ...and remember to track the target directory if it is changed. =============== Diff against Morphic-eem.1704 =============== Item was changed: ----- Method: TextEditor>>saveContentsInFile (in category 'menu messages') ----- saveContentsInFile "Save the receiver's contents string to a file, prompting the user for a file-name. Suggest a reasonable file-name." + | stringToSave parentWindow labelToUse suggestedName fileName | + (stringToSave := paragraph text string) isEmpty ifTrue: + [^self inform: 'nothing to save.']. + parentWindow := model dependents + detect: [:dep | dep isSystemWindow] + ifNone: [self error: 'could not find parent window']. + labelToUse := (parentWindow valueOfProperty: #myDir) + ifNil: [parentWindow label] + ifNotNil: [:dir| dir fullNameFor: parentWindow label]. - | fileName stringToSave parentWindow labelToUse suggestedName dir | - stringToSave := paragraph text string. - stringToSave size = 0 ifTrue: [^self inform: 'nothing to save.']. - parentWindow := model dependents - detect: [:dep | dep isKindOf: SystemWindow] - ifNone: [nil]. - dir := parentWindow valueOfProperty: #myDir. - labelToUse := - parentWindow - ifNil: ['Untitled'] - ifNotNil: [ - dir ifNil: [parentWindow label] - ifNotNil:[dir fullNameFor: parentWindow label]]. suggestedName := nil. + "can add more here..." + #(('Decompressed contents of: ' '.gz')) do: + [:pair | + [:leader :trailer| + (labelToUse beginsWith: leader) ifTrue: + [suggestedName := labelToUse allButFirst: leader size. + (labelToUse endsWith: trailer) + ifTrue: + [suggestedName := suggestedName allButLast: trailer size] + ifFalse: + [| lastIndex | + lastIndex := suggestedName lastIndexOf: $. ifAbsent: [0]. + lastIndex > 1 ifTrue: + [suggestedName := suggestedName copyFrom: 1 to: lastIndex - 1]]]] + valueWithArguments: pair]. + suggestedName ifNil: + [suggestedName := (labelToUse includes: $.) + ifTrue: [labelToUse] + ifFalse: [labelToUse, '.text']]. + fileName := UIManager default request: 'File name?' initialAnswer: suggestedName. + fileName isEmptyOrNil ifTrue: [^self]. + ((MultiByteFileStream newFileNamed: fileName) + lineEndConvention: (parentWindow valueOfProperty: #lineConversion); "nil is fine here..." + nextPutAll: stringToSave; + close; + directory) ifNotNil: + [:dir| + dir = FileDirectory default + ifTrue: [parentWindow removeProperty: #myDir] + ifFalse: [parentWindow setProperty: #myDir toValue: dir]. + fileName := dir localNameFor: fileName]. + suggestedName ~= fileName ifTrue: + [parentWindow label: ((fileName endsWith: '.text') ifTrue: [fileName allButLast: 5] ifFalse: [fileName])]. + self morph hasUnacceptedEdits: false! - #(#('Decompressed contents of: ' '.gz')) do: - [:leaderTrailer | | lastIndex | - "can add more here..." - - (labelToUse beginsWith: leaderTrailer first) - ifTrue: - [suggestedName := labelToUse copyFrom: leaderTrailer first size + 1 - to: labelToUse size. - (labelToUse endsWith: leaderTrailer last) - ifTrue: - [suggestedName := suggestedName copyFrom: 1 - to: suggestedName size - leaderTrailer last size] - ifFalse: - [lastIndex := suggestedName lastIndexOf: $. ifAbsent: [0]. - (lastIndex = 0 or: [lastIndex = 1]) - ifFalse: [suggestedName := suggestedName copyFrom: 1 to: lastIndex - 1]]]]. - suggestedName ifNil: [suggestedName := labelToUse. - (labelToUse includesSubstring: '.') ifFalse: [suggestedName := suggestedName , '.text']]. - fileName := UIManager default request: 'File name?' - initialAnswer: suggestedName. - fileName isEmptyOrNil - ifFalse: - [ |ns| - ns := MultiByteFileStream newFileNamed: fileName. - ns lineEndConvention: (parentWindow valueOfProperty: #lineConversion). - ns nextPutAll: stringToSave; - close. - suggestedName ~= fileName ifTrue:[parentWindow label: fileName]. - self morph hasUnacceptedEdits: false. - ]! |
Free forum by Nabble | Edit this page |