Classes

NSActionCell
NSAlert
NSApplication
NSArrayController
NSBezierPath
NSBitmapImageRep
NSBox
NSBrowser
NSBrowserCell
NSButton
NSButtonCell
NSCachedImageRep
NSCell
NSClipView
NSCollectionView
NSCollectionViewItem
NSColor
NSColorList
NSColorPanel
NSColorPicker
NSColorWell
NSComboBox
NSComboBoxCell
NSControl
NSController
NSCursor
NSCustomImageRep
NSDataLink
NSDataLinkManager
NSDataLinkPanel
NSDatePicker
NSDatePickerCell
NSDocument
NSDocumentController
NSDrawer
NSDrawerDelegate
NSEPSImageRep
NSEvent
NSFont
NSFontDescriptor
NSFontManager
NSFontPanel
NSForm
NSFormCell
NSGraphicsContext
NSHelpManager
NSHelpPanel
NSImage
NSImageCell
NSImageRep
NSImageView
NSInputServer
NSMatrix
NSMenu
NSMenuItem
NSMenuItemCell
NSMenuView
NSMovie
NSMovieView
NSMutableParagraphStyle
NSNib
NSObjectController
NSOpenGLContext
NSOpenGLPixelFormat
NSOpenGLView
NSOpenPanel
NSOutlineView
NSPageLayout
NSPanel
NSParagraphStyle
NSPasteboard
NSPasteboardItem
NSPopUpButton
NSPopUpButtonCell
NSPredicateEditor
NSPredicateEditorRowTemplate
NSPrintInfo
NSPrintOperation
NSPrintPanel
NSPrinter
NSProgressIndicator
NSResponder
NSRuleEditor
NSRulerMarker
NSSavePanel
NSScreen
NSScrollView
NSScroller
NSSecureTextField
NSSecureTextFieldCell
NSSelection
NSSharingService
NSSharingServicePicker
NSSlider
NSSliderCell
NSSound
NSSpeechSynthesizer
NSSpellChecker
NSSplitView
NSStepper
NSStepperCell
NSTabView
NSTabViewItem
NSTableColumn
NSTableHeaderCell
NSTableHeaderView
NSTableView
NSText
NSTextAttachment
NSTextAttachmentCell
NSTextContainer
NSTextField
NSTextFieldCell
NSTextStorage
NSTextTab
NSTextView
NSTokenField
NSTokenFieldCell
NSUserDefaultsController
NSView
NSWindow
NSWindowController
NSWorkspace

Protocols

<GSImageDelegateProtocol>
<NSAlertDelegate>
<NSApplicationDelegate>
<NSBrowserDelegate>
<NSCollectionViewDataSource>
<NSCollectionViewDelegate>
<NSCollectionViewElement>
<NSCollectionViewPrefetching>
<NSComboBoxCellDataSource>
<NSComboBoxDataSource>
<NSComboBoxDelegate>
<NSControlTextEditingDelegate>
<NSInputServerMouseTracker>
<NSInputServiceProvider>
<NSMatrixDelegate>
<NSMenuDelegate>
<NSMenuItem>
<NSMenuValidation>
<NSMenuView>
<NSOpenSavePanelDelegate>
<NSOutlineViewDataSource>
<NSOutlineViewDelegate>
<NSPasteboardItemDataProvider>
<NSPasteboardReading>
<NSPasteboardWriting>
<NSPrintPanelAccessorizing>
<NSRuleEditorDelegate>
<NSSharingServiceDelegate>
<NSSharingServicePickerDelegate>
<NSSpeechSynthesizerDelegate>
<NSSplitViewDelegate>
<NSTabViewDelegate>
<NSTableViewDataSource>
<NSTableViewDelegate>
<NSTextAttachmentCell>
<NSTextFieldDelegate>
<NSTextViewDelegate>
<NSWindowDelegate>
(NSAlertDelegate)
(NSApplicationDelegate)
(NSBrowserDelegate)
(NSComboBoxCellDataSource)
(NSControlDelegate)
(NSControlTextEditingDelegate)
(NSDataLinkManagerDelegate)
(NSDataPickerCellDelegate)
(NSEditor)
(NSEditorRegistration)
(NSFontManagerDelegate)
(NSFontPanelValidation)
(NSMenuActionResponder)
(NSMenuDelegate)
(NSOpenSavePanelDelegate)
(NSPasteboardItemDataProvider)
(NSPasteboardOwner)
(NSPasteboardReading)
(NSPasteboardWriting)
(NSPlaceholder)
(NSSavePanelDelegate)
(NSServicesRequests)
(NSSoundDelegate)
(NSSpeechSynthesizerDelegate)
(NSSplitViewDelegate)
(NSTableDataSource)
(NSTableViewDelegate)
(NSTextDelegate)
(NSTextStorageDelegate)
(NSTextViewDelegate)
(NSWindowDelegate)
(NSWindowDelegateAdditions)

