Re: Customized document creation
Re: Customized document creation
- Subject: Re: Customized document creation
- From: Michael Dagate <email@hidden>
- Date: Sat, 7 Jul 2001 14:44:29 -0500
I have a small problem with my custom document creation. It seems that
my document object no longer gets released properly. Rather than
subclass NSDocumentController, I made a category and created my own
document-creation method -newDocumentWithData. The code follows Brian's
example below.
If I use the standard -newDocument method, the document object gets
released as expected (my window controller calls -setShouldCloseDocument
to release the document when the window closes). Could
-newDocumentWithData be missing a step?
Thanks in advance,
Michael
On Tuesday, July 3, 2001, at 02:18 PM, Brian Webster wrote:
I have a similar situation in my app where I need to put up a panel and
get input before creating a document, and I can tell you what I did,
although your needs might vary slightly. I created a subclass of
NSDocumentController and overrode the newDocument: method. Actually
I'm not sure which is the best to override, newDocument:,
openUntitledDocumentOfType:display: or makeUntitledDocumentOfType:, but
I used newDocument: in any case. When the user selects New... from the
file menu, the method gets called and my implementation puts up a modal
panel that gets some info. Then my code looks like this:
NSDocument *newDocument = [[MyDocumentClass alloc]
initWithCustomData:blah];
//You only need this line if you'll have multiple window controllers,
otherwise just override -windowNibName in your document subclass
[newDocument makeWindowControllers];
[self addDocument:newDocument];
[newDocument showWindows];
If you want to be able to reject the info during init, probably the
easiest way is to just do a [self autorelease] and return nil from the
init method. If you want to differentiate between different errors,
you might want to raise an exception (and then catch and handle it)
instead of just returning nil. Also, in order for your subclass of
NSDocumentController to be used, you must have an instance of it
instantiated in your main nib.
--
Brian Webster
email@hidden
http://www.owlnet.rice.edu/~bwebster