From 19336396f3bbdc9d3fcded3689b97c403ae1f726 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Thu, 13 Jul 2006 00:32:00 +0000 Subject: [PATCH] remember selected rows correctly when filtering --- macosx/Controller.m | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/macosx/Controller.m b/macosx/Controller.m index 032b17f9d..9bdd7e9ad 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -956,6 +956,12 @@ static void sleepCallBack(void * controller, io_service_t y, - (void) applyFilter { + //remember selected rows if needed + NSArray * selectedTorrents = nil; + int numSelected = [fTableView numberOfSelectedRows]; + if (numSelected > 0 && numSelected < [fFilteredTorrents count]) + selectedTorrents = [self torrentsAtIndexes: [fTableView selectedRowIndexes]]; + NSMutableArray * tempTorrents = [[NSMutableArray alloc] initWithCapacity: [fTorrents count]]; if ([fFilterType isEqualToString: @"Pause"]) @@ -989,6 +995,21 @@ static void sleepCallBack(void * controller, io_service_t y, [tempTorrents release]; [self sortTorrents]; + + //set selected rows if needed...this selecting is more accurate than sort's + if (selectedTorrents) + { + Torrent * torrent; + NSEnumerator * enumerator = [selectedTorrents objectEnumerator]; + NSMutableIndexSet * indexSet = [[NSMutableIndexSet alloc] init]; + unsigned index; + while ((torrent = [enumerator nextObject])) + if ((index = [fFilteredTorrents indexOfObject: torrent]) != NSNotFound) + [indexSet addIndex: index]; + + [fTableView selectRowIndexes: indexSet byExtendingSelection: NO]; + [indexSet release]; + } } //resets filter and sorts torrents