Constants

Functions

Macros

Types

Variables

Up

NSDocumentController

Authors

Carl Lindberg (Carl.Lindberg@hbo.com)

Date: Generated at 2025-07-12 14:18:56 +0000

The document controller class

Copyright: (C) 1999 Free Software Foundation, Inc.

Software documentation for the NSDocumentController class

NSDocumentController : NSObject

Declared in:
AppKit/NSDocumentController.h
Availability: MacOS-X 10.0.0

NSDocumentController is a class that controls a set of NSDocuments for an application. As an application delegate, it responds to the typical File Menu commands for opening and creating new documents, and making sure all documents have been saved when an application quits. It also registers itself for the NSWorkspaceWillPowerOffNotification. Note that NSDocumentController isn't truly the application delegate, but it works in a similar way. You can still have your own application delegate - but beware, if it responds to the same methods as NSDocumentController, your delegate methods will get called, not the NSDocumentController's.

NSDocumentController also manages document types and the related NSDocument subclasses that handle them. This information comes from the custom info property list ({ApplicationName}Info.plist) loaded when NSDocumentController is initialized. The property list contains an array of dictionarys with the key NSTypes. Each dictionary contains a set of keys:

  • NSDocumentClass - The name of the subclass
  • NSName - Short name of the document type
  • NSHumanReadableName - Longer document type name
  • NSUnixExtensions - Array of strings
  • NSDOSExtensions - Array of strings
  • NSIcon - Icon name for these documents
  • NSRole - Viewer or Editor

You can use NSDocumentController to get a list of all open documents, the current document (The one whose window is Key) and other information about these documents. It also remembers the most recently opened documents (through the user default key NSRecentDocuments)..

You can subclass NSDocumentController to customize the behavior of certain aspects of the class, but it is very rare that you would need to do this.

Method summary


sharedDocumentController 

+ (id) sharedDocumentController;
Availability: MacOS-X 10.0.0

Returns the shared instance of the document controller class. You should always use this method to get the NSDocumentController.

URLsFromRunningOpenPanel 

- (NSArray*) URLsFromRunningOpenPanel;
Availability: MacOS-X 10.0.0

Uses -runModalOpenPanel:forTypes: to allow the user to select files to open (after initializing the NSOpenPanel). Returns the list of files as URLs that the user has selected.

addDocument: 

- (void) addDocument: (NSDocument*)document;
Availability: MacOS-X 10.0.0

Description forthcoming.

autosavingDelay 

- (NSTimeInterval) autosavingDelay;
Availability: MacOS-X 10.4.0

Description forthcoming.

beginOpenPanel: forTypes: completionHandler: 

- (void) beginOpenPanel: (NSOpenPanel*)openPanel forTypes: (NSArray*)inTypes completionHandler: (GSCompletionBlock3)completionHandler;
Availability: MacOS-X 10.8.0

