'From Squeak3.10.2 of ''5 June 2008'' [latest update: #7179] on 23 January 2020 at 4:09:38 pm'! Workspace subclass: #PersistentWorkspace instanceVariableNames: 'name toolMorph textMorph' classVariableNames: '' poolDictionaries: '' category: 'BabyUtilities-Utilities'! !PersistentWorkspace commentStamp: '20040201 13:39:22 TRee(Squeak3.6-5429-tree06.2)' prior: 0! The contents of a PersistentWorkspace resides on disk. The name of the file is the name of the window with a '.ws' extension. yellowMenu command 'rename window' also renames the file. The 'accept' command writes to disk, the 'cancel' command reads from disk. A new woskapce has not been accepted and is not on disk. ! !PersistentWorkspace methodsFor: 'code pane menu' stamp: 'Trygve 1/12/2014 11:50'! acceptContents: aText " Set aText to be the contents of the receiver. " " Write to file. " " Return true if happy " " 2007.11.08 Do not create new versions. " " 2007.11.10 TRee Overwrite file without asking. " " 2007.12.13. TRee. Bugfix. " " 2010.2.1 New file format. " self error: 'Not to be used.'. ^self. " super acceptContents: aText. (refStrm := ReferenceStream fileNamed: name , '.ws') ifNil: [self notify: 'I cannot save the workspace; ' , String cr , name , '.ws', ' may be a read-only file.'. ^false] ifNotNil: [refStrm nextPut: aText; close. ^ true]" " [aText storeOn: fileStrm. self contents: aText. ^ true]" ! ]style[(15 1 6 3 49 2 18 2 24 2 42 2 50 2 29 2 29 43 276 4 65 2)f2b,f2,f2i,f2,f2cblue;,f2,f2cblue;,f2,f2cblue;,f2,f2cblue;,f2,f2cblue;,f2,f2cblue;,f2,f2cblue;,f2,f2cblue;,f2,f2cblue;,f2! ! !PersistentWorkspace methodsFor: 'code pane menu' stamp: 'Trygve 3/1/2019 12:03'! acceptContents: aText notifying: foo " Set aText to be the contents of the receiver. " " Write to file. " " Return true if happy " " 2007.11.08 Do not create new versions. " " 2007.11.10 TRee Overwrite file without asking. " " 2007.12.13. TRee. Bugfix. " " 2010.2.1 New file format. " " 2014.01.10 Use ReferenceStream for write and read. " | refStrm | name := toolMorph label. [ refStrm := ReferenceStream fileNamed: name asString , '.ws'. refStrm nextPut: aText. textMorph hasUnacceptedEdits: false. ] ensure: [refStrm close]. ! ]style[(37 2 49 2 18 2 24 2 42 2 50 2 29 2 29 2 54 202)bf3,f3,cblue;f3,f3,cblue;f3,f3,cblue;f3,f3,cblue;f3,f3,cblue;f3,f3,cblue;f3,f3,cblue;f3,f3,cblue;f3,f3! ! !PersistentWorkspace methodsFor: 'code pane menu' stamp: 'Trygve 1/12/2014 12:11'! cancelContents: dummy " Read from file - if possible." " 2014.01.10 Use ReferenceStream for write and read. " | refStrm | [ refStrm := ReferenceStream fileNamed: name asString , '.ws'. textMorph setText: refStrm next] ensure: [refStrm close]. ! ]style[(15 1 6 2 32 2 54 11 1 70 31 27 3)f3b,f3,f3i,f3,f3cblue;,f2,f2cblue;,f2,f3,f2,f3,f2,f3! ! !PersistentWorkspace methodsFor: 'code pane menu' stamp: 'TRee 8/10/2009 14:08'! codePaneMenu: aMenu shifted: shifted " NOTE: PluggableTextMorph steals all no-argument menu items!!!!!! " " Menu items for the Workspace itself MUST have arguments. " | | ^shifted ifTrue: [ParagraphEditor shiftedYellowButtonMenu. "donorMenu := ParagraphEditor shiftedYellowButtonMenu. aMenu labels: donorMenu labelString lines: donorMenu lineArray selections: donorMenu selections"] ifFalse: [aMenu add: 'set font... (k)' target: textMorph selector: #offerFontMenu; add: 'find...(f)' target: textMorph selector: #find; add: 'find again (g)' target: textMorph selector: #findAgain; add: 'set search string (h)' target: textMorph selector: #setSearchString; addLine; add: 'do again (j)' target: textMorph selector: #again; add: 'undo (z)' target: textMorph selector: #undo; addLine; add: 'copy (c)' target: textMorph selector: #copySelection; add: 'cut (x)' target: textMorph selector: #cut; add: 'paste (v)' target: textMorph selector: #paste; add: 'paste...' target: textMorph selector: #pasteRecent; addLine; add: 'do it (d)' target: textMorph selector: #doIt; add: 'print it (p)' target: textMorph selector: #printIt; add: 'inspect it (i)' target: textMorph selector: #inspectIt; add: 'explore it (I)' target: textMorph selector: #exploreIt; add: 'debug it' target: textMorph selector: #debugIt; addLine; add: 'accept (s)' target: textMorph selector: #accept; " add: 'accept (s)' target: self selector: #acceptContents: argument: nil ;" add: 'cancel (l)' target: self selector: #cancelContents: argument: nil ; add: 'rename window' target: self selector: #renameWindow: argument: nil ; addLine; add: 'show bytecodes' target: textMorph selector: #showBytecodes; addLine; add: 'more...' target: textMorph selector: #shiftedTextPaneMenuRequest]. ! ! !PersistentWorkspace methodsFor: 'code pane menu' stamp: 'Trygve 1/12/2014 11:47'! okToChange self canDiscardEdits ifTrue: [^ true]. self changed: #wantToChange. ^ self canDiscardEdits ! ! !PersistentWorkspace methodsFor: 'code pane menu' stamp: 'Trygve 3/1/2019 11:24'! renameWindow: dummyArgument | newLabel | newLabel _ FillInTheBlank request: 'X Please type new workspace name' initialAnswer: name. newLabel = '' ifTrue: [^ self]. name := newLabel. toolMorph setLabel: name. textMorph hasUnacceptedEdits: true.! ! !PersistentWorkspace methodsFor: 'code pane menu' stamp: 'Trygve 1/11/2014 19:14'! zzacceptContents: aText " Set aText to be the contents of the receiver. " " Write to file. " " Return true if happy " " 2007.11.08 Do not create new versions. " " 2007.11.10 TRee Overwrite file without asking. " " 2007.12.13. TRee. Bugfix. " " 2010.2.1 New file format. " | refStrm | super acceptContents: aText. (refStrm := ReferenceStream fileNamed: name , '.ws') ifNil: [self notify: 'I cannot save the workspace; ' , String cr , name , '.ws', ' may be a read-only file.'. ^false] ifNotNil: [refStrm nextPut: aText; close. ^ true] " [aText storeOn: fileStrm. self contents: aText. ^ true]" ! ]style[(17 1 6 3 49 2 18 2 24 2 42 2 50 2 29 2 29 292 65 2)f2b,f2,f2i,f2,f2cblue;,f2,f2cblue;,f2,f2cblue;,f2,f2cblue;,f2,f2cblue;,f2,f2cblue;,f2,f2cblue;,f2,f2cblue;,f2! ! !PersistentWorkspace methodsFor: 'code pane menu' stamp: 'Trygve 1/12/2014 11:48'! zzcancelContents: dummy " Read from file - if possible." " 2014.01.10 Use ReferenceStream for write and read. " | refStrm txt | [ refStrm := ReferenceStream fileNamed: name asString , '.ws'. txt := Object readFrom: refStrm contents] ensure: [refStrm close]. textMorph setText: txt.! ]style[(17 1 6 2 32 2 54 12 4 68 40 27 25)f3b,f3,f3i,f3,f3cblue;,f2,f2cblue;,f2,f3,f2,f3,f2,f3! ! !PersistentWorkspace methodsFor: 'initialize-release'! initialize super initialize. name := 'PersistentWorkspace'.! ! !PersistentWorkspace methodsFor: 'initialize-release'! openAsMorphInWorld " PersistentWorkspace new openAsMorphInWorld. " | | ^self openAsMorphInWorld: ActiveWorld! ! !PersistentWorkspace methodsFor: 'initialize-release' stamp: 'TRee 9/9/2011 07:59'! openAsMorphInWorld: aWorld " PersistentWorkspace new openAsMorph. " | | toolMorph _ (SystemWindow labelled: name) model: self. textMorph := PluggableTextMorph on: self text: #contents accept: #acceptContents:notifying: readSelection: nil menu: #codePaneMenu:shifted:. textMorph hasUnacceptedEdits: true. toolMorph addMorph: textMorph frame: (0@0 corner: 1@1). toolMorph openInWorld: aWorld! ]style[(19 1 7 3 40 352)f2b,f2,f2i,f2,f2icblue;,f2! ! !PersistentWorkspace methodsFor: 'initialize-release' stamp: 'TRee 9/9/2011 07:56'! openAsMorphInWorldWithName: nameString contents: contentsText toolMorph _ (SystemWindow labelled: nameString) model: self. name := nameString. contents := contentsText. textMorph := PluggableTextMorph on: self text: #contents accept: #acceptContents:notifying: readSelection: nil menu: #codePaneMenu:shifted:. textMorph hasUnacceptedEdits: false. toolMorph addMorph: textMorph frame: (0@0 corner: 1@1). toolMorph openInWorld: ActiveWorld ! ]style[(27 1 11 9 1 13 394)f2b,f2,f2i,f2b,f2,f2i,f2! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! PersistentWorkspace class instanceVariableNames: ''! !PersistentWorkspace class methodsFor: 'instance creation' stamp: 'TRee 11/8/2007 14:28'! fileReaderServicesForFile: fullName suffix: suffix ^(suffix = 'ws') | (suffix = '*') ifTrue: [ Array with: self serviceLoadAsWorkspace] ifFalse: [#()] ! ! !PersistentWorkspace class methodsFor: 'instance creation'! openAsMorphInWorld " PersistentWorkspace openAsMorphInWorld. " ^self new openAsMorphInWorld! ! !PersistentWorkspace class methodsFor: 'instance creation' stamp: 'TRee 2/1/2010 18:44'! openFromFile: fullName | refStrm txt | Smalltalk verifyMorphicAvailability ifFalse: [^ self]. [ refStrm := ReferenceStream fileNamed: fullName. txt := refStrm next. ] ensure: [refStrm close]. PersistentWorkspace new openAsMorphInWorldWithName: (FileDirectory baseNameFor:(FileDirectory localNameFor: fullName)) contents: txt. " [ strm := FileDirectory default readOnlyFileNamed: fullName. txt := Object readFrom: strm contents ] ensure: [strm close]. PersistentWorkspace new openAsMorphInWorldWithName: (FileDirectory baseNameFor:(FileDirectory localNameFor: fullName)) contents: txt."! ]style[(13 1 9 583)f2b,f2,f2i,f2! ! !PersistentWorkspace class methodsFor: 'instance creation' stamp: 'TRee 5/30/2014 18:41'! openOnString: string withName: nam " PersistentWorkspace openOnString: 'testContents' withName: 'testName' " PersistentWorkspace new openAsMorphInWorldWithName: nam contents: string. ! ]style[(13 1 7 9 1 27 13 1 15 9 2 12 75)f2b,f2,f2i,f2b,f2,f2i,f2b,f2,f2i,f2b,f2,f2i,f2! ! !PersistentWorkspace class methodsFor: 'instance creation' stamp: 'TRee 11/8/2007 14:31'! serviceLoadAsWorkspace ^ SimpleServiceEntry provider: self label: 'open as persistent workspace' selector: #openFromFile: description: 'open as persistent workspace'! ! !PersistentWorkspace class methodsFor: 'instance creation' stamp: 'TRee 11/8/2007 14:22'! services ^ Array with: self serviceLoadAsWorkspace! ! !PersistentWorkspace class methodsFor: 'class initialization' stamp: 'TRee 8/4/2009 17:41'! initialize " PersistentWorkspace initialize " TheWorldMenu registerOpenCommand: {'Persistent workspace'. {PersistentWorkspace. #openAsMorphInWorld}. 'A workspace with its Text on disk'}. FileList registerFileReader: self.! ! PersistentWorkspace initialize!