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
8
votes
1 answer

Add to the "Open Recent" menu an item that doesn't point to a file

Is there a way to add an item that doesn't point to a file that exists on the file system to the "Open Recent" menu? In an application not based on NSDocument, I can add an item to the "Open Recent" submenu with the following…
Guillaume
  • 21,685
  • 6
  • 63
  • 95
8
votes
3 answers

How to use NSViewController in an NSDocument-based Cocoa app

I've got plenty of experience with iOS, but Cocoa has me a bit confused. I read through several Apple docs on Cocoa but there are still details that I could not find anywhere. It seems the documentation was written before the NSDocument-based Xcode…
8
votes
2 answers

NSDocument custom icon not displaying in Finder but displaying in Quick Look

I'm designing a custom application and I've set a custom icon for my file type. I've put the icon on both Document Types and Exported UTIs section (filling in other values too, obviously). Here is what I get when I run: No icon is defined in…
Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389
8
votes
2 answers

How do I initialise a new NSDocument instance in Swift?

Apple documentation suggests to override an NSDocument convenience init (initWithType:error:) as described here. However, as this is a convenience init, I cannot override it. But I still need to execute some code when a new document is created. I do…
Wizard of Kneup
  • 1,863
  • 1
  • 18
  • 35
8
votes
3 answers

How to disable NSDocument's window title popup

I have an NSDocument based app with autosave enabled. I'd like to prevent this popup from showing: I have tried returning nil from NSWindow's –title, –representedFilename and –representedURL which hide the title effectively hide the title but have…
pfandrade
  • 2,359
  • 15
  • 25
8
votes
4 answers

Multiple Documents in a Single Window in Cocoa

I want to write an application which may have multiple documents in a single window via a tabbed interface. Should I avoid the NSDocument architecture (the Cocoa Document-based Application template)? As far as I can tell, it supports only one or…
titaniumdecoy
  • 18,900
  • 17
  • 96
  • 133
7
votes
2 answers

Where do you put cleanup code for NSDocument sub-classes?

I have a document-based application and I have sub-classed NSDocument and provided the required methods, but my document needs some extensive clean-up (needs to run external tasks etc). Where is the best place to put this? I have tried a few…
dreamlax
  • 93,976
  • 29
  • 161
  • 209
7
votes
2 answers

Cocoa/Obj-C - Open file when dragging it to application icon

Currently there is a button on my app inteface which allow to open a file, here is my open code: In my app.h: - (IBAction)selectFile:(id)sender; In my app.m: @synthesize window; - (void)applicationDidFinishLaunching:(NSNotification *)aNotification…
Nono
  • 241
  • 5
  • 15
7
votes
2 answers

NSURL → NSImage → NSImageView

I am playing with AppKit and NSDocument and I don't know why this is not working?: I just wrote this and image is not nil but never loads any image, its size is always zero. Is this the correct method I have to implement to read files into my…
nacho4d
  • 43,720
  • 45
  • 157
  • 240
7
votes
1 answer

Remove 'Show/Hide tab bar' menu item

The latest version of macOS Sierra adds a 'Show/Hide tab bar' menu item to the 'View' menu. It does this dynamically. My application already includes its own tab bar using the MMTabBarView library. I would prefer to continue using this library as…
Kyle
  • 17,317
  • 32
  • 140
  • 246
7
votes
4 answers

How can you implement the NSDocument method -canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo: in Swift?

In my application, a NSDocument subclass mission-critical hardware – users really don’t want to close a document by accident! So, I’ve implemented canCloseDocumentWithDelegate… to show an NSAlert and ask before closing. I am now trying to implement…
DouglasHeriot
  • 1,674
  • 2
  • 13
  • 19
7
votes
3 answers

NSDocument: The document could not be autosaved. The file has been changed by another application

A search on the title of this post reveals that it's pretty common; indeed, I've gotten this error from Xcode. But I can't seem to find any fixes. I'm seeing it now when I run my program, and it appears to occur during or after…
pickwick
  • 3,134
  • 22
  • 30
6
votes
1 answer

How does NSDocumentController slot into my document based app?

I'm building my first serious Cocoa app. It is a document based app using Core Data for persistent storage. Using the Xcode "New project" template options, my project started with a couple of default classes: MainMenu.xib (the main menu of my…
Roger
  • 4,737
  • 4
  • 43
  • 68
6
votes
3 answers

Prevent warning when NSDocument file is programmatically renamed

My application allows the user to rename documents that are currently open. This is trivial, and works fine, with one really annoying bug I can't figure out. When a file is renamed, AppKit (kindly) warns the user the next time they try to save the…
d11wtq
  • 34,788
  • 19
  • 120
  • 195
6
votes
2 answers

NSDocument-based Mac application with bundles for document, super slow to save

So after googling a bit it's my understanding that when I use a bundle for my document in a NSDocument-based app I have to write the entire bundle each time I want to save? This is starting to get problematic here as I'm adding large video files to…
Christian A. Strømmen
  • 3,181
  • 2
  • 25
  • 46
1
2
3
31 32