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

Can underline, but not bold text in NSTextView

I have an NSDocuments & storyboard app created with the wizard in Xcode 8. In the ViewController Scene I have added a NSTextView. Certain menu items are disabled, such as Bold and Italic. Looking at the First Responder the actions for bold and…
Henrik
  • 3,908
  • 27
  • 48
2
votes
2 answers

Binding to array controller in another nib for inspector window

Binding a popup menu to an array controller with the path selection.type works fine. Binding a popup menu to a document controller with the path currentDocument.arrayController.selection.type works one way only (changes in selection are not…
andyvn22
  • 14,696
  • 1
  • 52
  • 74
2
votes
1 answer

In OS X who owns the model, NSDocument or NSViewController

Working in iOS I've never dealt with OS X and NSDocument based apps. Where should the model reference live, inside the NSDocument or the representedObject in the NSWindow's content NSViewController? Or both?
ahwulf
  • 2,584
  • 15
  • 29
2
votes
1 answer

NSDocument get actual save path?

I am trying to get the path that an NSDocument is being saved to at save time. I tried overriding writeToURL but that would pass me an obscure temp file URL, which was not where it was getting saved. Also asking the document like this [document…
Justin Meiners
  • 10,754
  • 6
  • 50
  • 92
2
votes
1 answer

Close new untitled document when opening a saved document

When I open TextEdit, it opens a new untitled document which is closed as soon as I open a saved document from disk. But even if one would think that this is standard behavior in a document-based app in Cocoa, this doesn't seem to be the case. In my…
Nickkk
  • 2,261
  • 1
  • 25
  • 34
2
votes
3 answers

Document-Based App autosave with storyboards

In Document-Based Apps, using XIB files, when a new window is created its behaviour is: Be positioned and sized based on the position of the last active window. If the last active window is still visible then the new window should be cascaded…
catlan
  • 25,100
  • 8
  • 67
  • 78
2
votes
1 answer

Access NSDocument from ViewController

I've a NSDocument and it saves and read some data. I'd like to use these data in my ViewController. How can I access it? I haven't found any information about doing this in swift, only in obj-c but when I translated it into swift it always…
Gun13
  • 103
  • 9
2
votes
2 answers

How to open a folder or a file with the help of file path in OS x programatically?

I have selected a file using NSOpenPanel and save its url path, but at any time in my os x Application i want to open this file in the default mac application.Suppose if I select an file and click on the open button in my app the file should open in…
2
votes
1 answer

Prevent NSDocument from being created when application gets active

When a document based application becomes active, and there are no open windows, a new document window is automatically created. I want to prevent this behavior and show my "Choose a Template" dialog instead of creating a blank document by…
user187676
2
votes
1 answer

Xcode document icon not updating

I've created an .icns and set it in the Document Types section of my project, but my documents' icons in Finder remain generic. I've noticed that if I change my document type's file extension, the icon displays. Is there a cache I need to clear or…
Tone416
  • 540
  • 3
  • 10
2
votes
0 answers

How to initialize a NSDocument after calling LSLaunchFSRefSpec?

I am working on a document-based application. If I execute this app from the Finder it runs like expected: First the NSApplicationDelegate applicationDidFinishLaunching method is executed. Then the NSPersistentDocument initialization is done. After…
2
votes
1 answer

Xcode - Document Based Application (Document Bundle)

I'm trying to find a somewhat more comprehensive writeup, or an example to refer to regarding a Document Based Application which saves it's contents to a document bundle rather than a single file. A good example of what I mean by a document bundle…
Adrian Sluyters
  • 2,186
  • 1
  • 16
  • 21
2
votes
0 answers

How can I move/reposition the title label + down arrow in a Cocoa Document based application?

My aim is to reposition the combination of title label and dropdown (that appear automatically in the titlebar of a document based app) against the right hand side of the window instead of centred. An alternative: I could set the titlebar to hidden…
Sam
  • 2,745
  • 3
  • 20
  • 42
2
votes
2 answers

How can I save an NSDocument concurrently?

I have a document based application. Saving the document can take a few seconds, so I want to enable the user to continue using the program while it saves the document in the background. Due to the document architecture, my application is asked to…
bastibe
  • 16,551
  • 28
  • 95
  • 126
2
votes
1 answer

NSDocument Subclass not closed by NSWindowController?

Okay, I'm fairly new to Cocoa and Objective-C, and to OOP in general. As background, I'm working on an extensible editor that stores the user's documents in a package. This of course required some "fun" to get around some issues with NSFileWrapper…