From: Mike Gelfand Date: Thu, 3 Mar 2016 17:57:08 +0000 (+0000) Subject: #6078: Show main window and scroll to torrent on notification click X-Git-Tag: 2.91~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=375571c9b42229f213bdbbde9f71b1974c3cd8c7;p=transmission #6078: Show main window and scroll to torrent on notification click --- diff --git a/macosx/Controller.m b/macosx/Controller.m index a7d53286e..597185396 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -1991,8 +1991,9 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy } NSAssert1(row != -1, @"expected a row to be found for torrent %@", torrent); - [fTableView selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection:NO]; - #warning focus the window + + [self showMainWindow: nil]; + [fTableView selectAndScrollToRow: row]; } } } diff --git a/macosx/TorrentTableView.h b/macosx/TorrentTableView.h index 7f4728d30..112f1480d 100644 --- a/macosx/TorrentTableView.h +++ b/macosx/TorrentTableView.h @@ -91,4 +91,6 @@ - (void) togglePiecesBar; - (CGFloat) piecesBarPercent; +- (void) selectAndScrollToRow: (NSInteger) row; + @end diff --git a/macosx/TorrentTableView.m b/macosx/TorrentTableView.m index e47b34283..8ee36d44d 100644 --- a/macosx/TorrentTableView.m +++ b/macosx/TorrentTableView.m @@ -842,6 +842,24 @@ return fPiecesBarPercent; } +- (void) selectAndScrollToRow: (NSInteger) row +{ + NSParameterAssert(row >= 0); + NSParameterAssert(row < [self numberOfRows]); + + [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO]; + + const NSRect rowRect = [self rectOfRow: row]; + const NSRect viewRect = [[self superview] frame]; + + NSPoint scrollOrigin = rowRect.origin; + scrollOrigin.y += (rowRect.size.height - viewRect.size.height) / 2; + if (scrollOrigin.y < 0) + scrollOrigin.y = 0; + + [[[self superview] animator] setBoundsOrigin: scrollOrigin]; +} + @end @implementation TorrentTableView (Private)