Skip to content

Commit

Permalink
fix: selected torrents when moving rows (transmission#5991)
Browse files Browse the repository at this point in the history
* Fix selected torrents when moving rows

* code review: keep selected torrents when toggling group presentation
  • Loading branch information
Coeur authored Sep 11, 2023
1 parent d566695 commit 92c8c41
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
5 changes: 5 additions & 0 deletions macosx/Controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3237,6 +3237,9 @@ - (void)applyFilter
//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];

Expand Down Expand Up @@ -3280,6 +3283,8 @@ - (void)applyFilter
for (TorrentGroup* group in self.fDisplayedTorrents)
[self.fTableView expandItem:group];
}

self.fTableView.selectedTorrents = selectedTorrents;
}

//sort the torrents (won't sort the groups, though)
Expand Down
4 changes: 1 addition & 3 deletions macosx/TorrentTableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
20 changes: 12 additions & 8 deletions macosx/TorrentTableView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ - (void)awakeFromNib
//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
Expand Down Expand Up @@ -185,8 +186,6 @@ - (void)reloadDataForRowIndexes:(NSIndexSet*)rowIndexes columnIndexes:(NSIndexSe
}
}
}];

[self restoreSelectionIndexes];
}

- (BOOL)isGroupCollapsed:(NSInteger)value
Expand Down Expand Up @@ -559,6 +558,16 @@ - (void)mouseDown:(NSEvent*)event
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]];
Expand All @@ -577,11 +586,6 @@ - (NSMenu*)menuForEvent:(NSEvent*)event
}
}

- (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
{
Expand Down

0 comments on commit 92c8c41

Please sign in to comment.