Instance Method

openDocumentWithContentsOfFile:display:

Returns a document object created from the contents of a given file and optionally displays it.

Declaration

- (id)openDocumentWithContentsOfFile:(NSString *)fileName display:(BOOL)display;

Discussion

Returns an NSDocument object created from the contents of the file fileName (an absolute path) and displays it if flag is YES. The returned object is not retained, but is added to the receiver’s list of managed documents. Returns 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 or HFS file type). Even if flag is YES, the document is not displayed if shouldCreateUI returns NO. This method calls makeDocumentWithContentsOfFile:ofType: to obtain the created NSDocument object. If you override this method, your implementation should be prepared to handle either YES or NO.

To handle an Open Documents Apple event, the Application Kit’s built-in Apple event handling automatically calls this method with the path to the file to open and a display argument.

Called with a display argument of YES instead of NO when a Print Documents Apple event is handled. This may have been handled differently in versions of macOS prior to version 10.3.

See Also

Deprecated Methods

- documentForFileName:

Returns the document object for the file in which the document data is stored.

Deprecated
- fileExtensionsFromType:

Returns the allowable file extensions for the given document type.

Deprecated
- fileNamesFromRunningOpenPanel

Returns a selection of files chosen by the user in the Open panel.

Deprecated
- makeUntitledDocumentOfType:

Creates and returns a document object for document type.

Deprecated
- makeDocumentWithContentsOfURL:ofType:

Creates and returns a document object for the given document type from the contents of a given URL.

Deprecated
- makeDocumentWithContentsOfFile:ofType:

Creates and returns a document object of a given document type from the contents of a file.

Deprecated
- openDocumentWithContentsOfURL:display:

Returns a document object created from the contents of a given URL and optionally displays it.

Deprecated
- openDocumentWithContentsOfURL:display:error:

Opens a document located by the given URL presents its user interface if requested, and returns the document if successful.

Deprecated
- openUntitledDocumentOfType:display:

Returns a document object instantiated from the subclass of the given document type and optionally displays it.

Deprecated
- reopenDocumentForURL:withContentsOfURL:error:

Reopens an autosaved document located by a URL, by reading the contents for the document from another URL, presents its user interface, and returns YES if successful.

Deprecated
- setShouldCreateUI:

Sets whether the window controllers of a document should be created when the document is created.

Deprecated
- shouldCreateUI

Returns a Boolean value that indicates whether the window controllers of a document should be created when the document is created.

Deprecated
- typeFromFileExtension:

Returns the document type associated with files having extension fileExtensionOrHFSFileType.

Deprecated