Add fallback to open recent documents with NSApplicationDelegate methods

If a document can't be created when opening a recent document, the url
points to a local file and the application delegate responds to
application:openFiles: or application:openFile:, call them with
the filename. This is the default behavior on Cocoa on Mac.
This commit is contained in:
Alberto García Hierro 2013-05-12 21:18:10 +01:00
parent b5211d1744
commit 9ef2b1c8c3

@ -502,7 +502,16 @@ static NSDocumentController *shared=nil;
NSError *error=nil;
NSURL *url=[NSURL fileURLWithPath:[paths objectAtIndex:tag]];
[self openDocumentWithContentsOfURL:url display:YES error:&error];
if (![self openDocumentWithContentsOfURL:url display:YES error:&error] || error) {
if ([url isFileURL]) {
NSObject <NSApplicationDelegate> *appDelegate = [NSApp delegate];
if ([appDelegate respondsToSelector:@selector(application:openFiles:)]) {
[appDelegate application:NSApp openFiles:[NSArray arrayWithObject:[url path]]];
} else if ([appDelegate respondsToSelector:@selector(application:openFile:)]) {
[appDelegate application:NSApp openFile:[url path]];
}
}
}
}
}