Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 31, 2009, 05:49 AM   #1
MrFusion
macrumors 6502a
 
Join Date: Jun 2005
Location: West-Europe
optimum design for document template picker?

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
}
MrFusion is offline   0 Reply With Quote
Old Jan 31, 2009, 11:57 AM   #2
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
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.
kainjow is offline   0 Reply With Quote
Old Jan 31, 2009, 03:47 PM   #3
MrFusion
Thread Starter
macrumors 6502a
 
Join Date: Jun 2005
Location: West-Europe
Quote:
Originally Posted by kainjow View Post
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 is offline   0 Reply With Quote
Old Feb 1, 2009, 05:09 AM   #4
MrFusion
Thread Starter
macrumors 6502a
 
Join Date: Jun 2005
Location: West-Europe
Quote:
Originally Posted by MrFusion View Post
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];
}
MrFusion is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
[New Update] PazteUp - Awesome Document Layout and Design kdan iPad Apps 5 May 9, 2014 04:36 AM
How to scan a document to true size? (of original document?) DramaLLama Mac Basics and Help 0 Jun 10, 2013 06:43 PM

Forum Jump

All times are GMT -5. The time now is 11:07 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC