- Inherits from:
- NSObject
- Package:
- com.apple.yellow.application
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.
- Constructors
- NSDocumentController
- Obtaining the shared instance
- sharedDocumentController
- Creating and opening documents
- makeDocumentWithContentsOfFile
- makeDocumentWithContentsOfURL
- makeUntitledDocumentOfType
- openDocumentWithContentsOfFile
- openDocumentWithContentsOfURL
- openUntitledDocumentOfType
- setShouldCreateUI
- shouldCreateUI
- Managing the Open panel
- runModalOpenPanel
- fileNamesFromRunningOpenPanel
- currentDirectory
- URLsFromRunningOpenPanel
- Closing documents
- closeAllDocuments
- reviewUnsavedDocumentsWithAlertTitle
- 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
public NSDocumentController()
public static NSDocumentController sharedDocumentController()
CustomInfo.plist
), registers
the instance for WorkspaceWillPowerOffNotifications, 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
public void addDocument(NSDocument document)
public void clearRecentDocuments(Object sender)
public boolean closeAllDocuments()
public String currentDirectory()
See Also: documentForFileName
public NSDocument currentDocument()
See Also: documentForFileName, documentForWindow, documents
public String displayNameForType(String docType)
TypeName
key
in the NSType property list.If there is no such value, docType is
returned.See Also: fileExtensionsFromType, typeFromFileExtension
public Class documentClassForType(String docType)
null
.See Also: displayNameForType, fileExtensionsFromType, typeFromFileExtension
public NSDocument documentForFileName(String fileName)
null
if
no document can be found.See Also: documentForWindow, documents
public NSDocument documentForWindow(NSWindow window)
null
if window is null
,
if window has no window controller,
or if the window controller does not have an association with an
NSDocument.See Also: currentDocument, documentForFileName, documents
public NSArray documents()
See Also: currentDocument, documentForFileName, documentForWindow
public NSArray fileExtensionsFromType(String docType)
See Also: displayNameForType, typeFromFileExtension
public NSArray fileNamesFromRunningOpenPanel()
null
if the user cancels
the Open panel or makes no selection.public boolean hasEditedDocuments()
See Also: documents
public NSDocument makeDocumentWithContentsOfFile(
String aString,
String docType)
null
if
the NSDocument subclass for docType couldn't
be determined or if the object couldn't be created. This method is
invoked by openDocumentWithContentsOfFile.See Also: makeUntitledDocumentOfType, openDocument
public NSDocument makeDocumentWithContentsOfURL(
java.net.URL anURL,
String docType)
null
if
the NSDocument subclass for docType couldn't
be determined or if the object couldn't be created. This method is
invoked by openDocumentWithContentsOfURL.See Also: makeUntitledDocumentOfType, openDocument
public NSDocument makeUntitledDocumentOfType(String type)
null
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.See Also: makeDocumentWithContentsOfFile, newDocument
public void newDocument(Object sender)
CustomInfo.plis
t);
the document type determines the NSDocument subclass used to instantiate
the document object.See Also: openDocument
public void noteNewRecentDocumentURL(java.net.URL anURL)
public void openDocument(Object sender)
See Also: fileNamesFromRunningOpenPanel, newDocument
public NSDocument openDocumentWithContentsOfFile(
String fileName,
boolean flag)
null
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 true, the document is
not displayed if shouldCreateUI returns false. This method invokes makeDocumentWithContentsOfFile to
obtain the created NSDocument object. See Also: openDocument, openUntitledDocumentOfType, setShouldCreateUI
public NSDocument openDocumentWithContentsOfURL(
java.net.URL anURL,
boolean flag)
null
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 true,
the document is not displayed if shouldCreateUI returns false. This
method invokes makeDocumentWithContentsOfURL to
obtain the created NSDocument object. See Also: openDocument, openUntitledDocumentOfType, setShouldCreateUI
public NSDocument openUntitledDocumentOfType(
String docType,
boolean display)
null
if the object could
not be created, typically because no NSDocument subclass could be
found for docType. Even if flag is true,
the document is not displayed if shouldCreateUI returns false. This
method invokes makeUntitledDocumentOfType to obtain the created
NSDocument object. See Also: newDocument, openDocumentWithContentsOfFile, setShouldCreateUI
public NSArray recentDocumentURLs()
public void removeDocument(NSDocument document)
public boolean reviewUnsavedDocumentsWithAlertTitle(
String title,
boolean flag)
public int runModalOpenPanel(
NSOpenPanel openPanel,
NSArray extensions)
public void saveAllDocuments(Object sender)
See Also: saveDocument (NSDocument)
public void setShouldCreateUI(boolean flag)
See Also: shouldCreateUI
public boolean shouldCreateUI()
See Also: setShouldCreateUI
public String typeFromFileExtension(String fileExtension)
See Also: displayNameForType, fileExtensionsFromType
public NSArray URLsFromRunningOpenPanel()
public boolean validateMenuItem(NSMenuItem anItem)