Ignore:
Timestamp:
Dec 29, 2011, 6:40:17 PM (11 years ago)
Author:
livings124
Message:

#4688 On Lion use new dragging functionality, allowing for the count of dragged files to appear under the mouse pointer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r13108 r13121  
    115115#define GROWL_AUTO_SPEED_LIMIT  @"Speed Limit Auto Changed"
    116116
     117#warning remove when Lion-only
    117118#define TORRENT_TABLE_VIEW_DATA_TYPE    @"TorrentTableViewDataType"
    118119
     
    399400                                "Main window -> 3rd bottom left button (remove all) tooltip")];
    400401   
    401     [fTableView registerForDraggedTypes: [NSArray arrayWithObject: TORRENT_TABLE_VIEW_DATA_TYPE]];
     402    [fTableView registerForDraggedTypes: [NSArray arrayWithObjects: TORRENT_TABLE_VIEW_DATA_TYPE, NSPasteboardTypeString, nil]];
    402403    [fWindow registerForDraggedTypes: [NSArray arrayWithObjects: NSFilenamesPboardType, NSURLPboardType, nil]];
    403404   
     
    24762477}
    24772478
     2479#warning remove when Lion-only
    24782480- (BOOL) outlineView: (NSOutlineView *) outlineView writeItems: (NSArray *) items toPasteboard: (NSPasteboard *) pasteboard
    24792481{
     
    24902492        }
    24912493       
    2492         [pasteboard declareTypes: [NSArray arrayWithObject: TORRENT_TABLE_VIEW_DATA_TYPE] owner: self];
    24932494        [pasteboard setData: [NSKeyedArchiver archivedDataWithRootObject: indexSet] forType: TORRENT_TABLE_VIEW_DATA_TYPE];
    24942495        return YES;
     
    24972498}
    24982499
    2499 - (NSDragOperation) outlineView: (NSOutlineView *) outlineView validateDrop: (id < NSDraggingInfo >) info proposedItem: (id) item
    2500     proposedChildIndex: (NSInteger) index
    2501 {
    2502     NSPasteboard * pasteboard = [info draggingPasteboard];
    2503     if ([[pasteboard types] containsObject: TORRENT_TABLE_VIEW_DATA_TYPE])
     2500- (id <NSPasteboardWriting>) outlineView: (NSOutlineView *) outlineView pasteboardWriterForItem: (id) item
     2501{
     2502    //only allow reordering of rows if sorting by order
     2503    if ([item isKindOfClass: [Torrent class]] && ([fDefaults boolForKey: @"SortByGroup"] || [[fDefaults stringForKey: @"Sort"] isEqualToString: SORT_ORDER]))
     2504    {
     2505        NSPasteboardItem * pbItem = [[[NSPasteboardItem alloc] init] autorelease];
     2506        #warning might make more sense to use TORRENT_TABLE_VIEW_DATA_TYPE
     2507        [pbItem setData: [NSKeyedArchiver archivedDataWithRootObject: [NSNumber numberWithInteger: [fTableView rowForItem: item]]] forType: NSPasteboardTypeString];
     2508        return pbItem;
     2509    }
     2510    else
     2511        return nil;
     2512}
     2513
     2514- (NSDragOperation) outlineView: (NSOutlineView *) outlineView validateDrop: (id <NSDraggingInfo>) info proposedItem: (id) item proposedChildIndex: (NSInteger) index
     2515{
     2516    if ([info draggingSource] == outlineView)
    25042517    {
    25052518        if ([fDefaults boolForKey: @"SortByGroup"])
     
    25402553}
    25412554
    2542 - (BOOL) outlineView: (NSOutlineView *) outlineView acceptDrop: (id < NSDraggingInfo >) info item: (id) item
    2543     childIndex: (NSInteger) newRow
    2544 {
    2545     NSPasteboard * pasteboard = [info draggingPasteboard];
    2546     if ([[pasteboard types] containsObject: TORRENT_TABLE_VIEW_DATA_TYPE])
     2555- (BOOL) outlineView: (NSOutlineView *) outlineView acceptDrop: (id <NSDraggingInfo>) info item: (id) item childIndex: (NSInteger) newRow
     2556{
     2557    if ([info draggingSource] == outlineView)
    25472558    {
    25482559        //remember selected rows
    25492560        NSArray * selectedValues = [fTableView selectedValues];
    2550    
    2551         NSIndexSet * indexes = [NSKeyedUnarchiver unarchiveObjectWithData: [pasteboard dataForType: TORRENT_TABLE_VIEW_DATA_TYPE]];
    2552        
    2553         //get the torrents to move
    2554         NSMutableArray * movingTorrents = [NSMutableArray arrayWithCapacity: [indexes count]];
    2555         for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
    2556             [movingTorrents addObject: [fTableView itemAtRow: i]];
     2561       
     2562        NSMutableArray * movingTorrents;
     2563        if ([[[info draggingPasteboard] types] containsObject: TORRENT_TABLE_VIEW_DATA_TYPE])
     2564        {
     2565            NSAssert(![NSApp isOnLionOrBetter], @"Dragging using pre-Lion functionality on Lion or greater");
     2566           
     2567            NSIndexSet * indexes = [NSKeyedUnarchiver unarchiveObjectWithData: [[info draggingPasteboard] dataForType: TORRENT_TABLE_VIEW_DATA_TYPE]];
     2568           
     2569            //get the torrents to move
     2570            movingTorrents = [NSMutableArray arrayWithCapacity: [indexes count]];
     2571            for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
     2572                [movingTorrents addObject: [fTableView itemAtRow: i]];   
     2573        }
     2574        else
     2575        {
     2576            NSAssert([NSApp isOnLionOrBetter], @"Dragging using Lion functionality on pre-Lion");
     2577           
     2578            movingTorrents = [NSMutableArray arrayWithCapacity: info.numberOfValidItemsForDrop];
     2579            [info enumerateDraggingItemsWithOptions: 0 forView: outlineView classes: [NSArray arrayWithObject: [NSPasteboardItem class]] searchOptions: nil usingBlock: ^(NSDraggingItem * draggingItem, NSInteger index, BOOL * stop) {
     2580                NSNumber * rowNumber = [NSKeyedUnarchiver unarchiveObjectWithData: [draggingItem.item dataForType: NSPasteboardTypeString]];
     2581                [movingTorrents addObject: [fTableView itemAtRow: [rowNumber integerValue]]];
     2582            }];
     2583        }
    25572584       
    25582585        //reset groups
Note: See TracChangeset for help on using the changeset viewer.