From aafb346abdc450180445112571034fe1dfd40bba Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Mon, 26 Dec 2011 02:33:13 +0000 Subject: [PATCH] #4686 Capture pasted strings that are URLs --- macosx/TorrentTableView.m | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/macosx/TorrentTableView.m b/macosx/TorrentTableView.m index 8bec13557..991569540 100644 --- a/macosx/TorrentTableView.m +++ b/macosx/TorrentTableView.m @@ -540,12 +540,27 @@ return [fTorrentCell iconRectForBounds: [self rectOfRow: row]]; } -#warning catch string urls? - (void) paste: (id) sender { NSURL * url; if ((url = [NSURL URLFromPasteboard: [NSPasteboard generalPasteboard]])) [fController openURL: [url absoluteString]]; + + if ([NSApp isOnLionOrBetter]) + { + NSArray * items = [[NSPasteboard generalPasteboard] readObjectsForClasses: [NSArray arrayWithObject: [NSString class]] options: nil]; + if (items) + { + NSDataDetector * detector = [NSDataDetector dataDetectorWithTypes: NSTextCheckingTypeLink error: nil]; + for (NSString * pbItem in items) + { + for (NSTextCheckingResult * result in [detector matchesInString: pbItem options: 0 range: NSMakeRange(0, [pbItem length])]) + { + [fController openURL: [[result URL] absoluteString]]; + } + } + } + } } - (BOOL) validateMenuItem: (NSMenuItem *) menuItem @@ -553,7 +568,23 @@ SEL action = [menuItem action]; if (action == @selector(paste:)) - return [[[NSPasteboard generalPasteboard] types] containsObject: NSURLPboardType]; + { + if ([[[NSPasteboard generalPasteboard] types] containsObject: NSURLPboardType]) + return YES; + + NSArray * items = [[NSPasteboard generalPasteboard] readObjectsForClasses: [NSArray arrayWithObject: [NSString class]] options: nil]; + if (items) + { + NSDataDetector * detector = [NSDataDetector dataDetectorWithTypes: NSTextCheckingTypeLink error: nil]; + for (NSString * pbItem in items) + { + if ([detector firstMatchInString: pbItem options: 0 range: NSMakeRange(0, [pbItem length])]) + return YES; + } + } + + return NO; + } return YES; }