Class CPDocument

CPObject
    extended byCPResponder
        extended byCPDocument

@implementation CPDocument : CPResponder

CPDocument is used to represent a document/file in a Cappuccino application. In a document-based application, generally multiple documents are open simutaneously (multiple text documents, slide presentations, spreadsheets, etc.), and multiple CPDocuments should be used to represent this.


Method Summary
-(id)init
          Initializes an empty document.
-(id)initForURL:(CPURL)anAbsoluteURL withContentsOfURL:(CPURL)absoluteContentsURL ofType:(CPString)aType delegate:(id)aDelegate didReadSelector:(SEL)aDidReadSelector contextInfo:(id)aContextInfo
          Initializes the document from a URL.
-(id)initWithContentsOfURL:(CPURL)anAbsoluteURL ofType:(CPString)aType delegate:(id)aDelegate didReadSelector:(SEL)aDidReadSelector contextInfo:(id)aContextInfo
          Initializes a document of a specific type located at a URL.
-(id)initWithType:(CPString)aType error:(CPError)anError
          Initializes the document with a specific data type.
-(void)addWindowController:(CPWindowController)aWindowController
          Add a controller to the document's list of controllers.
-(CPData)dataOfType:(CPString)aType error:(CPError)anError
          Returns the receiver's data in a specified type.
-(CPString)displayName
          Returns the name of the document as displayed in the title bar.
-(CPString)fileType
          Returns the document's file type.
-(CPURL)fileURL
          Returns the path to the document's file.
-(BOOL)hasUndoManager
          Returns YES if the document has a CPUndoManager.
-(BOOL)isDocumentEdited
          Returns YES if there are any unsaved changes.
-(void)makeWindowControllers
          Creates the window controller for this document.
-(void)readFromData:(CPData)aData ofType:(CPString)aType error:(CPError)anError
          Sets the content of the document by reading the provided data.
-(void)readFromURL:(CPURL)anAbsoluteURL ofType:(CPString)aType delegate:(id)aDelegate didReadSelector:(SEL)aDidReadSelector contextInfo:(id)aContextInfo
          Set the document's data from a URL.
-(void)saveDocument:(id)aSender
          Saves the document.
-(void)saveDocumentAs:(id)aSender
          Saves the document to a user specified path.
-(void)saveToURL:(CPURL)anAbsoluteURL ofType:(CPString)aTypeName forSaveOperation:(CPSaveOperationType)aSaveOperation delegate:(id)aDelegate didSaveSelector:(SEL)aDidSaveSelector contextInfo:(id)aContextInfo
          Saves the document to the specified URL.
-(void)setFileType:(CPString)aType
          Sets the document's file type.
-(void)setFileURL:(CPURL)aFileURL
          Sets the path to the document's file.
-(void)setHasUndoManager:(BOOL)aFlag
          Sets whether the document should have a CPUndoManager.
-(void)setUndoManager:(CPUndoManager)anUndoManager
          Sets the document's undo manager.
-(void)showWindows
          Shows all the document's windows.
-(CPUndoManager)undoManager
          Returns the document's undo manager.
-(void)updateChangeCount:(CPDocumentChangeType)aChangeType
          Updates the number of unsaved changes to the document.
-(CPString)windowCibName
          Returns the document's Cib name.
-(void)windowControllerDidLoadNib:(CPWindowController)aWindowController
          Called after aWindowController loads the document's Nib file.
-(void)windowControllerWillLoadNib:(CPWindowController)aWindowController
          Called before aWindowController will load the document's Nib file.
-(CPArray)windowControllers
          Returns the document's window controllers.

Methods inherited from class CPObject
initialize, alloc, class, instanceMethodForSelector, instancesRespondToSelector, isSubclassOfClass, load, new, setVersion, superclass, version, init, autorelease, awakeAfterUsingCoder, class, classForCoder, classForKeyedArchiver, className, copy, dealloc, description, doesNotRecognizeSelector, forwardInvocation, hash, isEqual, isKindOfClass, isMemberOfClass, isProxy, methodForSelector, methodSignatureForSelector, mutableCopy, performSelector, performSelector, performSelector, release, replacementObjectForArchiver, replacementObjectForCoder, replacementObjectForKeyedArchiver, respondsToSelector, retain, self, superclass

Methods inherited from class CPResponder
acceptsFirstResponder, becomeFirstResponder, deleteBackward, doCommandBySelector, insertLineBreak, insertText, interpretKeyEvents, keyDown, keyUp, menu, mouseDown, mouseDragged, mouseEntered, mouseExited, mouseMoved, mouseUp, nextResponder, noResponderFor, performKeyEquivalent, resignFirstResponder, scrollWheel, setMenu, setNextResponder, tryToPerform, undoManager


Method Detail

init

-(id)init
Initializes an empty document.
Returns:
the initialized document

initForURL

-(id)initForURL:(CPURL)anAbsoluteURL withContentsOfURL:(CPURL)absoluteContentsURL ofType:(CPString)aType delegate:(id)aDelegate didReadSelector:(SEL)aDidReadSelector contextInfo:(id)aContextInfo
Initializes the document from a URL.
Parameters:
anAbsoluteURL - the document location
absoluteContentsURL - the location of the document's contents
aType - the type of the contents
aDelegate - this object will receive a callback after the document's contents are loaded
aDidReadSelector - the message selector that will be sent to aDelegate
aContextInfo - passed as the argument to the message sent to the aDelegate
Returns:
the initialized document

