Re: saveDocument:
Re: saveDocument:
- Subject: Re: saveDocument:
- From: Graham Cox <email@hidden>
- Date: Thu, 10 May 2012 21:04:12 +1000
On 10/05/2012, at 7:12 PM, ecir hana wrote:
> This is what I try to do - subclass the
> NSDocumentController in applicationWillFinishLaunching:.
Subclassing NSDocumentController is extremely rare, and in almost every case, unnecessary. If you're doing this as a matter of course because you think you need to, you're almost certainly mistaken. I have subclassed this once, and that was because I needed to exclude certain files specifically from the Recent Items menu, and that was the sole reason. Forget about this class, it really just sits there and does its thing and you don't need to worry about it. Its main job is to create the relevant document instance when a file is opened from disk - after that the document itself is fairly autonomous. One of the main inputs to NSDocumentController is the app's property list (info.plist).
> Ok. My NSDocument has "saveDocument:", and my NSDocumentController doesn't
> have it. But the menu has "Save as" disabled.
There is a lot of interaction between the document and the application's info.plist, which describes the file types that the app can read and write and how those files types map to document (sub)classes. There is also the "dirty" state of the document to consider which in turn is influenced strongly by the state of any associated undo manager.
Again, stumbling across the correct precise set of connections by trying to build this bottom-up is unlikely to work.
> For instance, MyDocument.m does not even have to have dataOfType:error: or readFromData:ofType:error: in order to show "Save as" enabled in the menu
Indeed, that is quite true, and perfectly logical. Because the state of the menu has nothing to do with the actual data read or written by the document to disk, but by its internal state. After all, the user needs to choose a destination for a Save As before data can be written to that file, so the menu must be enabled and handled long before the document is asked to supply the file data to be written.
Also, reading data from a file has very little influence on the Save As menu, except that it will clear the dirty state initially. How the document interprets a file's content is up to it, and it is not required to maintain that file data internally or keep the file open, for example. It is very common for a document to read a file into some totally different internal form, manage that while the document is open, then write it out to a file when required.
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden