2023-11-01 21:11:11 +00:00
|
|
|
// This file Copyright © Transmission authors and contributors.
|
2022-01-20 18:27:56 +00:00
|
|
|
// It may be used under the MIT (SPDX: MIT) license.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-05-26 00:29:36 +00:00
|
|
|
#import "InfoWindowController.h"
|
2009-09-10 00:15:35 +00:00
|
|
|
#import "FileListNode.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
#import "FileNameCell.h"
|
2009-09-10 00:15:35 +00:00
|
|
|
#import "FileOutlineView.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
#import "FilePriorityCell.h"
|
|
|
|
#import "Torrent.h"
|
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
@interface FileOutlineView ()
|
|
|
|
|
|
|
|
@property(nonatomic) NSInteger hoveredRow;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@implementation FileOutlineView
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)awakeFromNib
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
FileNameCell* nameCell = [[FileNameCell alloc] init];
|
|
|
|
[self tableColumnWithIdentifier:@"Name"].dataCell = nameCell;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
FilePriorityCell* priorityCell = [[FilePriorityCell alloc] init];
|
|
|
|
[self tableColumnWithIdentifier:@"Priority"].dataCell = priorityCell;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
self.autoresizesOutlineColumn = NO;
|
|
|
|
self.indentationPerLevel = 14.0;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.hoveredRow = -1;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)mouseDown:(NSEvent*)event
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
[self.window makeKeyWindow];
|
2021-08-15 09:41:48 +00:00
|
|
|
[super mouseDown:event];
|
2007-09-16 01:02:06 +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 const row = [self rowAtPoint:[self convertPoint:event.locationInWindow fromView:nil]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self deselectAll:self];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
return self.menu;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
- (NSRect)iconRectForRow:(NSInteger)row
|
2008-05-21 22:09:05 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
FileNameCell* cell = (FileNameCell*)[self preparedCellAtColumn:[self columnWithIdentifier:@"Name"] row:row];
|
|
|
|
NSRect iconRect = [cell imageRectForBounds:[self rectOfRow:row]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
iconRect.origin.x += self.indentationPerLevel * (CGFloat)([self levelForRow:row] + 1);
|
2008-06-30 19:52:18 +00:00
|
|
|
return iconRect;
|
2008-05-21 22:09:05 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateTrackingAreas
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-01-15 03:33:44 +00:00
|
|
|
[super updateTrackingAreas];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSTrackingArea* area in self.trackingAreas)
|
2007-09-16 01:02:06 +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];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSRange visibleRows = [self rowsInRect:self.visibleRect];
|
2008-01-12 03:54:00 +00:00
|
|
|
if (visibleRows.length == 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-01-12 03:54:00 +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];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSInteger row = visibleRows.location, col = [self columnWithIdentifier:@"Priority"]; (NSUInteger)row < NSMaxRange(visibleRows); row++)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
FilePriorityCell* cell = (FilePriorityCell*)[self preparedCellAtColumn:col row:row];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSDictionary* userInfo = @{ @"Row" : @(row) };
|
|
|
|
[cell addTrackingAreasForView:self inRect:[self frameOfCellAtColumn:col row:row] withUserInfo:userInfo
|
|
|
|
mouseLocation:mouseLocation];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)mouseEntered:(NSEvent*)event
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSNumber* row;
|
|
|
|
if ((row = ((NSDictionary*)event.userData)[@"Row"]))
|
2008-01-12 03:39:26 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.hoveredRow = row.intValue;
|
|
|
|
[self setNeedsDisplayInRect:[self frameOfCellAtColumn:[self columnWithIdentifier:@"Priority"] row:self.hoveredRow]];
|
2008-01-12 03:39:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)mouseExited:(NSEvent*)event
|
2008-01-12 03:39:26 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSNumber* row;
|
|
|
|
if ((row = ((NSDictionary*)event.userData)[@"Row"]))
|
2008-01-12 03:39:26 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[self setNeedsDisplayInRect:[self frameOfCellAtColumn:[self columnWithIdentifier:@"Priority"] row:row.intValue]];
|
2022-02-22 16:04:20 +00:00
|
|
|
self.hoveredRow = -1;
|
2008-01-12 03:39:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|