Questions tagged [nsdocument]

NSDocument is an abstract class that defines the interface for documents, objects that can internally represent data displayed in windows and that can read data from and write data to files.

NSDocument is an abstract class that defines the interface for documents, objects that can internally represent data displayed in windows and that can read data from and write data to files. Documents create and manage one or more window controllers and are in turn managed by a document controller. Documents respond to first-responder action messages to save, revert, and print their data.

Conceptually, a document is a container for a body of information identified by a name under which it is stored in a disk file. In this sense, however, the document is not the same as the file but is an object in memory that owns and manages the document data. In the context of the Application Kit, a document is an instance of a custom NSDocument subclass that knows how to represent internally, in one or more formats, persistent data that is displayed in windows.

A document can read that data from a file and write it to a file. It is also the first-responder target for many menu commands related to documents, such as Save, Revert, and Print. A document manages its window’s edited status and is set up to perform undo and redo operations. When a window is closing, the document is asked before the window delegate to approve the closing.

NSDocument is one of the triad of AppKit classes that establish an architectural basis for document-based applications (the others being NSDocumentController and NSWindowController).

References:

NSDocument Class Reference

479 questions
2
votes
2 answers

How do I override -windowTitleForDocumentDisplayName?

In the Mac Developer Reference for windowTitleForDocumentDisplayName, here, it suggests that a window controller can override this method, to customize the window title. For example, a CAD application could append “-Top” or “-Side,” depending on…
2
votes
0 answers

How can I set the title of non-main-windows in an NSDocument application?

I am working on a document-based OSX application, with master-detail style windows. I understand how to open additional windows, to display additional information, by using -makeWindowControllers and adding extra window controllers, but I can't set…
Bob Broadley
  • 171
  • 1
  • 6
  • 19
2
votes
1 answer

Multiple windows per document (Cocoa document based app)

Let's say I have created a new Cocoa application and use Document-based application when I create the project. It will have one window, the one from the NSDocument subclass. How can I make it so that two (or more) windows belong to each document? I…
user3956212
  • 359
  • 2
  • 14
2
votes
1 answer

Where should document-related actions for a Cocoa app be implemented?

I'm writing a document-based Cocoa app that's basically a graphical editing program. I want the user to be able to show/hide non-modal windows (such as an inspector window). Since these windows would be shown/hidden from menu items, where is the…
Adam Preble
  • 2,162
  • 17
  • 28
2
votes
1 answer

Overriding NSDocument's fileWrapperOfType causes "Document could not be saved."

I've got to be missing something simple, but Google is not helping. My file saves and loads fine. (I've overridden dataOfType to get some stuff in it.) Then I override fileWrapperOfType (in preparation for creating a bundle), and I get a "The…
andyvn22
  • 14,696
  • 1
  • 52
  • 74
2
votes
0 answers

NSDocument is not in the responder chain

According to the doc (cf. fig 1.10), the NSDocument should be in the responder chain. However, if I try to log the responder chain via the method - (IBAction)logResponderChain:(id)sender { NSResponder *responder = self.view; while…
Colas
  • 3,473
  • 4
  • 29
  • 68
2
votes
0 answers

What is the chain of actions when I close the window of an NSDocument by clicking?

The question What happens when one click on the red button to close the window attached to an NSDocument? What methods are called on which object? Can I hook up somewhere in the process? Why I ask this question: When I click on the red button here …
Colas
  • 3,473
  • 4
  • 29
  • 68
2
votes
1 answer

Cleaning up NSDocument subclasses

I need to perform some cleanup operations in my NSDocument subclass when documents are closed. With the current implementation having that cleanup code in canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo: it only gets called when the…
Jay
  • 6,572
  • 3
  • 37
  • 65
2
votes
2 answers

Autosave NSDocument model changes that do not origin from the user

I have a NSDocument based OS X app which instead of creating new documents with a blank page shows a panel to the user to chose a template from, like for example Apple's Pages.app does. I made this by manually creating a new NSDocument instance when…
Elwisz
  • 654
  • 1
  • 6
  • 18
2
votes
1 answer

How to disable the NSUndoManager in an NSDocument?

I'm using NSDocument but I would like to disable the undo manager. How can I do it?
Colas
  • 3,473
  • 4
  • 29
  • 68
2
votes
1 answer

Setting up NSDocument for saving a non-native type

My application has a custom format for which it is registered in Info.plist as being an editor and can read and write to that format. It can also read a number of other formats, but cannot write to them. For these formats it is registered in…
iain
  • 5,660
  • 1
  • 30
  • 51
2
votes
1 answer

Creating NSOpenGLView inside an NSDocument (OS X)

I am creating a music-eduaction app that reads in musical scores - not audio files - and will need to present an animated graphical screen. I created a document-based app to make file access easy, and I have it now reading and parsing the files, and…
2
votes
2 answers

How to deactivate window restoration?

I am using SDK 10.8. I am subclassing NSPersistentDocument (but the question might interest people sublassing NSDocument) and I want to deactivate the window restoration. So far, here is what I have done : -(void)restoreStateWithCoder:(NSCoder…
Colas
  • 3,473
  • 4
  • 29
  • 68
2
votes
1 answer

Cocoa custom NSDocument saving

I have an application which I use a third party library for saving and loading data. Normally when using NSDocument, I have override the - (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError method and return the proper data, but…
Kyle
  • 17,317
  • 32
  • 140
  • 246
2
votes
1 answer

NSDocument subclass instance apparently not in responder chain

I'm creating my first NSDocument based application. I'm able to create new documents, both from scratch and by importing legacy files. This app will allow multiple windows per document, so I am overriding makeWindowControllers. This method is…
Jim Rea
  • 161
  • 7