From cfb91f22e4aa2aae1450f8c17c16e4838b1d55ff Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Sun, 11 May 2008 21:38:40 +0000 Subject: [PATCH] allow reordering while groups are shown (and sorting by queue) --- macosx/Controller.m | 95 +++++++++++++++++++++++++++------------ macosx/TorrentTableView.m | 19 ++++++-- 2 files changed, 83 insertions(+), 31 deletions(-) diff --git a/macosx/Controller.m b/macosx/Controller.m index 01218dc56..df5cc1a4a 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -1712,11 +1712,6 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi case SORT_ORDER_TAG: sortType = SORT_ORDER; [fDefaults setBool: NO forKey: @"SortReverse"]; - - [fDefaults setBool: NO forKey: @"SortByGroup"]; - [fTableView removeAllCollapsedGroups]; - - [self applyFilter: nil]; //ensure groups are removed break; case SORT_DATE_TAG: sortType = SORT_DATE; @@ -2525,6 +2520,7 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi - (BOOL) outlineView: (NSOutlineView *) outlineView isItemExpandable: (id) item { + return ![item isKindOfClass: [Torrent class]]; } @@ -2588,14 +2584,18 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi //only allow reordering of rows if sorting by order if ([[fDefaults stringForKey: @"Sort"] isEqualToString: SORT_ORDER]) { - [pasteboard declareTypes: [NSArray arrayWithObject: TORRENT_TABLE_VIEW_DATA_TYPE] owner: self]; - NSMutableIndexSet * indexSet = [NSMutableIndexSet indexSet]; NSEnumerator * enumerator = [items objectEnumerator]; - Torrent * torrent; + id torrent; while ((torrent = [enumerator nextObject])) + { + if (![torrent isKindOfClass: [Torrent class]]) + return NO; + [indexSet addIndex: [fTableView rowForItem: torrent]]; + } + [pasteboard declareTypes: [NSArray arrayWithObject: TORRENT_TABLE_VIEW_DATA_TYPE] owner: self]; [pasteboard setData: [NSKeyedArchiver archivedDataWithRootObject: indexSet] forType: TORRENT_TABLE_VIEW_DATA_TYPE]; return YES; } @@ -2608,10 +2608,28 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi NSPasteboard * pasteboard = [info draggingPasteboard]; if ([[pasteboard types] containsObject: TORRENT_TABLE_VIEW_DATA_TYPE]) { - if (item) - index = [fTableView rowForItem: item] + 1; + if ([fDefaults boolForKey: @"SortByGroup"]) + { + if (!item) + return NSDragOperationNone; + else if ([item isKindOfClass: [Torrent class]]) + { + NSDictionary * group = [fTableView parentForItem: item]; + index = [[group objectForKey: @"Torrents"] indexOfObject: item] + 1; + item = group; + } + else; + } + else + { + if (item) + { + index = [fTableView rowForItem: item] + 1; + item = nil; + } + } - [fTableView setDropItem: nil dropChildIndex: index]; + [fTableView setDropItem: item dropChildIndex: index]; return NSDragOperationGeneric; } @@ -2627,37 +2645,58 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi //remember selected rows NSArray * selectedValues = [fTableView selectedValues]; - NSIndexSet * indexes = [NSKeyedUnarchiver unarchiveObjectWithData: - [pasteboard dataForType: TORRENT_TABLE_VIEW_DATA_TYPE]]; + NSIndexSet * indexes = [NSKeyedUnarchiver unarchiveObjectWithData: [pasteboard dataForType: TORRENT_TABLE_VIEW_DATA_TYPE]]; - //determine where to move them - int i, originalRow = newRow; - for (i = [indexes firstIndex]; i < originalRow && i != NSNotFound; i = [indexes indexGreaterThanIndex: i]) - newRow--; + //get the torrents to move + NSMutableArray * movingTorrents = [NSMutableArray arrayWithCapacity: [indexes count]]; + int i; + for (i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i]) + [movingTorrents addObject: [fTableView itemAtRow: i]]; - //reinsert into array - int insertIndex = newRow > 0 ? [[fDisplayedTorrents objectAtIndex: newRow-1] orderValue] + 1 : 0; + //find torrent to place under + Torrent * topTorrent = nil; + if (item) //sorting by group + { + #warning get working + //change groups + /*int groupValue = [[item objectForKey: @"Group"] intValue]; + NSEnumerator * enumerator = [movingTorrents objectEnumerator]; + Torrent * torrent; + while ((torrent = [enumerator nextObject])) + [torrent setGroupValue: groupValue];*/ + + + NSArray * groupTorrents = [item objectForKey: @"Torrents"]; + while (newRow > 0 && [movingTorrents containsObject: [groupTorrents objectAtIndex: newRow-1]]) + newRow--; + + if (newRow > 0) + topTorrent = [groupTorrents objectAtIndex: newRow-1]; + } + else + { + while (newRow > 0 && [movingTorrents containsObject: [fDisplayedTorrents objectAtIndex: newRow-1]]) + newRow--; + + if (newRow > 0) + topTorrent = [fDisplayedTorrents objectAtIndex: newRow-1]; + } //get all torrents to reorder - NSSortDescriptor * orderDescriptor = [[[NSSortDescriptor alloc] initWithKey: - @"orderValue" ascending: YES] autorelease]; - + NSSortDescriptor * orderDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"orderValue" ascending: YES] autorelease]; NSMutableArray * sortedTorrents = [[fTorrents sortedArrayUsingDescriptors: [NSArray arrayWithObject: orderDescriptor]] mutableCopy]; //remove objects to reinsert - NSArray * movingTorrents = [[fDisplayedTorrents objectsAtIndexes: indexes] retain]; [sortedTorrents removeObjectsInArray: movingTorrents]; //insert objects at new location + int insertIndex = topTorrent ? [sortedTorrents indexOfObject: topTorrent] + 1 : 0; for (i = 0; i < [movingTorrents count]; i++) [sortedTorrents insertObject: [movingTorrents objectAtIndex: i] atIndex: insertIndex + i]; - [movingTorrents release]; - //redo order values - i = 0; - for (i = 0; i < [sortedTorrents count]; i++) + for (i = insertIndex; i < [sortedTorrents count]; i++) [[sortedTorrents objectAtIndex: i] setOrderValue: i]; [sortedTorrents release]; @@ -3690,7 +3729,7 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi if (action == @selector(setSortByGroup:)) { [menuItem setState: [fDefaults boolForKey: @"SortByGroup"] ? NSOnState : NSOffState]; - return ![[fDefaults stringForKey: @"Sort"] isEqualToString: SORT_ORDER]; + return YES; } //check proper filter search item diff --git a/macosx/TorrentTableView.m b/macosx/TorrentTableView.m index 97f5d6226..0852c2b4f 100644 --- a/macosx/TorrentTableView.m +++ b/macosx/TorrentTableView.m @@ -139,6 +139,11 @@ [fCollapsedGroups removeIndex: value]; } +- (BOOL)shouldCollapseAutoExpandedItemsForDeposited:(BOOL)deposited +{ + return NO; +} + - (void) removeAllCollapsedGroups { [fCollapsedGroups removeAllIndexes]; @@ -355,15 +360,23 @@ - (void) outlineViewItemDidExpand: (NSNotification *) notification { int value = [[[[notification userInfo] objectForKey: @"NSObject"] objectForKey: @"Group"] intValue]; - [fCollapsedGroups removeIndex: value >= 0 ? value : MAX_GROUP]; + if (value < 0) + value = MAX_GROUP; - [[NSNotificationCenter defaultCenter] postNotificationName: @"OutlineExpandCollapse" object: self]; + if ([fCollapsedGroups containsIndex: value]) + { + [fCollapsedGroups removeIndex: value]; + [[NSNotificationCenter defaultCenter] postNotificationName: @"OutlineExpandCollapse" object: self]; + } } - (void) outlineViewItemDidCollapse: (NSNotification *) notification { int value = [[[[notification userInfo] objectForKey: @"NSObject"] objectForKey: @"Group"] intValue]; - [fCollapsedGroups addIndex: value >= 0 ? value : MAX_GROUP]; + if (value < 0) + value = MAX_GROUP; + + [fCollapsedGroups addIndex: value]; [[NSNotificationCenter defaultCenter] postNotificationName: @"OutlineExpandCollapse" object: self]; } -- 2.40.0