I am planning to create a project-based Mac application. It has its own project file format and is currently able to read and handle it. That’s already the problem of the whole story: I open the project file and not the files each by each/individually.
This means the NSDocument architecture thinks the user is editing the project file. He/She isn’t. Currently my application takes over the reading part by opening the project files each by each manually but it’s hard to implement anything else like Autosave or Versions for the files in the project because they just refer to the project file.
So my question is: How do I use NSDocument in this kind of project architecture so it actually knows I am editing just a part of the project or a completely different file? Or is there a different approach I should use?
Currently the options “Save” and “Revert to Saved” are disabled. Why does this happen? Normally the options should be enabled for the project file.
You seem to be assuming that a document-based app can handle only one type of document. That is not the case, the document architecture can handle as many different types of document as you like.
Just create two different subclasses of
NSDocument, one for your project file and one for your actual documents. You’d need to make edit your Info.plist to add the new document type and associate it with its own file extension/UTI.Doing it this way makes it very straightforward for both types of document (project file and document file) to reap the benefits of the document architecture.
Things can get a little more complicated if you are handling the documents by loading them into a parent project window (à la Xcode). If that is the case then you would need to write custom
NSDocumentControllerandNSWindowControllersubclasses.