[squeak-dev] The Trunk: Tools-mt.1079.mcz
commits at source.squeak.org
commits at source.squeak.org
Mon Nov 29 17:36:41 UTC 2021
Marcel Taeumel uploaded a new version of Tools to project The Trunk:
http://source.squeak.org/trunk/Tools-mt.1079.mcz
==================== Summary ====================
Name: Tools-mt.1079
Author: mt
Time: 29 November 2021, 6:36:37.617615 pm
UUID: c92da027-c262-4fd2-9a02-fb7bce9a6cbc
Ancestors: Tools-mt.1078
Clean-up dependencies. Moves the save-contents protocol from Kernel/Collections/Morphic/ST80 to the Tools package.
=============== Diff against Tools-mt.1078 ===============
Item was added:
+ ----- Method: Model>>cleanFileNameForSave: (in category '*Tools-file out') -----
+ cleanFileNameForSave: aString
+ "Removes selected decoration (i.e., leader+trailer) of aString. This decoration usually comes from window titles and the desire to reuse those titles as a file name.
+ NOTE THAT if only the decoration's leader matches, any existing file extension will be removed.
+ NOTE THAT if no decoration matches, the '.text' extension is appended if there is none.
+ SEE #defaultFileNameForSave."
+
+ | cleanFileName |
+ self flag: #discuss. "mt: Rename 'save' to 'fileOut'?"
+ cleanFileName := aString.
+
+ #( " 'leader' 'trailer' "
+ 'Decompressed contents of: ' '.gz'
+ "Add more here..."
+ ) groupsDo: [:leader :trailer |
+ self flag: #discuss. "mt: Maybe extract this feature into String and Text? See #withoutLeading* and #withoutTrailing*."
+ (cleanFileName beginsWith: leader) ifTrue: [
+ cleanFileName := cleanFileName allButFirst: leader size.
+ (cleanFileName endsWith: trailer)
+ ifTrue: [cleanFileName := cleanFileName allButLast: trailer size]
+ ifFalse: [
+ | lastIndex |
+ lastIndex := cleanFileName lastIndexOf: $. ifAbsent: [0].
+ lastIndex > 1 ifTrue: [
+ cleanFileName := cleanFileName copyFrom: 1 to: lastIndex - 1]] ]].
+
+ (cleanFileName = aString and: [(cleanFileName includes: $.) not])
+ ifTrue: [cleanFileName := cleanFileName, '.text'].
+
+ ^ cleanFileName!
Item was added:
+ ----- Method: Model>>defaultFileNameForSave (in category '*Tools-file out') -----
+ defaultFileNameForSave
+ "Answer a label that should be used as a file name when saving the receivers textual contents to disk. Note that the answer can also be a relative or absolute file path."
+
+ self flag: #discuss. "mt: Rename 'save' to 'fileOut'?"
+ ^ self containingWindow
+ ifNil: ['Untitled']
+ ifNotNil: [:window | window label]!
Item was added:
+ ----- Method: Model>>saveContents: (in category '*Tools-file out') -----
+ saveContents: stringContents
+ "Interactive. See #saveContents:accessMode:."
+
+ ^ self
+ saveContents: stringContents
+ accessMode: #create!
Item was added:
+ ----- Method: Model>>saveContents:accessMode: (in category '*Tools-file out') -----
+ saveContents: stringContents accessMode: accessMode
+ "Interactive callback from TextEditor. Ask the user for a file name/path, suggesting a (cleaned-up) default name to accept. Answers whether the save request was successful."
+
+ ^ (Project uiManager
+ saveFilenameRequest: 'Save text contents in file...'
+ initialAnswer: self suggestedFileNameForSave)
+ ifNil: [false] ifNotNil: [:answer | answer ifEmpty: [false]
+ ifNotEmpty: [:fileName |
+ self
+ saveContents: stringContents
+ onFileNamed: fileName
+ accessMode: accessMode]].!
Item was added:
+ ----- Method: Model>>saveContents:onFileNamed:accessMode: (in category '*Tools-file out') -----
+ saveContents: stringContents onFileNamed: fileName accessMode: accessMode
+
+ ^ self
+ saveContents: stringContents
+ onFileNamed: fileName
+ accessMode: accessMode
+ workBlock: [:fileStream | fileStream nextPutAll: stringContents]!
Item was added:
+ ----- Method: Model>>saveContents:onFileNamed:accessMode:workBlock: (in category '*Tools-file out') -----
+ saveContents: stringContents onFileNamed: fileName accessMode: accessMode workBlock: workBlock
+ "Save stringContents on fileName. Answers whether the save request was successful. On success, fileName will exist, including any new directories in the relative/absolute path.
+
+ accessMode
+ #create ... Prompt the user if file exists.
+ #update ... Replace all contents if file exists.
+ #append ... Append new contents if file exists."
+
+ (FileDirectory default on: fileName) containingDirectory assureExistence.
+ accessMode caseOf: {
+ [#create] -> [FileStream newFileNamed: fileName do: workBlock].
+ [#update] -> [FileStream forceNewFileNamed: fileName do: workBlock].
+ [#append] -> [FileStream fileNamed: fileName do: [:s | s setToEnd. workBlock value: s]] }
+ otherwise: [
+ self error: 'Unknown file access mode: ', accessMode printString.
+ ^ false].
+
+ Transcript showln: ('{1} contents saved (via {2}) to: {3}' format: { self class. accessMode printString. fileName }).
+ ^ true!
Item was added:
+ ----- Method: Model>>suggestedFileNameForSave (in category '*Tools-file out') -----
+ suggestedFileNameForSave
+
+ ^ self cleanFileNameForSave: self defaultFileNameForSave!
Item was added:
+ ----- Method: PluggableTextMorph>>saveContentsInFile (in category '*Tools-file out') -----
+ saveContentsInFile
+ self handleEdit: [textMorph editor saveContentsInFile]!
Item was added:
+ ----- Method: TextEditor>>saveContentsInFile (in category '*Tools-file out') -----
+ saveContentsInFile
+ "Save the receiver's contents string to a file, which usually prompts the user for a file name."
+
+ self paragraph text string
+ ifEmpty: [self inform: 'Nothing to save.']
+ ifNotEmpty: [:stringToSave |
+ (self model saveContents: stringToSave accessMode: #create)
+ ifTrue: [
+ self flag: #discuss. "mt: Is this correct? Having unaccepted contents means that the model does not know about it. Do we assume that the model will also keep track of the stringToSave?"
+ self morph hasUnacceptedEdits: false]].!
Item was added:
+ ----- Method: TranscriptStream>>saveContents:accessMode: (in category '*Tools-file out') -----
+ saveContents: stringContents accessMode: accessMode
+ "Interactive callback from TextEditor. See commentary in Model class."
+
+ ^ (Project uiManager
+ saveFilenameRequest: 'Save text contents in file...'
+ initialAnswer: 'Transcript.text')
+ ifEmpty: [false]
+ ifNotEmpty: [:fileName |
+ Model new
+ saveContents: stringContents
+ onFileNamed: fileName
+ accessMode: accessMode].!
More information about the Squeak-dev
mailing list
|