1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-23 00:04:06 +00:00

fix: selected torrents when moving rows (#5991)

* Fix selected torrents when moving rows

* code review: keep selected torrents when toggling group presentation
This commit is contained in:
Cœur 2023-09-11 04:39:01 +02:00 committed by GitHub
parent d566695b33
commit 92c8c41c0b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 11 deletions

View file

@ -3237,6 +3237,9 @@ void onTorrentCompletenessChanged(tr_torrent* tor, tr_completeness status, bool
//set all groups as expanded
[self.fTableView removeAllCollapsedGroups];
// we need to remember selected values
NSArray<Torrent*>* selectedTorrents = self.fTableView.selectedTorrents;
beganUpdates = YES;
[self.fTableView beginUpdates];
@ -3280,6 +3283,8 @@ void onTorrentCompletenessChanged(tr_torrent* tor, tr_completeness status, bool
for (TorrentGroup* group in self.fDisplayedTorrents)
[self.fTableView expandItem:group];
}
self.fTableView.selectedTorrents = selectedTorrents;
}
//sort the torrents (won't sort the groups, though)

View file

@ -17,9 +17,7 @@ extern const CGFloat kGroupSeparatorHeight;
- (void)removeAllCollapsedGroups;
- (void)saveCollapsedGroups;
- (void)restoreSelectionIndexes;
@property(nonatomic, readonly) NSArray<Torrent*>* selectedTorrents;
@property(nonatomic) NSArray<Torrent*>* selectedTorrents;
- (NSRect)iconRectForRow:(NSInteger)row;

View file

@ -125,8 +125,9 @@ static NSTimeInterval const kToggleProgressSeconds = 0.175;
//make sure we don't lose selection on manual reloads
- (void)reloadData
{
NSArray<Torrent*>* selectedTorrents = self.selectedTorrents;
[super reloadData];
[self restoreSelectionIndexes];
self.selectedTorrents = selectedTorrents;
}
- (void)reloadVisibleRows
@ -185,8 +186,6 @@ static NSTimeInterval const kToggleProgressSeconds = 0.175;
}
}
}];
[self restoreSelectionIndexes];
}
- (BOOL)isGroupCollapsed:(NSInteger)value
@ -559,6 +558,16 @@ static NSTimeInterval const kToggleProgressSeconds = 0.175;
return torrents;
}
- (void)setSelectedTorrents:(NSArray<Torrent*>*)selectedTorrents
{
NSMutableIndexSet* selectedIndexes = [NSMutableIndexSet new];
for (Torrent* i in selectedTorrents)
{
[selectedIndexes addIndex:[self rowForItem:i]];
}
[self selectRowIndexes:selectedIndexes byExtendingSelection:NO];
}
- (NSMenu*)menuForEvent:(NSEvent*)event
{
NSInteger row = [self rowAtPoint:[self convertPoint:event.locationInWindow fromView:nil]];
@ -577,11 +586,6 @@ static NSTimeInterval const kToggleProgressSeconds = 0.175;
}
}
- (void)restoreSelectionIndexes
{
[self selectRowIndexes:self.fSelectedRowIndexes byExtendingSelection:NO];
}
//make sure that the pause buttons become orange when holding down the option key
- (void)flagsChanged:(NSEvent*)event
{