PDA

View Full Version : optimum design for document template picker?




MrFusion
Jan 31, 2009, 05:49 AM
I want to be able to pick a document template out of a list. This is a quick action, and the helping window doesn't have to stick around for long.

How do I have to deal with the release call in a nice and clean design? Here, the release call is called before the user makes a choice.

Thanks.


-(IBAction) newDocument:(id)sender {
WinController *wc = [[WinController alloc] init];
[wc setoptions:options];
[wc setselector:@selector(createDocumentFromTemplate:)];
[wc showwindow:nil];
[wc release];

}

-(void) createDocumentFromTemplate:(NSString *) template {
//add document
}



kainjow
Jan 31, 2009, 11:57 AM
If the templates are actual documents that are managed by your NSDocument subclass, I would do it outside of the NSDocument class and in your own separate controller object. Then in the controller, use NSDocumentController to create a new document based on the chosen template. I did something like this a few years back and this is the general model I used.

MrFusion
Jan 31, 2009, 03:47 PM
If the templates are actual documents that are managed by your NSDocument subclass, I would do it outside of the NSDocument class and in your own separate controller object. Then in the controller, use NSDocumentController to create a new document based on the chosen template. I did something like this a few years back and this is the general model I used.

Thanks for the advice.

Can I also not somehow do it in a subclass of NSDocumentController? The code I posted is sitting in such a subclass.

I'll play around with your suggestion. Thanks.

MrFusion
Feb 1, 2009, 05:09 AM
Thanks for the advice.

Can I also not somehow do it in a subclass of NSDocumentController? The code I posted is sitting in such a subclass.

I'll play around with your suggestion. Thanks.

I found a solution, if anyone is interested.

In MyDocumentController, newDocument is overwritten and contains the code below (not all is shown).
The window has a cancel and ok button.


TemplateWindowController *twc = [[TemplateWindowController alloc] init];
if ([NSApp runModalForWindow:[twc window]])
newDoc = [self makeUntitledDocumentFromTemplate:[twc valueForKey:@"chosenTemplate"] error:&err];
[twc release];



-(IBAction) cancelTemplate:(id)sender {
[NSApp stopModalWithCode:0];
[self close];
}
-(IBAction) chooseTemplate:(id)sender {
chosenTemplate = ...

[NSApp stopModalWithCode:1];
[self close];
}