fix error where the table would lose track of the selected torrent when sorting by activity
This commit is contained in:
parent
5e12a8b90d
commit
bf146526bf
|
@ -1600,26 +1600,11 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
|
|||
|
||||
- (void) sortTorrents
|
||||
{
|
||||
//remember selected rows if needed
|
||||
NSArray * selectedTorrents = nil;
|
||||
int numSelected = [fTableView numberOfSelectedRows];
|
||||
if (numSelected > 0 && numSelected < [fDisplayedTorrents count])
|
||||
selectedTorrents = [fDisplayedTorrents objectsAtIndexes: [fTableView selectedRowIndexes]];
|
||||
NSArray * selectedTorrents = [fDisplayedTorrents objectsAtIndexes: [fTableView selectedRowIndexes]];
|
||||
|
||||
[self sortTorrentsIgnoreSelected]; //actually sort
|
||||
|
||||
//set selected rows if needed
|
||||
if (selectedTorrents)
|
||||
{
|
||||
Torrent * torrent;
|
||||
NSEnumerator * enumerator = [selectedTorrents objectEnumerator];
|
||||
NSMutableIndexSet * indexSet = [[NSMutableIndexSet alloc] init];
|
||||
while ((torrent = [enumerator nextObject]))
|
||||
[indexSet addIndex: [fDisplayedTorrents indexOfObject: torrent]];
|
||||
|
||||
[fTableView selectRowIndexes: indexSet byExtendingSelection: NO];
|
||||
[indexSet release];
|
||||
}
|
||||
[fTableView selectTorrents: selectedTorrents];
|
||||
}
|
||||
|
||||
//doesn't remember selected rows
|
||||
|
@ -1759,9 +1744,7 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
|
|||
{
|
||||
NSMutableArray * previousTorrents = [fDisplayedTorrents mutableCopy];
|
||||
|
||||
//remember selected rows if needed
|
||||
NSArray * selectedTorrents = [fTableView numberOfSelectedRows] > 0
|
||||
? [fDisplayedTorrents objectsAtIndexes: [fTableView selectedRowIndexes]] : nil;
|
||||
NSArray * selectedTorrents = [fDisplayedTorrents objectsAtIndexes: [fTableView selectedRowIndexes]];
|
||||
|
||||
int active = 0, downloading = 0, seeding = 0, paused = 0;
|
||||
NSString * filterType = [fDefaults stringForKey: @"Filter"];
|
||||
|
@ -1886,19 +1869,8 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
|
|||
|
||||
[self sortTorrentsIgnoreSelected];
|
||||
|
||||
//set selected rows if needed
|
||||
if (selectedTorrents)
|
||||
{
|
||||
NSEnumerator * enumerator = [selectedTorrents objectEnumerator];
|
||||
Torrent * torrent;
|
||||
NSMutableIndexSet * selectedIndexes = [NSMutableIndexSet indexSet];
|
||||
unsigned index;
|
||||
while ((torrent = [enumerator nextObject]))
|
||||
if ((index = [fDisplayedTorrents indexOfObject: torrent]) != NSNotFound)
|
||||
[selectedIndexes addIndex: index];
|
||||
|
||||
[fTableView selectRowIndexes: selectedIndexes byExtendingSelection: NO];
|
||||
}
|
||||
//set selected rows
|
||||
[fTableView selectTorrents: selectedTorrents];
|
||||
|
||||
//set status bar torrent count text
|
||||
NSString * totalTorrentsString;
|
||||
|
@ -2434,10 +2406,7 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
|
|||
if ([[pasteboard types] containsObject: TORRENT_TABLE_VIEW_DATA_TYPE])
|
||||
{
|
||||
//remember selected rows if needed
|
||||
NSArray * selectedTorrents = nil;
|
||||
int numSelected = [fTableView numberOfSelectedRows];
|
||||
if (numSelected > 0 && numSelected < [fDisplayedTorrents count])
|
||||
selectedTorrents = [fDisplayedTorrents objectsAtIndexes: [fTableView selectedRowIndexes]];
|
||||
NSArray * selectedTorrents = [fDisplayedTorrents objectsAtIndexes: [fTableView selectedRowIndexes]];
|
||||
|
||||
NSIndexSet * indexes = [NSKeyedUnarchiver unarchiveObjectWithData:
|
||||
[pasteboard dataForType: TORRENT_TABLE_VIEW_DATA_TYPE]];
|
||||
|
@ -2476,18 +2445,8 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
|
|||
|
||||
[self applyFilter: nil];
|
||||
|
||||
//set selected rows if needed
|
||||
if (selectedTorrents)
|
||||
{
|
||||
Torrent * torrent;
|
||||
NSEnumerator * enumerator = [selectedTorrents objectEnumerator];
|
||||
NSMutableIndexSet * indexSet = [[NSMutableIndexSet alloc] init];
|
||||
while ((torrent = [enumerator nextObject]))
|
||||
[indexSet addIndex: [fDisplayedTorrents indexOfObject: torrent]];
|
||||
|
||||
[fTableView selectRowIndexes: indexSet byExtendingSelection: NO];
|
||||
[indexSet release];
|
||||
}
|
||||
//set selected rows
|
||||
[fTableView selectTorrents: selectedTorrents];
|
||||
}
|
||||
|
||||
return YES;
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
IBOutlet NSMenu * fContextRow, * fContextNoRow;
|
||||
|
||||
int fMouseControlRow, fMouseRevealRow, fMouseActionRow, fMouseActionIconRow, fActionPushedRow;
|
||||
NSIndexSet * fSelectedIndexes;
|
||||
NSArray * fSelectedTorrents;
|
||||
|
||||
NSMutableArray * fKeyStrokes;
|
||||
|
||||
|
@ -57,6 +57,8 @@
|
|||
- (void) setActionButtonHover: (int) row;
|
||||
- (void) setActionIconButtonHover: (int) row;
|
||||
|
||||
- (void) selectTorrents: (NSArray *) torrents;
|
||||
|
||||
- (void) toggleControlForTorrent: (Torrent *) torrent;
|
||||
|
||||
- (void) displayTorrentMenuForEvent: (NSEvent *) event;
|
||||
|
|
|
@ -77,7 +77,7 @@
|
|||
{
|
||||
[fPiecesBarTimer invalidate];
|
||||
|
||||
[fSelectedIndexes release];
|
||||
[fSelectedTorrents release];
|
||||
|
||||
[fKeyStrokes release];
|
||||
[fMenuTorrent release];
|
||||
|
@ -221,8 +221,8 @@
|
|||
|
||||
- (void) tableViewSelectionIsChanging: (NSNotification *) notification
|
||||
{
|
||||
if (fSelectedIndexes)
|
||||
[self selectRowIndexes: fSelectedIndexes byExtendingSelection: NO];
|
||||
if (fSelectedTorrents)
|
||||
[self selectTorrents: fSelectedTorrents];
|
||||
}
|
||||
|
||||
- (void) mouseDown: (NSEvent *) event
|
||||
|
@ -232,12 +232,12 @@
|
|||
//if pushing a button, don't change the selected rows
|
||||
if ([NSApp isOnLeopardOrBetter] && ([self pointInControlRect: point] || [self pointInRevealRect: point]
|
||||
|| [self pointInActionRect: point]))
|
||||
fSelectedIndexes = [[self selectedRowIndexes] retain];
|
||||
fSelectedTorrents = [[fTorrents objectsAtIndexes: [self selectedRowIndexes]] retain];
|
||||
|
||||
[super mouseDown: event];
|
||||
|
||||
[fSelectedIndexes release];
|
||||
fSelectedIndexes = nil;
|
||||
[fSelectedTorrents release];
|
||||
fSelectedTorrents = nil;
|
||||
|
||||
//avoid weird behavior when showing menu by doing this after mouse down
|
||||
if ([self pointInActionRect: point])
|
||||
|
@ -271,6 +271,18 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (void) selectTorrents: (NSArray *) torrents
|
||||
{
|
||||
Torrent * torrent;
|
||||
NSEnumerator * enumerator = [torrents objectEnumerator];
|
||||
NSMutableIndexSet * indexSet = [[NSMutableIndexSet alloc] init];
|
||||
while ((torrent = [enumerator nextObject]))
|
||||
[indexSet addIndex: [fTorrents indexOfObject: torrent]];
|
||||
|
||||
[self selectRowIndexes: indexSet byExtendingSelection: NO];
|
||||
[indexSet release];
|
||||
}
|
||||
|
||||
- (NSMenu *) menuForEvent: (NSEvent *) event
|
||||
{
|
||||
int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
|
||||
|
|
Loading…
Reference in New Issue