• 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: Brian Webster <email@hidden>
  • Date: Tue, 3 Jul 2001 14:18:20 -0500

On Monday, July 2, 2001, at 10:13 PM, cocoa-dev-
email@hidden wrote:

Hi,

My document-based app creates documents programmatically, based on input
(user login info) from a panel. Currently, the panel creates the
document object with:

[[NSDocumentController sharedDocumentController]
openUntitledDocumentOfType:@"MainDocument" display:YES];

, then passes the input data to the document object. Ideally, I'd like
to pass the input data during the creation of the document so that the
document object can authenticate the user login info before creating the
window controller and, if necessary, abort the document altogether.

Can anyone suggest a good way to do this? Do I need to subclass
NSDocumentController?

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


  • Follow-Ups:
    • Re: Customized document creation
      • From: Michael Dagate <email@hidden>
    • Re: Customized document creation
      • From: Michael Dagate <email@hidden>
  • Prev by Date: Java and Cocoa - NSTableView and NSOutlineView
  • Next by Date: Re: [ANN] FDWeakReferencingObject and FDObjectiveMethod
  • Previous by thread: Customized document creation
  • Next by thread: Re: Customized document creation
  • Index(es):
    • Date
    • Thread