Revision: 28975 http://sourceforge.net/p/bibdesk/svn/28975 Author: hofman Date: 2024-11-18 09:54:04 +0000 (Mon, 18 Nov 2024) Log Message: ----------- Use application:openURLs: delegate method to handle gURL events
Modified Paths: -------------- trunk/bibdesk/BDSKAppController.m Modified: trunk/bibdesk/BDSKAppController.m =================================================================== --- trunk/bibdesk/BDSKAppController.m 2024-11-12 16:22:42 UTC (rev 28974) +++ trunk/bibdesk/BDSKAppController.m 2024-11-18 09:54:04 UTC (rev 28975) @@ -102,10 +102,6 @@ BDSKStartupOpenLastOpenFiles }; -@interface BDSKAppController (Private) -- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent; -@end - @implementation BDSKAppController // remove legacy comparisons of added/created/modified strings in table column code from prefs @@ -310,9 +306,6 @@ // this registered the value transformers for radio buttons [BDSKRadioTransformer class]; - - // register URL handler - [[NSAppleEventManager sharedAppleEventManager] setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL]; } - (void)applicationDidFinishLaunching:(NSNotification *)aNotification{ @@ -424,6 +417,57 @@ } } +- (void)application:(NSApplication *)sender openURLs:(NSArray *)urls { + didCheckReopen = YES; + + NSAppleEventDescriptor *errr = [[[NSAppleEventManager sharedAppleEventManager] currentAppleEvent] descriptorForKeyword:'errr']; + BOOL errorReporting = errr ? [errr booleanValue] : YES; + + for (NSURL *theURL in urls) { + BibDocument *document = nil; + NSError *error = nil; + + if ([[theURL scheme] isEqualToString:BDSKBibItemURLScheme]) { + + NSString *citeKey = [[[theURL absoluteString] substringFromIndex:9] stringByRemovingPercentEncoding]; + NSURL *fileURL = [[NSFileManager defaultManager] spotlightCacheFileURLWithCiteKey:citeKey]; + + if (fileURL) { + [[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:fileURL display:YES completionHandler:^(NSDocument *doc, BOOL wasOpen, NSError *err){ + if (doc == nil && err && errorReporting) + [NSApp presentError:err]; + }]; + } else { + error = [NSError localErrorWithCode:kBDSKURLOperationFailed localizedDescription:NSLocalizedString(@"Unable to get item from bdsk:// URL.", @"error when opening bdskURL")]; + } + + } else if ([[theURL scheme] isEqualToString:BDSKSearchGroupURLScheme]) { + + BDSKSearchGroup *group = [[BDSKSearchGroup alloc] initWithURL:theURL]; + + if (group) { + document = [[NSDocumentController sharedDocumentController] currentBibliographyDocumentAndDisplay:YES error:&error]; + [[document groups] addChildGroup:group]; + } else { + error = [NSError localErrorWithCode:kBDSKURLOperationFailed localizedDescription:NSLocalizedString(@"Unable to get search group from bdsksearch:// URL.", @"error when opening bdsksearch URL")]; + } + + } else if ([@"http" isCaseInsensitiveEqual:[theURL scheme]] || [@"https" isCaseInsensitiveEqual:[theURL scheme]] || [@"file" isCaseInsensitiveEqual:[theURL scheme]] || [[theURL absoluteString] hasCaseInsensitivePrefix:@"bibdesk:"]) { + + document = [[NSDocumentController sharedDocumentController] currentBibliographyDocumentAndDisplay:YES error:&error]; + [document openURL:theURL]; + + } else if (theURL) { + + [[NSWorkspace sharedWorkspace] openURL:theURL]; + + } + + if (error && errorReporting) + [NSApp presentError:error]; + } +} + // we don't want to reopen last open files or show an Open dialog when re-activating the app - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag { NSInteger startupOption = [[NSUserDefaults standardUserDefaults] integerForKey:BDSKStartupBehaviorKey]; @@ -764,65 +808,4 @@ [sud setBool:NO == [sud boolForKey:BDSKHistoryByDateKey] forKey:BDSKHistoryByDateKey]; } -#pragma mark URL handling code - - -- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent{ - didCheckReopen = YES; - - NSString *theURLString = [[event descriptorForKeyword:keyDirectObject] stringValue]; - NSURL *theURL = nil; - BibDocument *document = nil; - NSError *error = nil; - NSAppleEventDescriptor *errr = [event descriptorForKeyword:'errr']; - BOOL errorReporting = errr ? [errr booleanValue] : YES; - - if (theURLString) { - if ([theURLString hasPrefix:@"<"] && [theURLString hasSuffix:@">"]) - theURLString = [theURLString substringWithRange:NSMakeRange(0, [theURLString length] - 2)]; - if ([theURLString hasPrefix:@"URL:"]) - theURLString = [theURLString substringFromIndex:4]; - theURL = [NSURL URLWithString:theURLString] ?: [NSURL URLWithStringByNormalizingPercentEscapes:theURLString]; - } - - if ([[theURL scheme] isEqualToString:BDSKBibItemURLScheme]) { - - NSString *citeKey = [[theURLString substringFromIndex:9] stringByRemovingPercentEncoding]; - NSURL *fileURL = [[NSFileManager defaultManager] spotlightCacheFileURLWithCiteKey:citeKey]; - - if (fileURL) { - [[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:fileURL display:YES completionHandler:^(NSDocument *doc, BOOL wasOpen, NSError *err){ - if (doc == nil && err && errorReporting) - [NSApp presentError:err]; - }]; - } else { - error = [NSError localErrorWithCode:kBDSKURLOperationFailed localizedDescription:NSLocalizedString(@"Unable to get item from bdsk:// URL.", @"error when opening bdskURL")]; - } - - } else if ([[theURL scheme] isEqualToString:BDSKSearchGroupURLScheme]) { - - BDSKSearchGroup *group = [[BDSKSearchGroup alloc] initWithURL:theURL]; - - if (group) { - document = [[NSDocumentController sharedDocumentController] currentBibliographyDocumentAndDisplay:YES error:&error]; - [[document groups] addChildGroup:group]; - } else { - error = [NSError localErrorWithCode:kBDSKURLOperationFailed localizedDescription:NSLocalizedString(@"Unable to get search group from bdsksearch:// URL.", @"error when opening bdsksearch URL")]; - } - - } else if ([@"http" isCaseInsensitiveEqual:[theURL scheme]] || [@"https" isCaseInsensitiveEqual:[theURL scheme]] || [@"file" isCaseInsensitiveEqual:[theURL scheme]] || [[theURL absoluteString] hasCaseInsensitivePrefix:@"bibdesk:"]) { - - document = [[NSDocumentController sharedDocumentController] currentBibliographyDocumentAndDisplay:YES error:&error]; - [document openURL:theURL]; - - } else if (theURL) { - - [[NSWorkspace sharedWorkspace] openURL:theURL]; - - } - - if (error && errorReporting) - [NSApp presentError:error]; -} - @end This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Bibdesk-commit mailing list Bibdesk-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bibdesk-commit