From 63cd46eeaa0b6a91872bffccb9bcbb74f839ef5b Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Thu, 3 Mar 2011 23:14:01 -0500 Subject: [PATCH] Add NSDocumentController for Open Recent... support. --- Image Opener/Image_OpenerAppDelegate.h | 3 ++- Image Opener/Image_OpenerAppDelegate.m | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Image Opener/Image_OpenerAppDelegate.h b/Image Opener/Image_OpenerAppDelegate.h index c5fd68c..2f7e64f 100644 --- a/Image Opener/Image_OpenerAppDelegate.h +++ b/Image Opener/Image_OpenerAppDelegate.h @@ -10,7 +10,8 @@ @interface Image_OpenerAppDelegate : NSObject { @private - NSWindow *window; + NSWindow *_window; + NSDocumentController *_controller; } @property (assign) IBOutlet NSWindow *window; diff --git a/Image Opener/Image_OpenerAppDelegate.m b/Image Opener/Image_OpenerAppDelegate.m index c61c128..81fb653 100644 --- a/Image Opener/Image_OpenerAppDelegate.m +++ b/Image Opener/Image_OpenerAppDelegate.m @@ -11,13 +11,21 @@ @implementation Image_OpenerAppDelegate -@synthesize window; +@synthesize window = _window; - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { + _controller = [[NSDocumentController sharedDocumentController] retain]; // Insert code here to initialize your application } +- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename +{ + WindowController *controller; + controller = [WindowController controllerWithFilePath: filename]; + return YES; +} + -(IBAction)openDocument:(id)sender { NSOpenPanel *panel; @@ -35,7 +43,6 @@ if (result == 1) { - WindowController *controller; NSURL *url = [[panel URLs] lastObject]; NSString *path = [url isFileURL] ? [url path] : nil; @@ -43,7 +50,9 @@ if (path) { - controller = [WindowController controllerWithFilePath: path]; + [self application: nil openFile: path]; + + [_controller noteNewRecentDocumentURL: url]; } }