- Inherits from:
- NSObject
- Conforms to:
- NSCoding
- NSObject (NSObject)
Declared in:
- AppKit/NSDocumentController.h
An NSDocumentController object manages an application's
documents. As the first-responder target of New and Open menu commands,
it creates and opens documents and tracks them throughout a session
of the application.When opening documents, an NSDocumentController
runs and manages the modal Open panel. As the application delegate,
it saves and closes documents when applications are terminated and
it responds to NSWorkspace methods when documents are opened or
printed from the workspace. NSDocumentControllers also maintain
and manage the mappings of document types, extensions, and NSDocument
subclasses as specified in the NSTypes property loaded from the
custom info property list (CustomInfo.plist
).
One instance of NSDocumentController is shared among processes.
You can use various NSDocumentController methods to get a list of the current documents, get the current document (which is the document whose window is currently key), get documents based on a given file name or window, and to find out about a document's extension, type, display name, and document class.
A document-based application can use the default NSDocumentController instance provided by the Application Kit, because this instance not only creates and manages documents, but acts as application controller. Typically, however, applications will require their own custom subclasses of NSDocumentController to implement behavior not provided by default, such as loading About panels and managing user preferences.
For more on the architecture of document-based applications, and the procedure for implementing, see the concepts "Document-Based Application Architecture" and "Implementing a Document-Based Application" , currently in the NSDocument class description.
- Obtaining the shared instance
- + sharedDocumentController
- Initializing a new NSDocumentController
- - init
- Creating and opening documents
- - makeDocumentWithContentsOfFile:ofType:
- - makeDocumentWithContentsOfURL:ofType:
- - makeUntitledDocumentOfType:
- - openDocumentWithContentsOfFile:display:
- - openDocumentWithContentsOfURL:
- - openUntitledDocumentOfType:display:
- - setShouldCreateUI:
- - shouldCreateUI
- Managing the Open panel
- - runModalOpenPanel:forTypes:
- - fileNamesFromRunningOpenPanel
- - currentDirectory
- - URLsFromRunningOpenPanel
- Closing documents
- - closeAllDocuments
- - reviewUnsavedDocumentsWithAlertTitle:cancellable:
- Responding to action messages
- - newDocument:
- - openDocument:
- - saveAllDocuments:
- Managing documents
- - documents
- - addDocument:
- - clearRecentDocuments:
- - currentDocument
- - documentClassForType:
- - documentForFileName:
- - documentForWindow:
- - hasEditedDocuments
- - noteNewRecentDocumentURL:
- - recentDocumentURLs
- - removeDocument:
- Managing document types
- - displayNameForType:
- - fileExtensionsFromType:
- - typeFromFileExtension:
- Validating menu items
- - validateMenuItem:
+ (id)sharedDocumentController
CustomInfo.plist
), registers
the instance for NSWorkspaceWillPowerOffNotifications, and turns
on the flag indicating that document user interfaces should be visible.
You should always obtain your application's NSDocumentController
using this method.See Also: - setShouldCreateUI:
- (void)addDocument:(NSDocument
*)document
- (IBAction)clearRecentDocuments:(id)sender
- (BOOL)closeAllDocuments
- (NSString *)currentDirectory
See Also: - documentForFileName:
- (id)currentDocument
See Also: - documentForFileName:, - documentForWindow:, - documents
- (NSString *)displayNameForType:(NSString
*)docType
NSTypeName
key
in the NSType property list.If there is no such value, docType is
returned.See Also: - fileExtensionsFromType:, - typeFromFileExtension:
- (Class)documentClassForType:(NSString
*)docType
nil
.See Also: - displayNameForType:, - fileExtensionsFromType:, - typeFromFileExtension:
- (id)documentForFileName:(NSString
*)fileName
nil
if
no document can be found.See Also: - documentForWindow:, - documents
- (id)documentForWindow:(NSWindow
*)window
nil
if window is nil
,
if window has no window controller,
or if the window controller does not have an association with an
NSDocument.See Also: - currentDocument, - documentForFileName:, - documents
- (NSArray *)documents
See Also: - currentDocument, - documentForFileName:, - documentForWindow:
- (NSArray *)fileExtensionsFromType:(NSString
*)docType
See Also: - displayNameForType:, - typeFromFileExtension:
- (NSArray *)fileNamesFromRunningOpenPanel
nil
if the user cancels the
Open panel or makes no selection.- (BOOL)hasEditedDocuments
See Also: - documents
- (id)init
- (id)makeDocumentWithContentsOfFile:(NSString
*)fileName
ofType:(NSString *)docType
nil
if the
NSDocument subclass for docType couldn't
be determined or if the object couldn't be created. This method invokes
NSDocument's initWithContentsOfFile:ofType: and is
invoked by openDocumentWithContentsOfFile:display:.See Also: - makeUntitledDocumentOfType:, - openDocument:
- (id)makeDocumentWithContentsOfURL:(NSURL
*)anURL
ofType:(NSString *)docType
nil
if
the NSDocument subclass for docType couldn't
be determined or if the object couldn't be created. This method invokes
NSDocument's initWithContentsOfURL:ofType: and is invoked by openDocumentWithContentsOfURL:.See Also: - makeUntitledDocumentOfType:, - openDocument:
- (id)makeUntitledDocumentOfType:(NSString
*)type
nil
if
the NSDocument subclass for docType couldn't be determined or
if the object couldn't be created. This method invokes NSDocument's init and
is invoked by openUntitledDocumentOfType:display:.See Also: - makeDocumentWithContentsOfFile:ofType:, - newDocument:
- (void)newDocument:(id)sender
CustomInfo.plis
t);
the document type determines the NSDocument subclass used to instantiate
the document object.See Also: - openDocument:
- (void)noteNewRecentDocumentURL:(NSURL
*)anURL
- (IBAction)openDocument:(id)sender
See Also: - fileNamesFromRunningOpenPanel, - newDocument:
- (id)openDocumentWithContentsOfFile:(NSString
*)fileName
display:(BOOL)flag
nil
if
the object could not be created, typically because fileName does not
point to a valid file or because there is no NSDocument subclass
for the document type (as indicated by the file extension). Even
if flag is YES, the document is not
displayed if shouldCreateUI returns NO. This method invokes makeDocumentWithContentsOfFile:ofType: to
obtain the created NSDocument object. See Also: - openDocument:, - openUntitledDocumentOfType:display:, - setShouldCreateUI:
- (id)openDocumentWithContentsOfURL:(NSURL
*)anURL
display:(BOOL)flag
nil
if
the object could not be created, typically because anURL does
not point to a valid location or because there is no NSDocument
subclass for the document type. Even if flag is YES,
the document is not displayed if shouldCreateUI returns NO. This
method invokes makeDocumentWithContentsOfURL:ofType: to
obtain the created NSDocument object. See Also: - openDocument:, - openUntitledDocumentOfType:display:, - setShouldCreateUI:
- (id)openUntitledDocumentOfType:(NSString
*)docType
display:(BOOL)display
nil
if
the object could not be created, typically because no NSDocument
subclass could be found for docType.
Even if flag is YES, the document
is not displayed if shouldCreateUI returns NO. This method invokes makeUntitledDocumentOfType: to
obtain the created NSDocument object. See Also: - newDocument:, - openDocumentWithContentsOfFile:display:, - setShouldCreateUI:
- (NSArray *)recentDocumentURLs
- (void)removeDocument:(NSDocument
*)document
- (BOOL)reviewUnsavedDocumentsWithAlertTitle:(NSString
*)title
cancellable:(BOOL)flag
- (int)runModalOpenPanel:(NSOpenPanel
*)openPanel
forTypes:(NSArray *)extensions
- (IBAction)saveAllDocuments:(id)sender
See Also: - saveDocument: (NSDocument)
- (void)setShouldCreateUI:(BOOL)flag
See Also: - shouldCreateUI
- (BOOL)shouldCreateUI
See Also: - setShouldCreateUI:
- (NSString *)typeFromFileExtension:(NSString
*)fileExtension
See Also: - displayNameForType:, - fileExtensionsFromType:
- (NSArray *)URLsFromRunningOpenPanel
- (BOOL)validateMenuItem:(NSMenuItem
*)anItem