2011-03-02 03:25:25 +00:00
|
|
|
//
|
|
|
|
// Image_OpenerAppDelegate.m
|
|
|
|
// Image Opener
|
|
|
|
//
|
|
|
|
// Created by Kelvin Sherlock on 3/1/2011.
|
|
|
|
// Copyright 2011 __MyCompanyName__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "Image_OpenerAppDelegate.h"
|
2011-03-04 03:32:37 +00:00
|
|
|
#import "WindowController.h"
|
2011-03-02 03:25:25 +00:00
|
|
|
|
|
|
|
@implementation Image_OpenerAppDelegate
|
|
|
|
|
2011-03-04 04:14:01 +00:00
|
|
|
@synthesize window = _window;
|
2011-03-02 03:25:25 +00:00
|
|
|
|
|
|
|
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
|
|
|
|
{
|
2011-03-04 04:14:01 +00:00
|
|
|
_controller = [[NSDocumentController sharedDocumentController] retain];
|
2011-03-02 03:25:25 +00:00
|
|
|
// Insert code here to initialize your application
|
|
|
|
}
|
|
|
|
|
2011-03-04 04:14:01 +00:00
|
|
|
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
|
|
|
|
{
|
|
|
|
WindowController *controller;
|
|
|
|
controller = [WindowController controllerWithFilePath: filename];
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2011-03-04 03:32:37 +00:00
|
|
|
-(IBAction)openDocument:(id)sender
|
|
|
|
{
|
|
|
|
NSOpenPanel *panel;
|
|
|
|
|
|
|
|
panel = [NSOpenPanel openPanel];
|
|
|
|
|
|
|
|
[panel setCanChooseFiles: YES];
|
|
|
|
[panel setCanCreateDirectories: NO];
|
|
|
|
[panel setResolvesAliases: YES];
|
|
|
|
[panel setAllowsMultipleSelection: NO];
|
|
|
|
[panel setExtensionHidden: NO];
|
|
|
|
|
|
|
|
|
|
|
|
[panel beginWithCompletionHandler: ^(NSInteger result){
|
|
|
|
|
|
|
|
if (result == 1)
|
|
|
|
{
|
|
|
|
NSURL *url = [[panel URLs] lastObject];
|
|
|
|
NSString *path = [url isFileURL] ? [url path] : nil;
|
|
|
|
|
2011-03-04 03:48:06 +00:00
|
|
|
//NSLog(@"%d %@", (int)result, path);
|
2011-03-04 03:32:37 +00:00
|
|
|
|
|
|
|
if (path)
|
|
|
|
{
|
2011-03-04 04:14:01 +00:00
|
|
|
[self application: nil openFile: path];
|
|
|
|
|
|
|
|
[_controller noteNewRecentDocumentURL: url];
|
2011-03-04 03:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-03-02 03:25:25 +00:00
|
|
|
@end
|