Description forthcoming.

beginOpenPanelWithCompletionHandler: 

- (void) beginOpenPanelWithCompletionHandler: (GSCompletionBlock2)completionHandler;
Availability: MacOS-X 10.7.0

Description forthcoming.

clearRecentDocuments: 

- (IBAction) clearRecentDocuments: (id)sender;
Availability: MacOS-X 10.0.0

Description forthcoming.

closeAllDocuments 

- (BOOL) closeAllDocuments;
Availability: MacOS-X 10.0.0

Iterates through all the open documents and asks each one in turn if it can close using [NSDocument -canCloseDocument] . If the document returns YES, then it is closed.

closeAllDocumentsWithDelegate: didCloseAllSelector: contextInfo: 

- (void) closeAllDocumentsWithDelegate: (id)delegate didCloseAllSelector: (SEL)didAllCloseSelector contextInfo: (void*)contextInfo;
Availability: MacOS-X 10.0.0

Description forthcoming.

currentDirectory 

- (NSString*) currentDirectory;
Availability: MacOS-X 10.0.0

Returns the current directory. This method first checks if there is a current document using the -currentDocument method. If this returns a document and the document has a filename, this method returns the directory this file is located in. Otherwise it returns the directory of the most recently opened document or the user's home directory if no document has been opened before.

currentDocument 

- (id) currentDocument;
Availability: MacOS-X 10.0.0

Returns the document whose window is the main window

defaultType 

- (NSString*) defaultType;
Availability: MacOS-X 10.4.0

Returns the first type found for which the application has an editor role.

displayNameForType: 

- (NSString*) displayNameForType: (NSString*)type;
Availability: MacOS-X 10.0.0

Description forthcoming.

documentClassForType: 

- (Class) documentClassForType: (NSString*)type;
Availability: MacOS-X 10.0.0

Description forthcoming.

documentClassNames 

- (NSArray*) documentClassNames;
Availability: MacOS-X 10.4.0

Returns the names of the NSDocument subclasses handling documents in this application. This will be nil or empty if this is not a document based application.

documentForFileName: 

- (id) documentForFileName: (NSString*)fileName;
Availability: MacOS-X 10.0.0

Returns the NSDocument class that controls the document with the name fileName.

documentForURL: 

- (id) documentForURL: (NSURL*)url;
Availability: MacOS-X 10.4.0

Description forthcoming.

documentForWindow: 

- (id) documentForWindow: (NSWindow*)window;
Availability: MacOS-X 10.0.0

Returns the NSDocument class that controls window

documents 

- (NSArray*) documents;
Availability: MacOS-X 10.0.0

Returns an array of all open documents

duplicateDocumentWithContentsOfURL: copying: displayName: error: 

- (id) duplicateDocumentWithContentsOfURL: (NSURL*)url copying: (BOOL)duplicateByCopying displayName: (NSString*)displayNameOrNil error: (NSError**)outError;
Availability: MacOS-X 10.7.0

Description forthcoming.

fileExtensionsFromType: 

- (NSArray*) fileExtensionsFromType: (NSString*)type;
Availability: MacOS-X 10.0.0

Description forthcoming.

fileNamesFromRunningOpenPanel 

- (NSArray*) fileNamesFromRunningOpenPanel;
Availability: MacOS-X 10.0.0

Uses -runModalOpenPanel:forTypes: to allow the user to select files to open (after initializing the NSOpenPanel). Returns the list of files that the user has selected.

hasEditedDocuments 

- (BOOL) hasEditedDocuments;
Availability: MacOS-X 10.0.0

Returns YES if any documents are "dirty", e.g. changes have been made to the document that have not been saved to the disk

makeDocumentForURL: withContentsOfURL: ofType: error: 

- (id) makeDocumentForURL: (NSURL*)url withContentsOfURL: (NSURL*)contents ofType: (NSString*)type error: (NSError**)err;
Availability: MacOS-X 10.4.0

Description forthcoming.

makeDocumentWithContentsOfFile: ofType: 

- (id) makeDocumentWithContentsOfFile: (NSString*)fileName ofType: (NSString*)type;
Availability: MacOS-X 10.0.0

Description forthcoming.

makeDocumentWithContentsOfURL: ofType: 

- (id) makeDocumentWithContentsOfURL: (NSURL*)url ofType: (NSString*)type;
Availability: MacOS-X 10.0.0

Description forthcoming.

makeDocumentWithContentsOfURL: ofType: error: 

- (id) makeDocumentWithContentsOfURL: (NSURL*)url ofType: (NSString*)type error: (NSError**)err;
Availability: MacOS-X 10.4.0

Description forthcoming.

makeUntitledDocumentOfType: 

- (id) makeUntitledDocumentOfType: (NSString*)type;
Availability: MacOS-X 10.0.0

Description forthcoming.

makeUntitledDocumentOfType: error: 

- (id) makeUntitledDocumentOfType: (NSString*)type error: (NSError**)err;
Availability: MacOS-X 10.4.0

Description forthcoming.

maximumRecentDocumentCount 

- (NSUInteger) maximumRecentDocumentCount;
Availability: MacOS-X 10.4.0

Description forthcoming.

newDocument: 

- (IBAction) newDocument: (id)sender;
Availability: MacOS-X 10.0.0

Description forthcoming.

noteNewRecentDocument: 

- (void) noteNewRecentDocument: (NSDocument*)aDocument;
Availability: MacOS-X 10.0.0

Description forthcoming.

noteNewRecentDocumentURL: 

- (void) noteNewRecentDocumentURL: (NSURL*)anURL;
Availability: MacOS-X 10.0.0

Description forthcoming.

openDocument: 

- (IBAction) openDocument: (id)sender;
Availability: MacOS-X 10.0.0

Description forthcoming.

openDocumentWithContentsOfFile: display: 

- (id) openDocumentWithContentsOfFile: (NSString*)fileName display: (BOOL)display;
Availability: MacOS-X 10.0.0

Creates an NSDocument object from the data at the absolute path given in fileName. Causes the document to be displayed if display is YES.

openDocumentWithContentsOfURL: display: 

- (id) openDocumentWithContentsOfURL: (NSURL*)url display: (BOOL)display;
Availability: MacOS-X 10.0.0

Creates an NSDocument object from the data at the supplied url.
Causes the document to be displayed if display is YES.

openDocumentWithContentsOfURL: display: completionHandler: 

- (void) openDocumentWithContentsOfURL: (NSURL*)url display: (BOOL)displayDocument completionHandler: (GSCompletionBlock1)completionHandler;
Availability: MacOS-X 10.7.0

Description forthcoming.

openDocumentWithContentsOfURL: display: error: 

- (id) openDocumentWithContentsOfURL: (NSURL*)url display: (BOOL)flag error: (NSError**)err;
Availability: MacOS-X 10.4.0

Description forthcoming.

openUntitledDocumentAndDisplay: error: 

- (id) openUntitledDocumentAndDisplay: (BOOL)flag error: (NSError**)err;
Availability: MacOS-X 10.4.0

Description forthcoming.

openUntitledDocumentOfType: display: 

- (id) openUntitledDocumentOfType: (NSString*)type display: (BOOL)display;
Availability: MacOS-X 10.0.0

Description forthcoming.

presentError: 

- (BOOL) presentError: (NSError*)err;
Availability: MacOS-X 10.4.0

Description forthcoming.

presentError: modalForWindow: delegate: didPresentSelector: contextInfo: 

- (void) presentError: (NSError*)err modalForWindow: (NSWindow*)win delegate: (id)delegate didPresentSelector: (SEL)sel contextInfo: (void*)context;
Availability: MacOS-X 10.4.0

