[squeak-dev] The Trunk: Kernel-mt.1424.mcz
commits at source.squeak.org
commits at source.squeak.org
Thu Nov 25 10:50:31 UTC 2021
Marcel Taeumel uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-mt.1424.mcz
==================== Summary ====================
Name: Kernel-mt.1424
Author: mt
Time: 25 November 2021, 11:50:28.227354 am
UUID: 0c871da1-4809-5545-aa5e-576509240c89
Ancestors: Kernel-ct.1423
Complements Tools-mt.1075
=============== Diff against Kernel-ct.1423 ===============
Item was added:
+ ----- Method: Model>>cleanFileNameForSave: (in category 'user interface - 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 'user interface - 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 'user interface - file out') -----
+ saveContents: stringContents
+ "Interactive. See #saveContents:accessMode:."
+
+ ^ self
+ saveContents: stringContents
+ accessMode: #create!
Item was added:
+ ----- Method: Model>>saveContents:accessMode: (in category 'user interface - 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 'user interface - 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 'user interface - 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 'user interface - file out') -----
+ suggestedFileNameForSave
+
+ ^ self cleanFileNameForSave: self defaultFileNameForSave!
More information about the Squeak-dev
mailing list
|