1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 09:37:56 +00:00

#4686 Capture pasted strings that are URLs

This commit is contained in:
Mitchell Livingston 2011-12-26 02:33:13 +00:00
parent 01590dacf3
commit aafb346abd

View file

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