• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Customized document creation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Customized document creation


  • Subject: Re: Customized document creation
  • From: Michael Dagate <email@hidden>
  • Date: Tue, 3 Jul 2001 19:33:47 -0500

Thanks, Brian. This works great. I got a little creative and made a category for the NSDocumentController class and put my new document-creation method there. Thus, I didn't have to subclass NSDocumentController and I can use the shared NSDocumentController instance.

Out of curiosity, how did you arrive at your implementation of newDocument? In other words, how do you know if it completely and correctly recreates the necessary document-creation steps. I ask only because this scenario exemplifies why it is good have Cocoa source code for reference. Had source code been available, I would have studied the document-creation process and found my answer. (anybody care to discuss the merits of this statement?) :)

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


References: 
 >Re: Customized document creation (From: Brian Webster <email@hidden>)

  • Prev by Date: Updating available services with -[NSWorkspace findApplications]
  • Next by Date: Delegate versus Controller
  • Previous by thread: Re: Customized document creation
  • Next by thread: Re: Customized document creation
  • Index(es):
    • Date
    • Thread