Marcel Taeumel uploaded a new version of Tools to project The Trunk: http://source.squeak.org/trunk/Tools-mt.1223.mcz
==================== Summary ====================
Name: Tools-mt.1223 Author: mt Time: 26 July 2023, 10:38:52.079063 am UUID: 40e74b7f-673b-7d44-bab8-b4e3f9334d72 Ancestors: Tools-mt.1222
In workspaces, add "load contents from file..." an a mechanism that restores those file contents on image startup. See Morphic-mt.2115.
=============== Diff against Tools-mt.1222 ===============
Item was added: + ----- Method: Model>>loadContents (in category '*Tools-file out') ----- + loadContents + "Load model contents from a text file and answers those contents. Answers nil if cancelled or errored." + + ^ (Project uiManager + chooseFileMatching: '*' + label: 'Load text contents from file...' translated) + ifNil: [false] ifNotNil: [:answer | answer ifEmpty: [false] + ifNotEmpty: [:fileName | self loadContentsFromFileNamed: fileName]]!
Item was added: + ----- Method: Model>>loadContentsFromFileNamed: (in category '*Tools-file out') ----- + loadContentsFromFileNamed: fileName + + ^ self + loadContentsFromFileNamed: fileName + workBlock: [:stream | stream "contents"]!
Item was added: + ----- Method: Model>>loadContentsFromFileNamed:workBlock: (in category '*Tools-file out') ----- + loadContentsFromFileNamed: fileName workBlock: workBlock + + FileStream + readOnlyFileNamed: fileName + do: [:stream | workBlock value: stream]. + ^ true!
Item was changed: ----- Method: Workspace>>addModelItemsToWindowMenu: (in category 'menu commands') ----- addModelItemsToWindowMenu: aMenu aMenu addLine. aMenu + add: 'load contents from file...' - add: 'change file name...' target: self + action: #loadContentsFromFile. - action: #changeFileName. aMenu add: 'save contents to file...' target: self action: #saveContentsInFile. aMenu addUpdating: #saveContentsInFileOnAcceptWording target: self action: #saveContentsInFileOnAccept. aMenu addUpdating: #appendContentsToFileOnAcceptWording target: self action: #appendContentsToFileOnAccept. + aMenu + add: 'change file name...' + target: self + action: #changeFileName. aMenu addLine. aMenu add: 'inspect variables' target: self action: #inspectBindings. aMenu add: 'reset variables' target: self action: #resetBindings. aMenu addLine. aMenu addUpdating: #mustDeclareVariableWording target: self action: #toggleVariableDeclarationMode. aMenu addUpdating: #acceptDroppedMorphsWording target: self action: #toggleDroppingMorphForReference.
self addToggleStylingMenuItemTo: aMenu. !
Item was added: + ----- Method: Workspace>>loadContentsFromFile (in category 'menu commands') ----- + loadContentsFromFile + + self okToChange ifFalse: [^ self]. + + self loadContents ifTrue: [ + "Reset append-to-file option if it was set so that enabling save-to-file works without extra prompt." + self appendContentsToFileOnAcceptEnabled ifTrue: [self acceptAction: nil]. + self saveContentsInFileOnAccept].!
Item was added: + ----- Method: Workspace>>loadContentsFromFileNamed: (in category 'user edits') ----- + loadContentsFromFileNamed: fileName + + ^ self + loadContentsFromFileNamed: fileName + workBlock: [:fileStream | + self fileLineEndConvention: fileStream detectLineEndConvention. + self contents: fileStream contents. + self changed: #contents]!
Item was added: + ----- Method: Workspace>>loadContentsFromFileNamed:workBlock: (in category 'user edits') ----- + loadContentsFromFileNamed: fileName workBlock: workBlock + + ^ (super loadContentsFromFileNamed: fileName workBlock: workBlock) + ifFalse: [false "no success"] + ifTrue: [self setFileName: fileName. true "success"]!
Item was added: + ----- Method: Workspace>>restoreContentsFromFile (in category 'user edits') ----- + restoreContentsFromFile + "When save-on-accept is enabled, reload the receivers contents from the associated file. Skip if append-on-accept is enabled as it would load redundant contents." + + | fn priorAction priorContents | + self saveContentsInFileOnAcceptEnabled ifFalse: [^ self]. + + priorAction := self acceptAction. "i.e., save-to-file" + self acceptAction: [:edits | true ]. "to silently fetch view contents" + self changed: #acceptChanges. "fetch view contents into model" + priorContents := contents. + self acceptAction: priorAction. + + ([self loadContentsFromFileNamed: (fn := self suggestedFileNameForSave)] + valueSupplyingAnswer: true "discard unsaved changes") + ifTrue: [ + priorContents ~= contents ifTrue: [ + Transcript showln: ('{1} contents restored from: {2}' format: { self class. fn}). + priorContents editWithLabel: self windowTitle, ' (prior in-image contents)']].!
packages@lists.squeakfoundation.org