Add NSDocumentController for Open Recent... support.

This commit is contained in:
Kelvin Sherlock 2011-03-03 23:14:01 -05:00
parent 5edc2cee6c
commit 63cd46eeaa
2 changed files with 14 additions and 4 deletions

View File

@ -10,7 +10,8 @@
@interface Image_OpenerAppDelegate : NSObject <NSApplicationDelegate> {
@private
NSWindow *window;
NSWindow *_window;
NSDocumentController *_controller;
}
@property (assign) IBOutlet NSWindow *window;

View File

@ -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];
}
}