Changeset 13116


Ignore:
Timestamp:
Dec 26, 2011, 2:33:13 AM (9 years ago)
Author:
livings124
Message:

#4686 Capture pasted strings that are URLs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/TorrentTableView.m

    r13023 r13116  
    541541}
    542542
    543 #warning catch string urls?
    544543- (void) paste: (id) sender
    545544{
     
    547546    if ((url = [NSURL URLFromPasteboard: [NSPasteboard generalPasteboard]]))
    548547        [fController openURL: [url absoluteString]];
     548   
     549    if ([NSApp isOnLionOrBetter])
     550    {
     551        NSArray * items = [[NSPasteboard generalPasteboard] readObjectsForClasses: [NSArray arrayWithObject: [NSString class]] options: nil];
     552        if (items)
     553        {
     554            NSDataDetector * detector = [NSDataDetector dataDetectorWithTypes: NSTextCheckingTypeLink error: nil];
     555            for (NSString * pbItem in items)
     556            {
     557                for (NSTextCheckingResult * result in [detector matchesInString: pbItem options: 0 range: NSMakeRange(0, [pbItem length])])
     558                {
     559                    [fController openURL: [[result URL] absoluteString]];
     560                }
     561            }
     562        }
     563    }
    549564}
    550565
     
    554569   
    555570    if (action == @selector(paste:))
    556         return [[[NSPasteboard generalPasteboard] types] containsObject: NSURLPboardType];
     571    {
     572        if ([[[NSPasteboard generalPasteboard] types] containsObject: NSURLPboardType])
     573            return YES;
     574       
     575        NSArray * items = [[NSPasteboard generalPasteboard] readObjectsForClasses: [NSArray arrayWithObject: [NSString class]] options: nil];
     576        if (items)
     577        {
     578            NSDataDetector * detector = [NSDataDetector dataDetectorWithTypes: NSTextCheckingTypeLink error: nil];
     579            for (NSString * pbItem in items)
     580            {
     581                if ([detector firstMatchInString: pbItem options: 0 range: NSMakeRange(0, [pbItem length])])
     582                    return YES;
     583            }
     584        }
     585       
     586        return NO;
     587    }
    557588   
    558589    return YES;
Note: See TracChangeset for help on using the changeset viewer.