Changeset 10513


Ignore:
Timestamp:
Apr 23, 2010, 2:05:34 AM (8 years ago)
Author:
livings124
Message:

#3006 Allow Trackers to be pasted in Create Window

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/CreatorWindowController.h

    r9844 r10513  
    6161- (void) addRemoveTracker: (id) sender;
    6262
     63- (void) paste: (id) sender;
     64
    6365@end
  • trunk/macosx/CreatorWindowController.m

    r10240 r10513  
    2424
    2525#import "CreatorWindowController.h"
     26#import "NSApplicationAdditions.h"
    2627#import "NSStringAdditions.h"
    2728#import "utils.h" //tr_urlIsValidTracker
     
    320321{
    321322    [fTrackerAddRemoveControl setEnabled: [fTrackerTable numberOfSelectedRows] > 0 forSegment: TRACKER_REMOVE_TAG];
     323}
     324
     325- (BOOL) validateMenuItem: (NSMenuItem *) menuItem
     326{
     327    const SEL action = [menuItem action];
     328   
     329    if (action == @selector(paste:))
     330        return [[self window] firstResponder] == fTrackerTable
     331            && ([NSApp isOnSnowLeopardOrBetter]
     332                ? [[NSPasteboard generalPasteboard] canReadObjectForClasses: [NSArray arrayWithObject: [NSString class]] options: nil]
     333                : [[NSPasteboard generalPasteboard] availableTypeFromArray: [NSArray arrayWithObject: NSStringPboardType]] != nil);
     334   
     335    return YES;
     336}
     337
     338- (void) paste: (id) sender
     339{
     340    NSMutableArray * tempTrackers = [NSMutableArray array];
     341   
     342    if ([NSApp isOnSnowLeopardOrBetter])
     343    {
     344        NSArray * items = [[NSPasteboard generalPasteboard] readObjectsForClasses:
     345                            [NSArray arrayWithObject: [NSString class]] options: nil];
     346        NSAssert(items != nil, @"no string items to paste; should not be able to call this method");
     347       
     348        for (NSString * pbItem in items)
     349        {
     350            for (NSString * tracker in [pbItem componentsSeparatedByString: @"\n"])
     351                [tempTrackers addObject: tracker];
     352        }
     353    }
     354    else
     355    {
     356        NSString * pbItem =[[NSPasteboard generalPasteboard] stringForType: NSStringPboardType];
     357        NSAssert(pbItem != nil, @"no string items to paste; should not be able to call this method");
     358       
     359        for (NSString * tracker in [pbItem componentsSeparatedByString: @"\n"])
     360            [tempTrackers addObject: tracker];
     361    }
     362   
     363    BOOL added = NO;
     364   
     365    for (NSString * tracker in tempTrackers)
     366    {
     367        tracker = [tracker stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
     368       
     369        if ([tracker rangeOfString: @"://"].location == NSNotFound)
     370            tracker = [@"http://" stringByAppendingString: tracker];
     371       
     372        if (tr_urlIsValidTracker([tracker UTF8String]))
     373        {
     374            [fTrackers addObject: tracker];
     375            added = YES;
     376        }
     377    }
     378   
     379    if (added)
     380    {
     381        [fTrackerTable deselectAll: self];
     382        [fTrackerTable reloadData];
     383    }
     384    else
     385        NSBeep();
    322386}
    323387
Note: See TracChangeset for help on using the changeset viewer.