Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
613
0
West-Europe
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.

Code:
-(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

Moderator emeritus
Jun 15, 2000
7,958
7
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

macrumors 6502a
Original poster
Jun 8, 2005
613
0
West-Europe
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

macrumors 6502a
Original poster
Jun 8, 2005
613
0
West-Europe
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.

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

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

	[NSApp stopModalWithCode:1];
	[self close];
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.