From 97c9f72cda648604c7e5b182fe37289366c7ba20 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Mon, 2 Jan 2012 23:55:10 +0000 Subject: [PATCH] revert r13121 for the time being --- macosx/Controller.m | 60 ++++++++++++--------------------------------- 1 file changed, 16 insertions(+), 44 deletions(-) diff --git a/macosx/Controller.m b/macosx/Controller.m index c21c6e5ea..471ff93ab 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -114,7 +114,6 @@ typedef enum #define GROWL_AUTO_ADD @"Torrent Auto Added" #define GROWL_AUTO_SPEED_LIMIT @"Speed Limit Auto Changed" -#warning remove when Lion-only #define TORRENT_TABLE_VIEW_DATA_TYPE @"TorrentTableViewDataType" #define ROW_HEIGHT_REGULAR 62.0 @@ -399,7 +398,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy [fClearCompletedButton setToolTip: NSLocalizedString(@"Remove all transfers that have completed seeding.", "Main window -> 3rd bottom left button (remove all) tooltip")]; - [fTableView registerForDraggedTypes: [NSArray arrayWithObjects: TORRENT_TABLE_VIEW_DATA_TYPE, NSPasteboardTypeString, nil]]; + [fTableView registerForDraggedTypes: [NSArray arrayWithObject: TORRENT_TABLE_VIEW_DATA_TYPE]]; [fWindow registerForDraggedTypes: [NSArray arrayWithObjects: NSFilenamesPboardType, NSURLPboardType, nil]]; //you would think this would be called later in this method from updateUI, but it's not reached in awakeFromNib @@ -2476,7 +2475,6 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy } } -#warning remove when Lion-only - (BOOL) outlineView: (NSOutlineView *) outlineView writeItems: (NSArray *) items toPasteboard: (NSPasteboard *) pasteboard { //only allow reordering of rows if sorting by order @@ -2491,30 +2489,18 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy [indexSet addIndex: [fTableView rowForItem: torrent]]; } - [pasteboard declareTypes: [NSArray arrayWithObject: TORRENT_TABLE_VIEW_DATA_TYPE] owner: self]; + [pasteboard declareTypes: [NSArray arrayWithObject: TORRENT_TABLE_VIEW_DATA_TYPE] owner: self]; [pasteboard setData: [NSKeyedArchiver archivedDataWithRootObject: indexSet] forType: TORRENT_TABLE_VIEW_DATA_TYPE]; return YES; } return NO; } -- (id ) outlineView: (NSOutlineView *) outlineView pasteboardWriterForItem: (id) item +- (NSDragOperation) outlineView: (NSOutlineView *) outlineView validateDrop: (id < NSDraggingInfo >) info proposedItem: (id) item + proposedChildIndex: (NSInteger) index { - //only allow reordering of rows if sorting by order - if ([item isKindOfClass: [Torrent class]] && ([fDefaults boolForKey: @"SortByGroup"] || [[fDefaults stringForKey: @"Sort"] isEqualToString: SORT_ORDER])) - { - NSPasteboardItem * pbItem = [[[NSPasteboardItem alloc] init] autorelease]; - #warning might make more sense to use TORRENT_TABLE_VIEW_DATA_TYPE - [pbItem setData: [NSKeyedArchiver archivedDataWithRootObject: [NSNumber numberWithInteger: [fTableView rowForItem: item]]] forType: NSPasteboardTypeString]; - return pbItem; - } - else - return nil; -} - -- (NSDragOperation) outlineView: (NSOutlineView *) outlineView validateDrop: (id ) info proposedItem: (id) item proposedChildIndex: (NSInteger) index -{ - if ([info draggingSource] == outlineView) + NSPasteboard * pasteboard = [info draggingPasteboard]; + if ([[pasteboard types] containsObject: TORRENT_TABLE_VIEW_DATA_TYPE]) { if ([fDefaults boolForKey: @"SortByGroup"]) { @@ -2553,35 +2539,21 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy return NSDragOperationNone; } -- (BOOL) outlineView: (NSOutlineView *) outlineView acceptDrop: (id ) info item: (id) item childIndex: (NSInteger) newRow +- (BOOL) outlineView: (NSOutlineView *) outlineView acceptDrop: (id < NSDraggingInfo >) info item: (id) item + childIndex: (NSInteger) newRow { - if ([info draggingSource] == outlineView) + NSPasteboard * pasteboard = [info draggingPasteboard]; + if ([[pasteboard types] containsObject: TORRENT_TABLE_VIEW_DATA_TYPE]) { //remember selected rows NSArray * selectedValues = [fTableView selectedValues]; + + NSIndexSet * indexes = [NSKeyedUnarchiver unarchiveObjectWithData: [pasteboard dataForType: TORRENT_TABLE_VIEW_DATA_TYPE]]; - NSMutableArray * movingTorrents; - if ([[[info draggingPasteboard] types] containsObject: TORRENT_TABLE_VIEW_DATA_TYPE]) - { - NSAssert(![NSApp isOnLionOrBetter], @"Dragging using pre-Lion functionality on Lion or greater"); - - NSIndexSet * indexes = [NSKeyedUnarchiver unarchiveObjectWithData: [[info draggingPasteboard] dataForType: TORRENT_TABLE_VIEW_DATA_TYPE]]; - - //get the torrents to move - movingTorrents = [NSMutableArray arrayWithCapacity: [indexes count]]; - for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i]) - [movingTorrents addObject: [fTableView itemAtRow: i]]; - } - else - { - NSAssert([NSApp isOnLionOrBetter], @"Dragging using Lion functionality on pre-Lion"); - - movingTorrents = [NSMutableArray arrayWithCapacity: info.numberOfValidItemsForDrop]; - [info enumerateDraggingItemsWithOptions: 0 forView: outlineView classes: [NSArray arrayWithObject: [NSPasteboardItem class]] searchOptions: nil usingBlock: ^(NSDraggingItem * draggingItem, NSInteger index, BOOL * stop) { - NSNumber * rowNumber = [NSKeyedUnarchiver unarchiveObjectWithData: [draggingItem.item dataForType: NSPasteboardTypeString]]; - [movingTorrents addObject: [fTableView itemAtRow: [rowNumber integerValue]]]; - }]; - } + //get the torrents to move + NSMutableArray * movingTorrents = [NSMutableArray arrayWithCapacity: [indexes count]]; + for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i]) + [movingTorrents addObject: [fTableView itemAtRow: i]]; //reset groups if (item)