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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Character picker now disabled by default? ricardobeat OS X 1 Nov 8, 2011 02:07 PM
template for NSDocument MrFusion Mac Programming 1 Jan 12, 2011 01:40 AM
Document Template patricksan iPhone/iPad Programming 0 Apr 16, 2009 08:13 AM
Program Design and documentation using Key-Value coding gekko513 Mac Programming 10 May 1, 2006 12:45 PM


All times are GMT -5. The time now is 06:26 AM.

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

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