Up
Authors
- Carl Lindberg (
Carl.Lindberg@hbo.com)
-
Date: Generated at 2025-12-03
The abstract document class
Copyright: (C) 1999 Free Software Foundation, Inc.
- Declared in:
- AppKit/NSDocument.h
Availability: OpenStep
NSDocument is the abstract base class for
document-based applications in the AppKit
framework. This class provides a comprehensive
foundation for managing individual documents
within a multi-document application architecture.
NSDocument handles the complete document lifecycle
including creation, loading, saving, printing, and
closing operations. The class integrates seamlessly
with NSDocumentController for application-level document
management and NSWindowController for document
presentation and user interaction. Key
responsibilities include file I/O
operations, change tracking with undo support,
window management, print operations, and user
interface validation. NSDocument supports various
file formats, automatic and manual save operations,
error handling, and delegate-based callbacks for
asynchronous operations. Subclasses must
override specific methods to provide
document-specific functionality while
leveraging the extensive infrastructure provided
by the base class.
+ (BOOL)
isNativeType: (
NSString*)type;
Availability: OpenStep
Tests whether the specified type
represents a native file format for this
document class. Native types are formats that
preserve all document information without data
loss and represent the primary or preferred storage
format for this document type. This
method helps distinguish between native formats and
export/import formats that may not preserve
complete document fidelity. The document
controller uses this information for save
operation behavior, determining when to prompt
users about potential data loss or format
limitations. Subclasses should override this
method to identify their native file formats
accurately.
+ (
NSArray*)
readableTypes;
Availability: OpenStep
Returns an array of file types that this document
class can read and open. The returned array contains
type identifier strings that correspond to file
formats supported for document loading operations.
These types are typically UTI strings or file
extensions that define the readable formats for
this document class. The document controller uses this
information to determine which document classes
can handle specific file types during open operations.
Subclasses should override this method to
specify their supported input formats, enabling
proper document type resolution and automatic
document class selection based on file
characteristics.
+ (
NSArray*)
writableTypes;
Availability: OpenStep
Returns an array of file types that this document
class can write and save. The returned array contains
type identifier strings that correspond to file
formats supported for document saving operations.
These types define the available output formats that
users can select when saving documents of this class.
The document controller and save panels use this
information to populate format selection
controls and validate save operations. Subclasses
should override this method to specify their
supported output formats, enabling appropriate
save format options and proper file type handling
during save operations.
- (void)
addWindowController: (
NSWindowController*)windowController;
Availability: OpenStep
Adds the specified window controller to this
document's controller collection. The
windowController parameter represents an
NSWindowController instance that will
manage document presentation and user interface
coordination. This method establishes the
bidirectional relationship between the
document and its window controller, enabling
proper document lifecycle management and user
interface synchronization. The document retains
the window controller and configures it for
document-specific operations. Multiple
window controllers can be added to support complex
document presentations with specialized interface
components.
- (void)
autosaveDocumentWithDelegate: (id)delegate
didAutosaveSelector: (SEL)didAutosaveSelector
contextInfo: (void*)context;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (
NSURL*)
autosavedContentsFileURL;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (
NSString*)
autosavingFileType;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (BOOL)
canCloseDocument;
Availability: MacOS-X 10.0.0 removed at MacOS-X 10.4.0
Description forthcoming.
- (void)
canCloseDocumentWithDelegate: (id)delegate
shouldCloseSelector: (SEL)shouldCloseSelector
contextInfo: (void*)contextInfo;
Availability: MacOS-X 10.0.0
Description forthcoming.
- (void)
close;
Availability: OpenStep
Closes all the windows owned by the document, then
removes itself from the list of documents known by
the NSDocumentController. This method does not ask the
user if they want to save the document before closing.
It is closed without saving any information.
- (
NSData*)
dataOfType: (
NSString*)type
error: (
NSError**)error;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (
NSData*)
dataRepresentationOfType: (
NSString*)type;
Availability: OpenStep
Description forthcoming.
- (
NSString*)
displayName;
Availability: OpenStep
Description forthcoming.
- (
NSDate*)
fileModificationDate;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (
NSString*)
fileName;
Availability: OpenStep
Description forthcoming.
- (BOOL)
fileNameExtensionWasHiddenInLastRunSavePanel;
Availability: MacOS-X 10.1.0
Description forthcoming.
- (
NSString*)
fileNameFromRunningSavePanelForSaveOperation: (
NSSaveOperationType)saveOperation;
Availability: MacOS-X 10.0.0 removed at MacOS-X 10.4.0
Description forthcoming.
- (
NSString*)
fileType;
Availability: OpenStep
Description forthcoming.
- (
NSString*)
fileTypeFromLastRunSavePanel;
Availability: OpenStep
Description forthcoming.
- (
NSURL*)
fileURL;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (
NSFileWrapper*)
fileWrapperRepresentationOfType: (
NSString*)type;
Availability: OpenStep
Description forthcoming.
- (BOOL)
hasUnautosavedChanges;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (BOOL)
hasUndoManager;
Availability: OpenStep
Returns whether this document has an active undo
manager available for undo and redo operations.
This method indicates the document's undo capability
without requiring access to the actual undo manager
instance. Documents with undo managers can track
and reverse changes, while those without undo managers
operate in a linear modification mode without
change reversal capabilities. User interface
elements like Undo menu items use this information
to determine their availability and enabled state.
Applications can use this method to
conditionally enable undo- dependent features
and provide appropriate user feedback about available
functionality.
- (id)
init;
Availability: OpenStep
Initializes a new empty document instance with
default settings. This designated initializer
creates a new document without loading content from
any file source, suitable for creating blank documents
that users will populate with content. The
initialization process establishes default
document state, creates necessary internal
structures, and prepares the document for
content editing and user interaction. Subclasses
should override this method to perform
document-specific initialization while
ensuring proper super class initialization. This
method is typically used when creating new documents
through menu actions or programmatic document
creation workflows.
- (id)
initForURL: (
NSURL*)forUrl
withContentsOfURL: (
NSURL*)url
ofType: (
NSString*)type
error: (
NSError**)error;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (id)
initWithContentsOfFile: (
NSString*)fileName
ofType: (
NSString*)fileType;
Availability: OpenStep
Initializes a new document instance by loading
content from the specified file path with the given
file type. The fileName parameter specifies
the complete path to the source file, while
fileType identifies the format for proper
content interpretation and loading. This
initialization method handles file reading,
content parsing, and document state setup in a
single operation. The document's file location and
type properties are automatically configured based on
the provided parameters. Subclasses typically override
this method to implement format-specific loading logic
while leveraging the base class infrastructure for
standard document management operations.
Initialises the receiver with the contents of
the document at fileName assuming that the
type of data is as specified by fileType.
Destroys the receiver and returns
nil on failure.
- (id)
initWithContentsOfURL: (
NSURL*)url
ofType: (
NSString*)fileType;
Availability: OpenStep
Initializes a new document instance by loading
content from the specified URL with the given file
type. The url parameter specifies the
source location using URL syntax, supporting both
local file URLs and potentially remote resources
depending on implementation. The
fileType parameter identifies the content
format for proper interpretation during loading.
This method provides URL-based initialization with
automatic content loading and document
configuration. Modern document
implementations should prefer URL-based
methods for enhanced flexibility and network
resource support. Subclasses override this method
to implement format-specific URL-based loading while
maintaining standard document lifecycle
behavior.
Initialises the receiver with
the contents of the document at url assuming
that the type of data is as specified by
fileType.
Destroys the receiver and
returns nil on failure.
- (id)
initWithContentsOfURL: (
NSURL*)url
ofType: (
NSString*)type
error: (
NSError**)error;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (id)
initWithType: (
NSString*)type
error: (
NSError**)error;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (BOOL)
isDocumentEdited;
Availability: OpenStep
Returns whether this document has unsaved changes
that require saving. The document maintains an
internal change count that tracks modifications
since the last save operation, and this method
reports the current edited state based on that
count. The edited state affects user interface
elements like window titles, close confirmations,
and save menu items. Document controllers and window
managers use this information to provide
appropriate user feedback and prevent
accidental data loss. The method returns
YES when the document contains unsaved
changes and NO when all changes have
been saved or the document is in its original state.
- (BOOL)
keepBackupFile;
Availability: OpenStep
Description forthcoming.
- (
NSString*)
lastComponentOfFileName;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (BOOL)
loadDataRepresentation: (
NSData*)data
ofType: (
NSString*)type;
Availability: OpenStep
Description forthcoming.
- (BOOL)
loadFileWrapperRepresentation: (
NSFileWrapper*)wrapper
ofType: (
NSString*)type;
Availability: OpenStep
Description forthcoming.
- (void)
makeWindowControllers;
Availability: OpenStep
Creates the window controllers for the current
document. Calls addWindowController: on the
receiver to add them to the controller array.
- (BOOL)
preparePageLayout: (
NSPageLayout*)pageLayout;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (BOOL)
prepareSavePanel: (
NSSavePanel*)savePanel;
Availability: OpenStep
Description forthcoming.
- (BOOL)
presentError: (
NSError*)error;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (void)
presentError: (
NSError*)error
modalForWindow: (
NSWindow*)window
delegate: (id)delegate
didPresentSelector: (SEL)sel
contextInfo: (void*)context;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (IBAction)
printDocument: (id)sender;
Availability: OpenStep
Description forthcoming.
- (void)
printDocumentWithSettings: (
NSDictionary*)settings
showPrintPanel: (BOOL)flag
delegate: (id)delegate
didPrintSelector: (SEL)sel
contextInfo: (void*)context;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (
NSPrintInfo*)
printInfo;
Availability: OpenStep
Description forthcoming.
- (void)
printShowingPrintPanel: (BOOL)flag;
Availability: OpenStep
Not implemented (as of 2025-12-03).
Please help us by producing an implementation of
this and donating it to the GNUstep project.
- (BOOL)
readFromData: (
NSData*)data
ofType: (
NSString*)type
error: (
NSError**)error;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (BOOL)
readFromFile: (
NSString*)fileName
ofType: (
NSString*)type;
Availability: OpenStep
Description forthcoming.
- (BOOL)
readFromFileWrapper: (
NSFileWrapper*)wrapper
ofType: (
NSString*)type
error: (
NSError**)error;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (BOOL)
readFromURL: (
NSURL*)url
ofType: (
NSString*)type;
Availability: OpenStep
Description forthcoming.
- (BOOL)
readFromURL: (
NSURL*)url
ofType: (
NSString*)type
error: (
NSError**)error;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (void)
removeWindowController: (
NSWindowController*)windowController;
Availability: OpenStep
Description forthcoming.
- (IBAction)
revertDocumentToSaved: (id)sender;
Availability: OpenStep
Reverts the document to its last saved state,
discarding all unsaved changes since the last
save operation. This action method presents user
confirmation when appropriate and then reloads
the document content from its file source. The revert
operation restores the document to its previously
saved state, resetting the change count and edited
status. This method provides a mechanism for
abandoning unwanted changes and returning to
known good document state. The revert process
includes user interface updates and proper window
controller coordination to maintain consistent
document presentation after content restoration.
- (BOOL)
revertToContentsOfURL: (
NSURL*)url
ofType: (
NSString*)type
error: (
NSError**)error;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (BOOL)
revertToSavedFromFile: (
NSString*)fileName
ofType: (
NSString*)type;
Availability: OpenStep
Description forthcoming.
- (BOOL)
revertToSavedFromURL: (
NSURL*)url
ofType: (
NSString*)type;
Availability: OpenStep
Description forthcoming.
- (
NSInteger)
runModalPageLayoutWithPrintInfo: (
NSPrintInfo*)printInfo;
Availability: OpenStep
Description forthcoming.
- (void)
runModalPageLayoutWithPrintInfo: (
NSPrintInfo*)info
delegate: (id)delegate
didRunSelector: (SEL)sel
contextInfo: (void*)context;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (void)
runModalPrintOperation: (
NSPrintOperation*)op
delegate: (id)delegate
didRunSelector: (SEL)sel
contextInfo: (void*)context;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (
NSInteger)
runModalSavePanel: (
NSSavePanel*)savePanel
withAccessoryView: (
NSView*)accessoryView;
Availability: MacOS-X 10.0.0 removed at MacOS-X 10.4.0
Description forthcoming.
- (void)
runModalSavePanelForSaveOperation: (
NSSaveOperationType)saveOperation
delegate: (id)delegate
didSaveSelector: (SEL)didSaveSelector
contextInfo: (void*)contextInfo;
Availability: OpenStep
Description forthcoming.
- (IBAction)
runPageLayout: (id)sender;
Availability: OpenStep
Description forthcoming.
- (IBAction)
saveDocument: (id)sender;
Availability: OpenStep
Performs a save operation for the current
document, preserving changes to the existing file
location. This action method is typically
connected to Save menu items or toolbar buttons
and initiates the standard document save process. If
the document has an established file location, the save
operation writes changes directly to that
location. For new documents without a file
location, this method automatically presents a
save panel to allow the user to specify a save
location and file name. The method handles all
aspects of the save process including user
interface updates, error handling, and change
count management. Successful saves reset the
document's edited status and update the
modification date.
- (IBAction)
saveDocumentAs: (id)sender;
Availability: OpenStep
Performs a save-as operation, allowing the user to
specify a new save location and potentially change
the file format. This action method presents a save
panel regardless of whether the document has an
existing file location, enabling users to create
copies or save in different formats. The save-as
operation preserves the original file while
creating a new file at the specified location.
After successful completion, the document's file
location is updated to the new location, making it
the target for subsequent save operations. This method
supports workflow flexibility and file management
by enabling document duplication and format conversion
capabilities.
- (IBAction)
saveDocumentTo: (id)sender;
Availability: OpenStep
Performs a save-to operation, creating a copy of
the document at a specified location without changing
the current document's file location. Unlike save-as,
this operation preserves the original document's
location as the target for future save operations
while creating an independent copy at the new
location. This action is useful for creating
backups, exporting to different locations, or
generating copies for distribution without
affecting the primary document workflow. The
save-to operation maintains the current document's
edited status and file associations while ensuring
the copy reflects the current document content.
- (void)
saveDocumentWithDelegate: (id)delegate
didSaveSelector: (SEL)didSaveSelector
contextInfo: (void*)contextInfo;
Availability: OpenStep
Description forthcoming.
- (void)
saveToFile: (
NSString*)fileName
saveOperation: (
NSSaveOperationType)saveOperation
delegate: (id)delegate
didSaveSelector: (SEL)didSaveSelector
contextInfo: (void*)contextInfo;
Availability: OpenStep
Description forthcoming.
- (void)
saveToURL: (
NSURL*)url
ofType: (
NSString*)type
forSaveOperation: (
NSSaveOperationType)op
delegate: (id)delegate
didSaveSelector: (SEL)didSaveSelector
contextInfo: (void*)contextInfo;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (void)
setAutosavedContentsFileURL: (
NSURL*)url;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (void)
setFileModificationDate: (
NSDate*)date;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (void)
setFileName: (
NSString*)fileName;
Availability: OpenStep
Description forthcoming.
- (void)
setFileType: (
NSString*)type;
Availability: OpenStep
Description forthcoming.
- (void)
setFileURL: (
NSURL*)url;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (void)
setHasUndoManager: (BOOL)flag;
Availability: OpenStep
Configures whether this document should maintain
an undo manager for change tracking and reversal
operations. The flag parameter
determines whether the document creates and
maintains an undo manager instance. When
YES, the document provides full undo
and redo functionality with change history tracking.
When NO, the document operates without
undo support, which may improve performance for large
documents or specialized applications where undo
functionality is not required. This setting
affects user interface validation, change count
management, and the availability of
undo-related menu items and toolbar buttons.
- (void)
setLastComponentOfFileName: (
NSString*)str;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (void)
setPrintInfo: (
NSPrintInfo*)printInfo;
Availability: OpenStep
Description forthcoming.
- (void)
setUndoManager: (
NSUndoManager*)undoManager;
Availability: OpenStep
Sets the undo manager instance for this document. The
undoManager parameter specifies the
NSUndoManager instance that will handle undo
and redo operations for this document. Setting a custom
undo manager allows applications to provide
specialized undo behavior, shared undo
management across multiple documents, or
enhanced undo functionality beyond the standard
implementation. The document integrates the
provided undo manager with its change tracking and
user interface validation systems. Setting
nil removes undo support from the
document, which may be appropriate for certain
document types or application configurations.
- (void)
setWindow: (
NSWindow*)aWindow;
Availability: OpenStep
Description forthcoming.
- (BOOL)
shouldChangePrintInfo: (
NSPrintInfo*)newPrintInfo;
Availability: OpenStep
Description forthcoming.
- (BOOL)
shouldCloseWindowController: (
NSWindowController*)windowController;
Availability: MacOS-X 10.0.0 removed at MacOS-X 10.4.0
Description forthcoming.
- (void)
shouldCloseWindowController: (
NSWindowController*)windowController
delegate: (id)delegate
shouldCloseSelector: (SEL)callback
contextInfo: (void*)contextInfo;
Availability: MacOS-X 10.0.0
Description forthcoming.
- (BOOL)
shouldRunSavePanelWithAccessoryView;
Availability: OpenStep
Description forthcoming.
- (void)
showWindows;
Availability: OpenStep
Makes all the documents windows visible by ordering
them to the front and making them main or key.
If the document has no windows, this method has no
effect.
- (
NSUndoManager*)
undoManager;
Availability: OpenStep
Returns the undo manager instance associated with
this document. The undo manager coordinates undo and
redo operations for document modifications,
maintaining a history of changes that can be
reversed or reapplied. Each document typically
maintains its own undo manager to provide
isolated undo functionality that doesn't interfere
with other documents. The returned undo manager
integrates with the document's change tracking
system to provide accurate change counts and edited
status updates. Applications can customize undo
behavior by configuring the undo manager or
providing custom undo implementations through the
standard NSUndoManager interface.
- (void)
updateChangeCount: (
NSDocumentChangeType)change;
Availability: OpenStep
Updates the document's change tracking
state based on the specified change type.
The change parameter indicates whether a
modification was made, undone, or cleared,
allowing the document to maintain accurate
change counts and edited status.
NSChangeDone increments the change
count for new modifications, NSChangeUndone
decrements for undo operations, and
NSChangeCleared resets the count after save
operations. This method automatically updates
user interface elements and triggers appropriate
notifications to maintain consistent document
state representation. Proper change
tracking enables undo support, save prompts, and
accurate document status reporting.
- (BOOL)
validateMenuItem: (
NSMenuItem*)anItem;
Availability: OpenStep
Description forthcoming.
- (
NSError*)
willPresentError: (
NSError*)error;
Availability: MacOS-X 10.4.0
Description forthcoming.
- (void)
windowControllerDidLoadNib: (
NSWindowController*)windowController;
Availability: OpenStep
Not implemented (as of 2025-12-03).
Please help us by producing an implementation of
this and donating it to the GNUstep project.
- (void)
windowControllerWillLoadNib: (
NSWindowController*)windowController;
Availability: OpenStep
Not implemented (as of 2025-12-03).
Please help us by producing an implementation of
this and donating it to the GNUstep project.
- (
NSArray*)
windowControllers;
Availability: OpenStep
Returns an array of window controllers currently
associated with this document. Window
controllers manage the presentation and user
interface aspects of the document, with each
controller typically corresponding to a document
window. This method provides access to all window
controllers for document-wide operations,
window enumeration, or controller-specific
customization. The returned array contains
NSWindowController instances that handle
window lifecycle, user interface updates, and user
interaction coordination. Multiple window
controllers enable complex document
presentations with multiple views or
specialized interface panels.
- (
NSWindow*)
windowForSheet;
Availability: MacOS-X 10.3.0
Description forthcoming.
- (
NSString*)
windowNibName;
Availability: OpenStep
Description forthcoming.
- (BOOL)
writeToFile: (
NSString*)fileName
ofType: (
NSString*)type;
Availability: OpenStep
Description forthcoming.
- (BOOL)
writeToURL: (
NSURL*)url
ofType: (
NSString*)type;
Availability: OpenStep
Description forthcoming.
- (BOOL)
writeToURL: (
NSURL*)url
ofType: (
NSString*)type
error: (
NSError**)error;
Availability: MacOS-X 10.4.0
Description forthcoming.
Up