2007-09-16 01:02:06 +00:00
|
|
|
/******************************************************************************
|
2019-01-11 18:36:19 +00:00
|
|
|
* Copyright (c) 2005-2019 Transmission authors and contributors
|
2007-09-16 01:02:06 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#import "TorrentTableView.h"
|
2009-10-11 02:22:38 +00:00
|
|
|
#import "Controller.h"
|
2008-05-22 20:00:22 +00:00
|
|
|
#import "FileListNode.h"
|
2011-07-21 02:35:03 +00:00
|
|
|
#import "InfoOptionsViewController.h"
|
2009-08-30 18:38:56 +00:00
|
|
|
#import "NSApplicationAdditions.h"
|
2010-11-21 14:45:06 +00:00
|
|
|
#import "NSStringAdditions.h"
|
2009-10-11 02:22:38 +00:00
|
|
|
#import "Torrent.h"
|
|
|
|
#import "TorrentCell.h"
|
|
|
|
#import "TorrentGroup.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-10-29 02:33:20 +00:00
|
|
|
#define MAX_GROUP 999999
|
2008-02-07 16:20:24 +00:00
|
|
|
|
2011-10-06 00:30:40 +00:00
|
|
|
//eliminate when Lion-only
|
2007-09-16 01:02:06 +00:00
|
|
|
#define ACTION_MENU_GLOBAL_TAG 101
|
|
|
|
#define ACTION_MENU_UNLIMITED_TAG 102
|
|
|
|
#define ACTION_MENU_LIMIT_TAG 103
|
|
|
|
|
2009-04-20 03:36:35 +00:00
|
|
|
#define ACTION_MENU_PRIORITY_HIGH_TAG 101
|
|
|
|
#define ACTION_MENU_PRIORITY_NORMAL_TAG 102
|
|
|
|
#define ACTION_MENU_PRIORITY_LOW_TAG 103
|
|
|
|
|
2008-06-18 16:25:30 +00:00
|
|
|
#define TOGGLE_PROGRESS_SECONDS 0.175
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@interface TorrentTableView (Private)
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)pointInGroupStatusRect:(NSPoint)point;
|
2008-02-28 02:17:17 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setGroupStatusColumns;
|
2008-02-28 16:40:14 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TorrentTableView
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (instancetype)initWithCoder:(NSCoder*)decoder
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ((self = [super initWithCoder:decoder]))
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
fDefaults = NSUserDefaults.standardUserDefaults;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-02-19 15:57:27 +00:00
|
|
|
fTorrentCell = [[TorrentCell alloc] init];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSData* groupData = [fDefaults dataForKey:@"CollapsedGroups"];
|
2008-02-07 21:26:04 +00:00
|
|
|
if (groupData)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
fCollapsedGroups = [[NSUnarchiver unarchiveObjectWithData:groupData] mutableCopy];
|
|
|
|
}
|
2008-02-07 21:26:04 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-02-07 21:26:04 +00:00
|
|
|
fCollapsedGroups = [[NSMutableIndexSet alloc] init];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-20 03:27:17 +00:00
|
|
|
fMouseRow = -1;
|
2008-01-15 04:45:57 +00:00
|
|
|
fMouseControlRow = -1;
|
|
|
|
fMouseRevealRow = -1;
|
2008-01-15 23:48:03 +00:00
|
|
|
fMouseActionRow = -1;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-07-27 03:38:01 +00:00
|
|
|
fActionPopoverShown = NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
self.delegate = self;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
fPiecesBarPercent = [fDefaults boolForKey:@"PiecesBar"] ? 1.0 : 0.0;
|
|
|
|
|
|
|
|
if (@available(macOS 11.0, *))
|
|
|
|
{
|
2020-11-18 03:07:45 +00:00
|
|
|
self.style = NSTableViewStyleFullWidth;
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)dealloc
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter removeObserver:self];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)awakeFromNib
|
2008-03-17 21:44:14 +00:00
|
|
|
{
|
|
|
|
//set group columns to show ratio, needs to be in awakeFromNib to size columns correctly
|
|
|
|
[self setGroupStatusColumns];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(setNeedsDisplay) name:@"RefreshTorrentTable" object:nil];
|
2008-03-17 21:44:14 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)isGroupCollapsed:(NSInteger)value
|
2008-02-07 01:26:12 +00:00
|
|
|
{
|
2008-06-11 03:28:14 +00:00
|
|
|
if (value == -1)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-02-07 16:20:24 +00:00
|
|
|
value = MAX_GROUP;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
return [fCollapsedGroups containsIndex:value];
|
2008-02-07 01:26:12 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)removeCollapsedGroup:(NSInteger)value
|
2008-02-07 02:11:26 +00:00
|
|
|
{
|
2008-06-11 03:28:14 +00:00
|
|
|
if (value == -1)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-02-07 16:20:24 +00:00
|
|
|
value = MAX_GROUP;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[fCollapsedGroups removeIndex:value];
|
2008-02-07 02:11:26 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)removeAllCollapsedGroups
|
2008-02-07 02:15:24 +00:00
|
|
|
{
|
|
|
|
[fCollapsedGroups removeAllIndexes];
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)saveCollapsedGroups
|
2008-02-07 21:26:04 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[fDefaults setObject:[NSArchiver archivedDataWithRootObject:fCollapsedGroups] forKey:@"CollapsedGroups"];
|
2008-02-07 21:26:04 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)outlineView:(NSOutlineView*)outlineView isGroupItem:(id)item
|
2008-01-23 02:51:58 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
return ![item isKindOfClass:[Torrent class]];
|
2008-01-23 02:51:58 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (CGFloat)outlineView:(NSOutlineView*)outlineView heightOfRowByItem:(id)item
|
2008-01-23 02:51:58 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
return [item isKindOfClass:[Torrent class]] ? self.rowHeight : GROUP_SEPARATOR_HEIGHT;
|
2008-01-23 02:51:58 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSCell*)outlineView:(NSOutlineView*)outlineView dataCellForTableColumn:(NSTableColumn*)tableColumn item:(id)item
|
2008-01-23 02:51:58 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const group = ![item isKindOfClass:[Torrent class]];
|
2008-02-18 20:53:10 +00:00
|
|
|
if (!tableColumn)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-02-18 20:53:10 +00:00
|
|
|
return !group ? fTorrentCell : nil;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-02-18 20:53:10 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
return group ? [tableColumn dataCellForRow:[self rowForItem:item]] : nil;
|
|
|
|
}
|
2008-01-23 02:51:58 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)outlineView:(NSOutlineView*)outlineView
|
|
|
|
willDisplayCell:(id)cell
|
|
|
|
forTableColumn:(NSTableColumn*)tableColumn
|
|
|
|
item:(id)item
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([item isKindOfClass:[Torrent class]])
|
2008-02-18 20:53:10 +00:00
|
|
|
{
|
2011-07-21 02:35:03 +00:00
|
|
|
if (!tableColumn)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
TorrentCell* torrentCell = cell;
|
2021-08-07 07:27:56 +00:00
|
|
|
torrentCell.representedObject = item;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger const row = [self rowForItem:item];
|
2021-08-07 07:27:56 +00:00
|
|
|
torrentCell.hover = (row == fMouseRow);
|
|
|
|
torrentCell.controlHover = (row == fMouseControlRow);
|
|
|
|
torrentCell.revealHover = (row == fMouseRevealRow);
|
|
|
|
torrentCell.actionHover = (row == fMouseActionRow);
|
2011-07-21 02:35:03 +00:00
|
|
|
}
|
2008-02-18 20:53:10 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSRect)frameOfCellAtColumn:(NSInteger)column row:(NSInteger)row
|
2007-10-27 14:57:46 +00:00
|
|
|
{
|
2008-12-26 05:57:51 +00:00
|
|
|
if (column == -1)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
return [self rectOfRow:row];
|
|
|
|
}
|
2008-02-18 19:42:46 +00:00
|
|
|
else
|
2008-02-19 02:10:20 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSRect rect = [super frameOfCellAtColumn:column row:row];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-02-19 02:10:20 +00:00
|
|
|
//adjust placement for proper vertical alignment
|
2021-08-15 09:41:48 +00:00
|
|
|
if (column == [self columnWithIdentifier:@"Group"])
|
|
|
|
{
|
2008-10-29 01:18:03 +00:00
|
|
|
rect.size.height -= 1.0f;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-02-19 02:10:20 +00:00
|
|
|
return rect;
|
|
|
|
}
|
2007-10-27 14:57:46 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)outlineView:(NSOutlineView*)outlineView typeSelectStringForTableColumn:(NSTableColumn*)tableColumn item:(id)item
|
2008-01-23 21:33:54 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([item isKindOfClass:[Torrent class]])
|
|
|
|
{
|
|
|
|
return ((Torrent*)item).name;
|
|
|
|
}
|
2012-11-02 21:46:18 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
return [self.dataSource outlineView:outlineView objectValueForTableColumn:[self tableColumnWithIdentifier:@"Group"]
|
|
|
|
byItem:item];
|
|
|
|
}
|
2008-01-23 21:33:54 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)outlineView:(NSOutlineView*)outlineView
|
|
|
|
toolTipForCell:(NSCell*)cell
|
|
|
|
rect:(NSRectPointer)rect
|
|
|
|
tableColumn:(NSTableColumn*)column
|
|
|
|
item:(id)item
|
|
|
|
mouseLocation:(NSPoint)mouseLocation
|
2008-02-28 21:28:48 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* ident = column.identifier;
|
|
|
|
if ([ident isEqualToString:@"DL"] || [ident isEqualToString:@"DL Image"])
|
|
|
|
{
|
2008-02-28 21:28:48 +00:00
|
|
|
return NSLocalizedString(@"Download speed", "Torrent table -> group row -> tooltip");
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else if ([ident isEqualToString:@"UL"] || [ident isEqualToString:@"UL Image"])
|
|
|
|
{
|
|
|
|
return [fDefaults boolForKey:@"DisplayGroupRowRatio"] ?
|
|
|
|
NSLocalizedString(@"Ratio", "Torrent table -> group row -> tooltip") :
|
|
|
|
NSLocalizedString(@"Upload speed", "Torrent table -> group row -> tooltip");
|
|
|
|
}
|
2008-03-04 00:30:26 +00:00
|
|
|
else if (ident)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSUInteger count = ((TorrentGroup*)item).torrents.count;
|
2008-03-04 00:30:26 +00:00
|
|
|
if (count == 1)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-03-04 00:30:26 +00:00
|
|
|
return NSLocalizedString(@"1 transfer", "Torrent table -> group row -> tooltip");
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-03-04 00:30:26 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
return [NSString stringWithFormat:NSLocalizedString(@"%@ transfers", "Torrent table -> group row -> tooltip"),
|
|
|
|
[NSString formattedUInteger:count]];
|
|
|
|
}
|
2008-03-04 00:30:26 +00:00
|
|
|
}
|
2008-02-28 21:28:48 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-02-28 21:28:48 +00:00
|
|
|
return nil;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-02-28 21:28:48 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateTrackingAreas
|
2008-01-15 03:33:44 +00:00
|
|
|
{
|
|
|
|
[super updateTrackingAreas];
|
2010-03-20 03:27:17 +00:00
|
|
|
[self removeTrackingAreas];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSRange const rows = [self rowsInRect:self.visibleRect];
|
2008-02-06 23:45:44 +00:00
|
|
|
if (rows.length == 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-01-15 03:33:44 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSPoint mouseLocation = [self convertPoint:self.window.mouseLocationOutsideOfEventStream fromView:nil];
|
2008-10-12 22:17:27 +00:00
|
|
|
for (NSUInteger row = rows.location; row < NSMaxRange(rows); row++)
|
2008-01-15 03:33:44 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if (![[self itemAtRow:row] isKindOfClass:[Torrent class]])
|
|
|
|
{
|
2008-02-06 23:45:44 +00:00
|
|
|
continue;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSDictionary* userInfo = @{ @"Row" : @(row) };
|
|
|
|
TorrentCell* cell = (TorrentCell*)[self preparedCellAtColumn:-1 row:row];
|
|
|
|
[cell addTrackingAreasForView:self inRect:[self rectOfRow:row] withUserInfo:userInfo mouseLocation:mouseLocation];
|
2008-01-15 03:33:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)removeTrackingAreas
|
2008-01-15 16:19:16 +00:00
|
|
|
{
|
2010-03-20 03:27:17 +00:00
|
|
|
fMouseRow = -1;
|
2008-01-15 16:19:16 +00:00
|
|
|
fMouseControlRow = -1;
|
|
|
|
fMouseRevealRow = -1;
|
2008-01-15 23:48:03 +00:00
|
|
|
fMouseActionRow = -1;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSTrackingArea* area in self.trackingAreas)
|
2008-01-15 16:19:16 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (area.owner == self && area.userInfo[@"Row"])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self removeTrackingArea:area];
|
|
|
|
}
|
2008-01-15 16:19:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setRowHover:(NSInteger)row
|
2010-03-20 03:27:17 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAssert([fDefaults boolForKey:@"SmallView"], @"cannot set a hover row when not in compact view");
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-20 03:27:17 +00:00
|
|
|
fMouseRow = row;
|
2010-03-20 18:27:09 +00:00
|
|
|
if (row >= 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self setNeedsDisplayInRect:[self rectOfRow:row]];
|
|
|
|
}
|
2010-03-20 03:27:17 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setControlButtonHover:(NSInteger)row
|
2008-01-15 19:48:19 +00:00
|
|
|
{
|
|
|
|
fMouseControlRow = row;
|
|
|
|
if (row >= 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self setNeedsDisplayInRect:[self rectOfRow:row]];
|
|
|
|
}
|
2008-01-15 19:48:19 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setRevealButtonHover:(NSInteger)row
|
2008-01-15 19:48:19 +00:00
|
|
|
{
|
|
|
|
fMouseRevealRow = row;
|
|
|
|
if (row >= 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self setNeedsDisplayInRect:[self rectOfRow:row]];
|
|
|
|
}
|
2008-01-15 19:48:19 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setActionButtonHover:(NSInteger)row
|
2008-01-15 23:48:03 +00:00
|
|
|
{
|
|
|
|
fMouseActionRow = row;
|
|
|
|
if (row >= 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self setNeedsDisplayInRect:[self rectOfRow:row]];
|
|
|
|
}
|
2008-01-15 23:48:03 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)mouseEntered:(NSEvent*)event
|
2008-01-15 03:33:44 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSDictionary* dict = (NSDictionary*)event.userData;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSNumber* row;
|
2017-07-08 14:38:47 +00:00
|
|
|
if ((row = dict[@"Row"]))
|
2008-01-15 03:33:44 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSInteger rowVal = row.integerValue;
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* type = dict[@"Type"];
|
|
|
|
if ([type isEqualToString:@"Action"])
|
|
|
|
{
|
2008-01-16 06:48:12 +00:00
|
|
|
fMouseActionRow = rowVal;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else if ([type isEqualToString:@"Control"])
|
|
|
|
{
|
2008-01-15 04:45:57 +00:00
|
|
|
fMouseControlRow = rowVal;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else if ([type isEqualToString:@"Reveal"])
|
|
|
|
{
|
2008-01-16 06:48:12 +00:00
|
|
|
fMouseRevealRow = rowVal;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-20 03:27:17 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
fMouseRow = rowVal;
|
2021-08-15 09:41:48 +00:00
|
|
|
if (![fDefaults boolForKey:@"SmallView"])
|
|
|
|
{
|
2010-03-20 03:27:17 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-20 03:27:17 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self setNeedsDisplayInRect:[self rectOfRow:rowVal]];
|
2008-01-15 03:33:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)mouseExited:(NSEvent*)event
|
2008-01-15 03:33:44 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSDictionary* dict = (NSDictionary*)event.userData;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSNumber* row;
|
2017-07-08 14:38:47 +00:00
|
|
|
if ((row = dict[@"Row"]))
|
2008-01-15 03:33:44 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* type = dict[@"Type"];
|
|
|
|
if ([type isEqualToString:@"Action"])
|
|
|
|
{
|
2008-01-16 06:48:12 +00:00
|
|
|
fMouseActionRow = -1;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else if ([type isEqualToString:@"Control"])
|
|
|
|
{
|
2008-01-16 06:48:12 +00:00
|
|
|
fMouseControlRow = -1;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
else if ([type isEqualToString:@"Reveal"])
|
|
|
|
{
|
2008-01-16 06:48:12 +00:00
|
|
|
fMouseRevealRow = -1;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-20 03:27:17 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
fMouseRow = -1;
|
2021-08-15 09:41:48 +00:00
|
|
|
if (![fDefaults boolForKey:@"SmallView"])
|
|
|
|
{
|
2010-03-20 03:27:17 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-20 03:27:17 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self setNeedsDisplayInRect:[self rectOfRow:row.integerValue]];
|
2008-01-15 03:33:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)outlineViewSelectionIsChanging:(NSNotification*)notification
|
2008-01-15 03:50:00 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
#warning elliminate when view-based?
|
2012-01-15 07:39:24 +00:00
|
|
|
//if pushing a button, don't change the selected rows
|
2008-01-23 02:51:58 +00:00
|
|
|
if (fSelectedValues)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self selectValues:fSelectedValues];
|
|
|
|
}
|
2008-01-15 03:50:00 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)outlineViewItemDidExpand:(NSNotification*)notification
|
2008-02-06 23:45:44 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
TorrentGroup* group = notification.userInfo[@"NSObject"];
|
2021-08-07 07:27:56 +00:00
|
|
|
NSInteger value = group.groupIndex;
|
2008-05-11 21:38:40 +00:00
|
|
|
if (value < 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-05-11 21:38:40 +00:00
|
|
|
value = MAX_GROUP;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([fCollapsedGroups containsIndex:value])
|
2008-05-11 21:38:40 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[fCollapsedGroups removeIndex:value];
|
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"OutlineExpandCollapse" object:self];
|
2008-05-11 21:38:40 +00:00
|
|
|
}
|
2008-02-06 23:45:44 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)outlineViewItemDidCollapse:(NSNotification*)notification
|
2008-02-06 23:45:44 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
TorrentGroup* group = notification.userInfo[@"NSObject"];
|
2021-08-07 07:27:56 +00:00
|
|
|
NSInteger value = group.groupIndex;
|
2008-05-11 21:38:40 +00:00
|
|
|
if (value < 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-05-11 21:38:40 +00:00
|
|
|
value = MAX_GROUP;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[fCollapsedGroups addIndex:value];
|
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"OutlineExpandCollapse" object:self];
|
2008-02-06 23:45:44 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)mouseDown:(NSEvent*)event
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSPoint point = [self convertPoint:event.locationInWindow fromView:nil];
|
|
|
|
NSInteger const row = [self rowAtPoint:point];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-02-28 02:17:17 +00:00
|
|
|
//check to toggle group status before anything else
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([self pointInGroupStatusRect:point])
|
2008-02-28 02:17:17 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[fDefaults setBool:![fDefaults boolForKey:@"DisplayGroupRowRatio"] forKey:@"DisplayGroupRowRatio"];
|
2008-02-28 16:40:14 +00:00
|
|
|
[self setGroupStatusColumns];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-02-28 02:17:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const pushed = row != -1 && (fMouseActionRow == row || fMouseRevealRow == row || fMouseControlRow == row);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-17 04:20:52 +00:00
|
|
|
//if pushing a button, don't change the selected rows
|
2008-01-22 05:33:02 +00:00
|
|
|
if (pushed)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
fSelectedValues = self.selectedValues;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[super mouseDown:event];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-23 02:51:58 +00:00
|
|
|
fSelectedValues = nil;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-17 04:20:52 +00:00
|
|
|
//avoid weird behavior when showing menu by doing this after mouse down
|
2008-12-26 05:57:51 +00:00
|
|
|
if (row != -1 && fMouseActionRow == row)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
#warning maybe make appear on mouse down
|
|
|
|
[self displayTorrentActionPopoverForEvent:event];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2021-08-07 07:27:56 +00:00
|
|
|
else if (!pushed && event.clickCount == 2) //double click
|
2008-02-06 23:45:44 +00:00
|
|
|
{
|
2008-04-08 15:45:01 +00:00
|
|
|
id item = nil;
|
|
|
|
if (row != -1)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
item = [self itemAtRow:row];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
if (!item || [item isKindOfClass:[Torrent class]])
|
|
|
|
{
|
|
|
|
[fController showInfo:nil];
|
|
|
|
}
|
2008-02-06 23:45:44 +00:00
|
|
|
else
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([self isItemExpanded:item])
|
|
|
|
{
|
|
|
|
[self collapseItem:item];
|
|
|
|
}
|
2008-02-06 23:45:44 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self expandItem:item];
|
|
|
|
}
|
2008-02-06 23:45:44 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)selectValues:(NSArray*)values
|
2008-01-20 18:28:28 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableIndexSet* indexSet = [NSMutableIndexSet indexSet];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-12-26 15:11:37 +00:00
|
|
|
for (id item in values)
|
2008-01-20 20:38:51 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([item isKindOfClass:[Torrent class]])
|
2008-02-06 23:45:44 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger const index = [self rowForItem:item];
|
2008-02-06 23:45:44 +00:00
|
|
|
if (index != -1)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[indexSet addIndex:index];
|
|
|
|
}
|
2008-02-06 23:45:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
TorrentGroup* group = (TorrentGroup*)item;
|
|
|
|
NSInteger const groupIndex = group.groupIndex;
|
2021-08-07 07:27:56 +00:00
|
|
|
for (NSInteger i = 0; i < self.numberOfRows; i++)
|
2008-02-06 23:45:44 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
id tableItem = [self itemAtRow:i];
|
|
|
|
if ([tableItem isKindOfClass:[TorrentGroup class]] && groupIndex == ((TorrentGroup*)tableItem).groupIndex)
|
2008-02-07 01:26:12 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[indexSet addIndex:i];
|
2008-02-07 01:26:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-02-06 23:45:44 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-20 20:38:51 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self selectRowIndexes:indexSet byExtendingSelection:NO];
|
2008-01-20 18:28:28 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSArray*)selectedValues
|
2008-01-23 02:51:58 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSIndexSet* selectedIndexes = self.selectedRowIndexes;
|
|
|
|
NSMutableArray* values = [NSMutableArray arrayWithCapacity:selectedIndexes.count];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSUInteger i = selectedIndexes.firstIndex; i != NSNotFound; i = [selectedIndexes indexGreaterThanIndex:i])
|
|
|
|
{
|
|
|
|
[values addObject:[self itemAtRow:i]];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-02-06 23:45:44 +00:00
|
|
|
return values;
|
2008-01-23 02:51:58 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSArray*)selectedTorrents
|
2008-01-22 23:48:14 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSIndexSet* selectedIndexes = self.selectedRowIndexes;
|
|
|
|
NSMutableArray* torrents = [NSMutableArray arrayWithCapacity:selectedIndexes.count]; //take a shot at guessing capacity
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSUInteger i = selectedIndexes.firstIndex; i != NSNotFound; i = [selectedIndexes indexGreaterThanIndex:i])
|
2008-01-23 02:51:58 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
id item = [self itemAtRow:i];
|
|
|
|
if ([item isKindOfClass:[Torrent class]])
|
|
|
|
{
|
|
|
|
[torrents addObject:item];
|
|
|
|
}
|
2008-06-05 02:16:33 +00:00
|
|
|
else
|
2008-01-23 03:12:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSArray* groupTorrents = ((TorrentGroup*)item).torrents;
|
|
|
|
[torrents addObjectsFromArray:groupTorrents];
|
|
|
|
if ([self isItemExpanded:item])
|
|
|
|
{
|
|
|
|
i += groupTorrents.count;
|
|
|
|
}
|
2008-01-23 03:12:06 +00:00
|
|
|
}
|
2008-01-23 02:51:58 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-02-06 23:45:44 +00:00
|
|
|
return torrents;
|
2008-01-22 23:48:14 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSMenu*)menuForEvent:(NSEvent*)event
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger row = [self rowAtPoint:[self convertPoint:event.locationInWindow fromView:nil]];
|
2007-09-16 01:02:06 +00:00
|
|
|
if (row >= 0)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if (![self isRowSelected:row])
|
|
|
|
{
|
|
|
|
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
return fContextRow;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[self deselectAll:self];
|
2007-09-16 01:02:06 +00:00
|
|
|
return fContextNoRow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-16 21:09:59 +00:00
|
|
|
//make sure that the pause buttons become orange when holding down the option key
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)flagsChanged:(NSEvent*)event
|
2007-10-27 14:57:46 +00:00
|
|
|
{
|
|
|
|
[self display];
|
2021-08-15 09:41:48 +00:00
|
|
|
[super flagsChanged:event];
|
2007-10-27 14:57:46 +00:00
|
|
|
}
|
|
|
|
|
2008-03-16 14:24:27 +00:00
|
|
|
//option-command-f will focus the filter bar's search field
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)keyDown:(NSEvent*)event
|
2008-03-16 14:24:27 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
unichar const firstChar = [event.charactersIgnoringModifiers characterAtIndex:0];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if (firstChar == 'f' && event.modifierFlags & NSAlternateKeyMask && event.modifierFlags & NSCommandKeyMask)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-03-16 14:24:27 +00:00
|
|
|
[fController focusFilterField];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2009-09-04 04:10:46 +00:00
|
|
|
else if (firstChar == ' ')
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[fController toggleQuickLook:nil];
|
|
|
|
}
|
2021-08-07 07:27:56 +00:00
|
|
|
else if (event.keyCode == 53) //esc key
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self deselectAll:nil];
|
|
|
|
}
|
2008-03-16 14:24:27 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[super keyDown:event];
|
|
|
|
}
|
2008-03-16 14:24:27 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSRect)iconRectForRow:(NSInteger)row
|
2008-05-21 22:09:05 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
return [fTorrentCell iconRectForBounds:[self rectOfRow:row]];
|
2008-05-21 22:09:05 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)paste:(id)sender
|
2008-05-01 02:20:53 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSURL* url;
|
|
|
|
if ((url = [NSURL URLFromPasteboard:NSPasteboard.generalPasteboard]))
|
|
|
|
{
|
|
|
|
[fController openURL:url.absoluteString];
|
|
|
|
}
|
2016-01-06 11:05:37 +00:00
|
|
|
else
|
2011-12-26 02:33:13 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSArray* items = [NSPasteboard.generalPasteboard readObjectsForClasses:@[ [NSString class] ] options:nil];
|
2011-12-26 02:33:13 +00:00
|
|
|
if (items)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSDataDetector* detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
|
|
|
|
for (__strong NSString* pbItem in items)
|
2011-12-26 02:33:13 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
pbItem = [pbItem stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
|
|
|
|
if ([pbItem rangeOfString:@"magnet:" options:(NSAnchoredSearch | NSCaseInsensitiveSearch)].location != NSNotFound)
|
|
|
|
{
|
|
|
|
[fController openURL:pbItem];
|
|
|
|
}
|
2011-12-27 23:19:14 +00:00
|
|
|
else
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
#warning only accept full text?
|
|
|
|
for (NSTextCheckingResult* result in [detector matchesInString:pbItem options:0
|
|
|
|
range:NSMakeRange(0, pbItem.length)])
|
|
|
|
[fController openURL:result.URL.absoluteString];
|
2011-12-27 23:19:14 +00:00
|
|
|
}
|
2011-12-26 02:33:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-05-01 02:20:53 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)validateMenuItem:(NSMenuItem*)menuItem
|
2008-05-01 02:20:53 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
SEL action = menuItem.action;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-05-01 02:20:53 +00:00
|
|
|
if (action == @selector(paste:))
|
2011-12-26 02:33:13 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([NSPasteboard.generalPasteboard.types containsObject:NSURLPboardType])
|
|
|
|
{
|
2011-12-26 02:33:13 +00:00
|
|
|
return YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2016-01-06 11:05:37 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSArray* items = [NSPasteboard.generalPasteboard readObjectsForClasses:@[ [NSString class] ] options:nil];
|
2016-01-06 11:05:37 +00:00
|
|
|
if (items)
|
2011-12-26 02:33:13 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSDataDetector* detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
|
|
|
|
for (__strong NSString* pbItem in items)
|
2011-12-26 02:33:13 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
pbItem = [pbItem stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
|
|
|
|
if (([pbItem rangeOfString:@"magnet:" options:(NSAnchoredSearch | NSCaseInsensitiveSearch)].location != NSNotFound) ||
|
|
|
|
[detector firstMatchInString:pbItem options:0 range:NSMakeRange(0, pbItem.length)])
|
|
|
|
{
|
2016-01-06 11:05:37 +00:00
|
|
|
return YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2011-12-26 02:33:13 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
return NO;
|
2011-12-26 02:33:13 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-05-01 02:20:53 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)toggleControlForTorrent:(Torrent*)torrent
|
2008-01-14 18:02:08 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.active)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[fController stopTorrents:@[ torrent ]];
|
|
|
|
}
|
2008-01-14 18:02:08 +00:00
|
|
|
else
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (NSEvent.modifierFlags & NSAlternateKeyMask)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[fController resumeTorrentsNoWait:@[ torrent ]];
|
|
|
|
}
|
2021-08-07 07:27:56 +00:00
|
|
|
else if (torrent.waitingToStart)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[fController stopTorrents:@[ torrent ]];
|
|
|
|
}
|
2008-01-14 18:02:08 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[fController resumeTorrents:@[ torrent ]];
|
|
|
|
}
|
2008-01-14 18:02:08 +00:00
|
|
|
}
|
2007-12-17 16:06:20 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)displayTorrentActionPopoverForEvent:(NSEvent*)event
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger const row = [self rowAtPoint:[self convertPoint:event.locationInWindow fromView:nil]];
|
2007-09-16 01:02:06 +00:00
|
|
|
if (row < 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSRect const rect = [fTorrentCell iconRectForBounds:[self rectOfRow:row]];
|
2016-01-06 11:05:37 +00:00
|
|
|
|
|
|
|
if (fActionPopoverShown)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2016-01-06 11:05:37 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent = [self itemAtRow:row];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSPopover* popover = [[NSPopover alloc] init];
|
2021-08-07 07:27:56 +00:00
|
|
|
popover.behavior = NSPopoverBehaviorTransient;
|
2021-08-15 09:41:48 +00:00
|
|
|
InfoOptionsViewController* infoViewController = [[InfoOptionsViewController alloc] init];
|
2021-08-07 07:27:56 +00:00
|
|
|
popover.contentViewController = infoViewController;
|
|
|
|
popover.delegate = self;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[popover showRelativeToRect:rect ofView:self preferredEdge:NSMaxYEdge];
|
|
|
|
[infoViewController setInfoForTorrents:@[ torrent ]];
|
2016-01-06 11:05:37 +00:00
|
|
|
[infoViewController updateInfo];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2011-07-27 03:38:01 +00:00
|
|
|
//don't show multiple popovers when clicking the gear button repeatedly
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)popoverWillShow:(NSNotification*)notification
|
2011-07-27 03:38:01 +00:00
|
|
|
{
|
|
|
|
fActionPopoverShown = YES;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)popoverWillClose:(NSNotification*)notification
|
2011-07-27 03:38:01 +00:00
|
|
|
{
|
|
|
|
fActionPopoverShown = NO;
|
|
|
|
}
|
|
|
|
|
2011-10-06 00:30:40 +00:00
|
|
|
//eliminate when Lion-only, along with all the menu item instance variables
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)menuNeedsUpdate:(NSMenu*)menu
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
//this method seems to be called when it shouldn't be
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!fMenuTorrent || !menu.supermenu)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
if (menu == fUploadMenu || menu == fDownloadMenu)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMenuItem* item;
|
2021-08-07 07:27:56 +00:00
|
|
|
if (menu.numberOfItems == 3)
|
2008-01-10 06:52:13 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger const speedLimitActionValue[] = { 0, 5, 10, 20, 30, 40, 50, 75, 100,
|
|
|
|
150, 200, 250, 500, 750, 1000, 1500, 2000, -1 };
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-10-12 22:17:27 +00:00
|
|
|
for (NSInteger i = 0; speedLimitActionValue[i] != -1; i++)
|
2008-01-10 06:52:13 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
item = [[NSMenuItem alloc]
|
|
|
|
initWithTitle:[NSString stringWithFormat:NSLocalizedString(@"%d KB/s", "Action menu -> upload/download limit"),
|
|
|
|
speedLimitActionValue[i]]
|
|
|
|
action:@selector(setQuickLimit:)
|
|
|
|
keyEquivalent:@""];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.target = self;
|
|
|
|
item.representedObject = @(speedLimitActionValue[i]);
|
2021-08-15 09:41:48 +00:00
|
|
|
[menu addItem:item];
|
2008-01-10 06:52:13 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const upload = menu == fUploadMenu;
|
|
|
|
BOOL const limit = [fMenuTorrent usesSpeedLimit:upload];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
item = [menu itemWithTag:ACTION_MENU_LIMIT_TAG];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.state = limit ? NSOnState : NSOffState;
|
2021-08-15 09:41:48 +00:00
|
|
|
item.title = [NSString stringWithFormat:NSLocalizedString(@"Limit (%d KB/s)", "torrent action menu -> upload/download limit"),
|
|
|
|
[fMenuTorrent speedLimit:upload]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
item = [menu itemWithTag:ACTION_MENU_UNLIMITED_TAG];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.state = !limit ? NSOnState : NSOffState;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else if (menu == fRatioMenu)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMenuItem* item;
|
2021-08-07 07:27:56 +00:00
|
|
|
if (menu.numberOfItems == 4)
|
2008-01-10 06:52:13 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
float const ratioLimitActionValue[] = { 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, -1.0 };
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-02-15 14:56:14 +00:00
|
|
|
for (NSInteger i = 0; ratioLimitActionValue[i] != -1.0; i++)
|
2008-01-10 06:52:13 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
item = [[NSMenuItem alloc] initWithTitle:[NSString localizedStringWithFormat:@"%.2f", ratioLimitActionValue[i]]
|
|
|
|
action:@selector(setQuickRatio:)
|
|
|
|
keyEquivalent:@""];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.target = self;
|
|
|
|
item.representedObject = @(ratioLimitActionValue[i]);
|
2021-08-15 09:41:48 +00:00
|
|
|
[menu addItem:item];
|
2008-01-10 06:52:13 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_ratiolimit const mode = fMenuTorrent.ratioSetting;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
item = [menu itemWithTag:ACTION_MENU_LIMIT_TAG];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.state = mode == TR_RATIOLIMIT_SINGLE ? NSOnState : NSOffState;
|
2021-08-15 09:41:48 +00:00
|
|
|
item.title = [NSString localizedStringWithFormat:NSLocalizedString(@"Stop at Ratio (%.2f)", "torrent action menu -> ratio stop"),
|
|
|
|
fMenuTorrent.ratioLimit];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
item = [menu itemWithTag:ACTION_MENU_UNLIMITED_TAG];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.state = mode == TR_RATIOLIMIT_UNLIMITED ? NSOnState : NSOffState;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
item = [menu itemWithTag:ACTION_MENU_GLOBAL_TAG];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.state = mode == TR_RATIOLIMIT_GLOBAL ? NSOnState : NSOffState;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2009-04-20 03:36:35 +00:00
|
|
|
else if (menu == fPriorityMenu)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_priority_t const priority = fMenuTorrent.priority;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMenuItem* item = [menu itemWithTag:ACTION_MENU_PRIORITY_HIGH_TAG];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.state = priority == TR_PRI_HIGH ? NSOnState : NSOffState;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
item = [menu itemWithTag:ACTION_MENU_PRIORITY_NORMAL_TAG];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.state = priority == TR_PRI_NORMAL ? NSOnState : NSOffState;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
item = [menu itemWithTag:ACTION_MENU_PRIORITY_LOW_TAG];
|
2021-08-07 07:27:56 +00:00
|
|
|
item.state = priority == TR_PRI_LOW ? NSOnState : NSOffState;
|
2009-04-20 03:36:35 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2011-10-06 00:30:40 +00:00
|
|
|
//the following methods might not be needed when Lion-only
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setQuickLimitMode:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const limit = [sender tag] == ACTION_MENU_LIMIT_TAG;
|
|
|
|
[fMenuTorrent setUseSpeedLimit:limit upload:[sender menu] == fUploadMenu];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateOptions" object:nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setQuickLimit:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const upload = [sender menu] == fUploadMenu;
|
|
|
|
[fMenuTorrent setUseSpeedLimit:YES upload:upload];
|
|
|
|
[fMenuTorrent setSpeedLimit:[[sender representedObject] intValue] upload:upload];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateOptions" object:nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setGlobalLimit:(id)sender
|
2009-03-05 22:48:01 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
fMenuTorrent.usesGlobalSpeedLimit = ((NSButton*)sender).state != NSOnState;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateOptions" object:nil];
|
2009-03-05 22:48:01 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setQuickRatioMode:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-02-24 00:34:46 +00:00
|
|
|
tr_ratiolimit mode;
|
2007-10-11 12:06:46 +00:00
|
|
|
switch ([sender tag])
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
case ACTION_MENU_UNLIMITED_TAG:
|
|
|
|
mode = TR_RATIOLIMIT_UNLIMITED;
|
|
|
|
break;
|
|
|
|
case ACTION_MENU_LIMIT_TAG:
|
|
|
|
mode = TR_RATIOLIMIT_SINGLE;
|
|
|
|
break;
|
|
|
|
case ACTION_MENU_GLOBAL_TAG:
|
|
|
|
mode = TR_RATIOLIMIT_GLOBAL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
2007-10-11 12:06:46 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fMenuTorrent.ratioSetting = mode;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateOptions" object:nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setQuickRatio:(id)sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
fMenuTorrent.ratioSetting = TR_RATIOLIMIT_SINGLE;
|
|
|
|
fMenuTorrent.ratioLimit = [[sender representedObject] floatValue];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateOptions" object:nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setPriority:(id)sender
|
2009-04-20 03:36:35 +00:00
|
|
|
{
|
|
|
|
tr_priority_t priority;
|
|
|
|
switch ([sender tag])
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
case ACTION_MENU_PRIORITY_HIGH_TAG:
|
|
|
|
priority = TR_PRI_HIGH;
|
|
|
|
break;
|
|
|
|
case ACTION_MENU_PRIORITY_NORMAL_TAG:
|
|
|
|
priority = TR_PRI_NORMAL;
|
|
|
|
break;
|
|
|
|
case ACTION_MENU_PRIORITY_LOW_TAG:
|
|
|
|
priority = TR_PRI_LOW;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NSAssert1(NO, @"Unknown priority: %ld", [sender tag]);
|
|
|
|
priority = TR_PRI_NORMAL;
|
2009-04-20 03:36:35 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fMenuTorrent.priority = priority;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateUI" object:nil];
|
2009-04-20 03:36:35 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)togglePiecesBar
|
2008-01-16 15:56:40 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableArray* progressMarks = [NSMutableArray arrayWithCapacity:16];
|
2012-03-13 02:52:11 +00:00
|
|
|
for (NSAnimationProgress i = 0.0625; i <= 1.0; i += 0.0625)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[progressMarks addObject:@(i)];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-03-13 03:49:30 +00:00
|
|
|
//this stops a previous animation
|
2021-08-15 09:41:48 +00:00
|
|
|
fPiecesBarAnimation = [[NSAnimation alloc] initWithDuration:TOGGLE_PROGRESS_SECONDS animationCurve:NSAnimationEaseIn];
|
2021-08-07 07:27:56 +00:00
|
|
|
fPiecesBarAnimation.animationBlockingMode = NSAnimationNonblocking;
|
|
|
|
fPiecesBarAnimation.progressMarks = progressMarks;
|
|
|
|
fPiecesBarAnimation.delegate = self;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-06-10 05:09:30 +00:00
|
|
|
[fPiecesBarAnimation startAnimation];
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)animationDidEnd:(NSAnimation*)animation
|
2008-06-10 05:09:30 +00:00
|
|
|
{
|
|
|
|
if (animation == fPiecesBarAnimation)
|
|
|
|
{
|
|
|
|
fPiecesBarAnimation = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)animation:(NSAnimation*)animation didReachProgressMark:(NSAnimationProgress)progress
|
2008-06-10 05:09:30 +00:00
|
|
|
{
|
|
|
|
if (animation == fPiecesBarAnimation)
|
2008-01-16 16:39:18 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([fDefaults boolForKey:@"PiecesBar"])
|
|
|
|
{
|
2008-06-10 05:09:30 +00:00
|
|
|
fPiecesBarPercent = progress;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-06-10 05:09:30 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-02-15 14:56:14 +00:00
|
|
|
fPiecesBarPercent = 1.0 - progress;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
self.needsDisplay = YES;
|
2008-01-16 16:39:18 +00:00
|
|
|
}
|
2008-01-16 15:56:40 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (CGFloat)piecesBarPercent
|
2008-01-16 19:30:12 +00:00
|
|
|
{
|
|
|
|
return fPiecesBarPercent;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)selectAndScrollToRow:(NSInteger)row
|
2016-03-03 17:57:08 +00:00
|
|
|
{
|
|
|
|
NSParameterAssert(row >= 0);
|
2021-08-07 07:27:56 +00:00
|
|
|
NSParameterAssert(row < self.numberOfRows);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSRect const rowRect = [self rectOfRow:row];
|
|
|
|
NSRect const viewRect = self.superview.frame;
|
2016-03-03 17:57:08 +00:00
|
|
|
|
|
|
|
NSPoint scrollOrigin = rowRect.origin;
|
|
|
|
scrollOrigin.y += (rowRect.size.height - viewRect.size.height) / 2;
|
|
|
|
if (scrollOrigin.y < 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2016-03-03 17:57:08 +00:00
|
|
|
scrollOrigin.y = 0;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2016-03-03 17:57:08 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[[self.superview animator] setBoundsOrigin:scrollOrigin];
|
2016-03-03 17:57:08 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation TorrentTableView (Private)
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)pointInGroupStatusRect:(NSPoint)point
|
2008-02-28 02:17:17 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger row = [self rowAtPoint:point];
|
|
|
|
if (row < 0 || [[self itemAtRow:row] isKindOfClass:[Torrent class]])
|
|
|
|
{
|
2008-02-28 02:17:17 +00:00
|
|
|
return NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* ident = (self.tableColumns[[self columnAtPoint:point]]).identifier;
|
|
|
|
return [ident isEqualToString:@"UL"] || [ident isEqualToString:@"UL Image"] || [ident isEqualToString:@"DL"] ||
|
|
|
|
[ident isEqualToString:@"DL Image"];
|
2008-02-28 02:17:17 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setGroupStatusColumns
|
2008-02-28 16:40:14 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const ratio = [fDefaults boolForKey:@"DisplayGroupRowRatio"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self tableColumnWithIdentifier:@"DL"].hidden = ratio;
|
|
|
|
[self tableColumnWithIdentifier:@"DL Image"].hidden = ratio;
|
2008-02-28 16:40:14 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|