initWithContentsOfURL

-(id)initWithContentsOfURL:(CPURL)anAbsoluteURL ofType:(CPString)aType delegate:(id)aDelegate didReadSelector:(SEL)aDidReadSelector contextInfo:(id)aContextInfo
Initializes a document of a specific type located at a URL. Notifies the provided delegate after initialization.
Parameters:
anAbsoluteURL - the url of the document content
aType - the type of document located at the URL
aDelegate - the delegate to notify
aDidReadSelector - the selector used to notify the delegate
aContextInfo - context information passed to the delegate after initialization
Returns:
the initialized document

initWithType

-(id)initWithType:(CPString)aType error:(CPError)anError
Initializes the document with a specific data type.
Parameters:
aType - the type of document to initialize
anError - not used
Returns:
the initialized document

addWindowController

-(void)addWindowController:(CPWindowController)aWindowController
Add a controller to the document's list of controllers. This should be called after making a new window controller.
Parameters:
aWindowController - the controller to add

dataOfType

-(CPData)dataOfType:(CPString)aType error:(CPError)anError
Returns the receiver's data in a specified type. The default implementation just throws an exception.
Parameters:
aType - the format of the data
anError - not used
Throws:
CPUnsupportedMethodException - if this method hasn't been overriden by the subclass
Returns:
the document data

displayName

-(CPString)displayName
Returns the name of the document as displayed in the title bar.

fileType

-(CPString)fileType
Returns the document's file type

fileURL

-(CPURL)fileURL
Returns the path to the document's file.

hasUndoManager

-(BOOL)hasUndoManager
Returns YES if the document has a CPUndoManager.

isDocumentEdited

-(BOOL)isDocumentEdited
Returns YES if there are any unsaved changes.

makeWindowControllers

-(void)makeWindowControllers
Creates the window controller for this document.

readFromData

-(void)readFromData:(CPData)aData ofType:(CPString)aType error:(CPError)anError
Sets the content of the document by reading the provided data. The default implementation just throws an exception.
Parameters:
aData - the document's data
aType - the document type
anError - not used
Throws:
CPUnsupportedMethodException - if this method hasn't been overridden by the subclass

readFromURL

-(void)readFromURL:(CPURL)anAbsoluteURL ofType:(CPString)aType delegate:(id)aDelegate didReadSelector:(SEL)aDidReadSelector contextInfo:(id)aContextInfo
Set the document's data from a URL. Notifies the provided delegate afterwards.
Parameters:
anAbsoluteURL - the URL to the document's content
aType - the document type
aDelegate - delegate to notify after reading the data
aDidReadSelector - message that will be sent to the delegate
aContextInfo - context information that gets sent to the delegate

saveDocument

-(void)saveDocument:(id)aSender
Saves the document. If the document does not have a file path to save to (fileURL) then saveDocumentAs: will be called.
Parameters:
aSender - the object requesting the save

saveDocumentAs

-(void)saveDocumentAs:(id)aSender
Saves the document to a user specified path.
Parameters:
aSender - the object requesting the operation

saveToURL

-(void)saveToURL:(CPURL)anAbsoluteURL ofType:(CPString)aTypeName forSaveOperation:(CPSaveOperationType)aSaveOperation delegate:(id)aDelegate didSaveSelector:(SEL)aDidSaveSelector contextInfo:(id)aContextInfo
Saves the document to the specified URL. Notifies the provided delegate with the provided selector and context info afterwards.
Parameters:
anAbsoluteURL - the url to write the document data to
aTypeName - the document type
aSaveOperation - the type of save operation
aDelegate - the delegate to notify after saving
aDidSaveSelector - the selector to send the delegate
aContextInfo - context info that gets passed to the delegate

setFileType

-(void)setFileType:(CPString)aType
Sets the document's file type
Parameters:
aType - the document's type

setFileURL

-(void)setFileURL:(CPURL)aFileURL
Sets the path to the document's file.
Parameters:
aFileURL - the path to the document's file

setHasUndoManager

-(void)setHasUndoManager:(BOOL)aFlag
Sets whether the document should have a CPUndoManager.
Parameters:
aFlag - YES makes the document have an undo manager

setUndoManager

-(void)setUndoManager:(CPUndoManager)anUndoManager
Sets the document's undo manager. This method will add the undo manager as an observer to the notification center.
Parameters:
anUndoManager - the new undo manager for the document

showWindows

-(void)showWindows
Shows all the document's windows.

undoManager

-(CPUndoManager)undoManager
Returns the document's undo manager. If the document should have one, but the manager is nil, it will be created and then returned.
Returns:
the document's undo manager

updateChangeCount

-(void)updateChangeCount:(CPDocumentChangeType)aChangeType
Updates the number of unsaved changes to the document.
Parameters:
aChangeType - a new document change to apply

windowCibName

-(CPString)windowCibName
Returns the document's Cib name

windowControllerDidLoadNib

-(void)windowControllerDidLoadNib:(CPWindowController)aWindowController
Called after aWindowController loads the document's Nib file.
Parameters:
aWindowController - the controller that loaded the Nib file

windowControllerWillLoadNib

-(void)windowControllerWillLoadNib:(CPWindowController)aWindowController
Called before aWindowController will load the document's Nib file.
Parameters:
aWindowController - the controller that will load the Nib file

windowControllers

-(CPArray)windowControllers
Returns the document's window controllers

Created on Sat Sep 13 14:15:43 PDT 2008