class Document(Model, MessageHandler)

A Document represents an application data structure that can be stored in a file. It implements standard functionality such as asking the user for file names and opening and closing files.

Each Document can have one or more windows associated with it. When the last window belonging to a document is closed, the document itself is closed.

A Document provides support for keeping track of whether it has been edited, and asking the user whether to save changes when it is closed.

Properties

needs_saving
A boolean indicating that the document has been edited and needs to be saved.
file
A FileRef identifying the file that the document was read from or last written to, or None.
title
Document title to be displayed in window headers. The default value of this property is derived from the last pathname component of the associated file, or if the document is not associated with a file, a title such as "Untitled-n" is constructed. Assigning to this property will cause all associated windows to update their titles accordingly.  
windows
Read-only. List of windows associated with this document.

Attributes

binary
Determines the mode in which the file object passed to the read_contents and write_contents methods is opened. If true, the file is opened in binary mode for reading or writing. If false, the file is opened in text mode for writing, and universal newlines mode for reading.

This attribute may be specified as a class attribute. The default value is true.

Abstract Methods

new_contents()
Should initialise the document to the appropriate state following a New command.
read_contents(file)
Should initialise the document's contents by reading it from the given file.
write_contents(file)
Should write the document's contents to the given file.
destroy_contents()
Called when the contents of the document are about to be discarded. If the contents contains any Model objects, they should be destroyed.

Methods

changed()
Mark the document as needing to be saved.Equivalent to setting the  needs_saving property to true.
save_changes()
If the document has been edited, ask the user whether to save changes and do so if requested.
save_cmd()
Implements the standard Save command. Writes the document to its associated file, asking the user for one first if necessary.
save_as_cmd()
Implements the standard Save As... command. Asks the user for a new file and writes the document to it.
revert_cmd()
Implements the standard Revert command. Discards the current contents of the document and re-reads it from the associated file.
close_cmd()
Implements the standard Close command. Asks whether to save any changes, then destroys any associated windows.

Destructor

destroy()
Destroys any associated Windows, then destroys the Document.

---