Storing Documents In a Soup
After the user has finished modifying a word-processing document, you need to save it in your soup. The TXWord program does this at view closing time, in its implementation of theViewQuitScript
method, which is shown in Listing 3-8.Listing 3-8 Closing the word-processing view
The TXWord implementation of theViewQuitScript:
func() begin :SetSoupData(); inherited:?ViewQuitScript(); end
ViewQuitScript
method calls theeditor:SetSoupData
method to store the modified data and then calls the inheritedViewQuitScript
method. Theeditor:SetSoupData
method is shown in Listing 3-9.Listing 3-9 Storing a word-processing document
Theeditor:SetSoupData:
func() begin // only save if something changed if not :IsModified() then return; local externalData := self:Externalize(); // change existing soup entry if there is one if theSoupEntry then begin theSoupEntry.EditorData := externalData; EntryChangeXmit(theSoupEntry, nil); end; else begin local soup := GetUnionSoupAlways(kSoupName); if soup then theSoupEntry := soup:AddToDefaultStoreXmit( {EditorData: externalData}, nil); else begin soup := GetDefaultStore():CreateSoup(kSoupName, []); theSoupEntry := soup:AddXmit( {EditorData: externalData}, nil); end; end; end
editor:SetSoupData
method first determines if the view has been modified by the user by calling the *protoTXView:*IsModified
method. If not,SetSoupData
simply returns, rather than spending time saving unchanged data.If the view has been modified,
SetSoupData
calls the *protoTXView:*Externalize
method to convert the word-processing data in the view into a format that can be stored in your soup.SetSoupData
then updates the soup as follows:
- If there already is a soup entry for the view,
SetSoupData
updates that entry.SetSoupData
knows that a soup entry already exists iftheSoupEntry
slot has a value. This is the case if theGetSoupData
method found a soup entry at view setup time, as described in "Reading a Word-Processing Document From a Soup".- If there is not already a soup entry for the view,
SetSoupData
creates the soup in the default store and adds the data to the soup.
Main | Top of Section | What's New | Apple Computer, Inc. | Find It | Feedback | Help