Description forthcoming.

recentDocumentURLs 

- (NSArray*) recentDocumentURLs;
Availability: MacOS-X 10.0.0

Description forthcoming.

removeDocument: 

- (void) removeDocument: (NSDocument*)document;
Availability: MacOS-X 10.0.0

Description forthcoming.

reopenDocumentForURL: withContentsOfURL: display: completionHandler: 

- (void) reopenDocumentForURL: (NSURL*)urlOrNil withContentsOfURL: (NSURL*)contentsURL display: (BOOL)displayDocument completionHandler: (GSCompletionBlock1)completionHandler;
Availability: MacOS-X 10.7.0

Description forthcoming.

reopenDocumentForURL: withContentsOfURL: error: 

- (BOOL) reopenDocumentForURL: (NSURL*)url withContentsOfURL: (NSURL*)contents error: (NSError**)err;
Availability: MacOS-X 10.4.0

Description forthcoming.

reviewUnsavedDocumentsWithAlertTitle: cancellable: 

- (BOOL) reviewUnsavedDocumentsWithAlertTitle: (NSString*)title cancellable: (BOOL)cancellable;
Availability: MacOS-X 10.0.0

If there are any unsaved documents, this method displays an alert panel asking if the user wants to review the unsaved documents. If the user agrees to review the documents, this method calls -closeAllDocuments to close each document (prompting to save a document if it is dirty). If cancellable is YES, then the user is not allowed to cancel this request, otherwise this method will return NO if the user presses the Cancel button. Otherwise returns YES after all documents have been closed (or if there are no unsaved documents.)

reviewUnsavedDocumentsWithAlertTitle: cancellable: delegate: didReviewAllSelector: contextInfo: 

- (void) reviewUnsavedDocumentsWithAlertTitle: (NSString*)title cancellable: (BOOL)cancellable delegate: (id)delegate didReviewAllSelector: (SEL)didReviewAllSelector contextInfo: (void*)contextInfo;
Availability: MacOS-X 10.0.0

Description forthcoming.

runModalOpenPanel: forTypes: 

- (NSInteger) runModalOpenPanel: (NSOpenPanel*)openPanel forTypes: (NSArray*)openableFileExtensions;
Availability: MacOS-X 10.0.0

Invokes [NSOpenPanel -runModalForTypes:] with the NSOpenPanel object openPanel, and passes the openableFileExtensions file types

saveAllDocuments: 

- (IBAction) saveAllDocuments: (id)sender;
Availability: MacOS-X 10.0.0

Description forthcoming.

setAutosavingDelay: 

- (void) setAutosavingDelay: (NSTimeInterval)autosavingDelay;
Availability: MacOS-X 10.4.0

Description forthcoming.

setShouldCreateUI: 

- (void) setShouldCreateUI: (BOOL)flag;
Availability: MacOS-X 10.0.0

Description forthcoming.

shouldCreateUI 

- (BOOL) shouldCreateUI;
Availability: MacOS-X 10.0.0

Description forthcoming.

typeForContentsOfURL: error: 

- (NSString*) typeForContentsOfURL: (NSURL*)url error: (NSError**)err;
Availability: MacOS-X 10.4.0

Description forthcoming.

typeFromFileExtension: 

- (NSString*) typeFromFileExtension: (NSString*)fileExtension;
Availability: MacOS-X 10.0.0

Description forthcoming.

validateMenuItem: 

- (BOOL) validateMenuItem: (NSMenuItem*)anItem;
Availability: MacOS-X 10.0.0

Description forthcoming.

validateUserInterfaceItem: 

- (BOOL) validateUserInterfaceItem: (id)anItem;
Availability: MacOS-X 10.0.0

Description forthcoming.

willPresentError: 

- (NSError*) willPresentError: (NSError*)err;
Availability: MacOS-X 10.4.0

Description forthcoming.


Up