NSDocument with fixed/auto-generated filename
NSDocument with fixed/auto-generated filename
- Subject: NSDocument with fixed/auto-generated filename
- From: James Bucanek <email@hidden>
- Date: Fri, 2 Jun 2006 09:56:19 -0700
Greetings,
I'm obviously doing something wrong. I have an NSDocument subclass that allows a user to edit a "settings" file. The user can have multiple settings documents.
I want the document to behave exactly like any other document (new, open, close, save, undo, revert, ...) EXCEPT for the single fact the the user doesn't get to name the document. These "settings" files are stored in a pre-defined folder in the user Preferences and their name and window titled are derieved from the settings themselves. The name of the file is auto-generated when the user saves the document.
So, how I can create an NSDocument that behaves like any other NSDocument, it just never asks the user to name the document or where they'd like to save the file?
I *thought* I could do this by simply
1) Disabling the Save As... command in validateMenuItem:
2) Overriding -[NSDocument saveDocument:]. In it I check to see if the file for this document already exists. If not, I generate a unique filename and write the file. If it does already exist, I simply call [super saveDocument:].
However, I'm having all manor of oddball problems and behaviour. If, for example, I open an existing document, modify it, and issue a Save command I often get a "The location of the document "xxx" cannot be determined" warning with a Save As... button (Huh??????).
Also, the isDocumentEdited/Save/Revert/Undo menus aren't behaving themselves. After a save (even to an existing file) the Save, Revert, and Undo commands are still active. I tried to hack that by managing the Save menu myself and adding [[self undoManager] removeAllActions]; [[self window] setDocumentedited:No]; [self updateChangeCount:NSChangeCleared]; to the end of the saveDocument: method. But even that isn't acting quite right, and I suspect that it's not happening automatically becuase I've short-circuited something somewhere.
--
James Bucanek
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden