2007-09-16 01:02:06 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-01-02 16:55:05 +00:00
|
|
|
* Copyright (c) 2007-2008 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 "FileOutlineView.h"
|
|
|
|
#import "FileNameCell.h"
|
|
|
|
#import "FilePriorityCell.h"
|
|
|
|
#import "Torrent.h"
|
2008-05-22 18:39:49 +00:00
|
|
|
#import "FileListNode.h"
|
2008-05-21 15:23:26 +00:00
|
|
|
#import "QuickLookController.h"
|
2007-11-08 12:58:05 +00:00
|
|
|
#import "CTGradient.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
@implementation FileOutlineView
|
|
|
|
|
|
|
|
- (void) awakeFromNib
|
|
|
|
{
|
|
|
|
FileNameCell * nameCell = [[FileNameCell alloc] init];
|
|
|
|
[[self tableColumnWithIdentifier: @"Name"] setDataCell: nameCell];
|
|
|
|
[nameCell release];
|
|
|
|
|
|
|
|
FilePriorityCell * priorityCell = [[FilePriorityCell alloc] init];
|
|
|
|
[[self tableColumnWithIdentifier: @"Priority"] setDataCell: priorityCell];
|
|
|
|
[priorityCell release];
|
|
|
|
|
|
|
|
[self setAutoresizesOutlineColumn: NO];
|
|
|
|
[self setIndentationPerLevel: 14.0];
|
|
|
|
|
2007-12-22 15:49:45 +00:00
|
|
|
NSColor * endingColor = [NSColor colorWithCalibratedRed: 217.0/255.0 green: 250.0/255.0 blue: 211.0/255.0 alpha: 1.0];
|
|
|
|
NSColor * beginningColor = [endingColor blendedColorWithFraction: 0.3 ofColor: [NSColor whiteColor]];
|
2007-11-08 12:58:05 +00:00
|
|
|
fHighPriorityGradient = [[CTGradient gradientWithBeginningColor: beginningColor endingColor: endingColor] retain];
|
|
|
|
|
2007-12-22 15:49:45 +00:00
|
|
|
endingColor = [NSColor colorWithCalibratedRed: 255.0/255.0 green: 243.0/255.0 blue: 206.0/255.0 alpha: 1.0];
|
|
|
|
beginningColor = [endingColor blendedColorWithFraction: 0.3 ofColor: [NSColor whiteColor]];
|
2007-11-08 12:58:05 +00:00
|
|
|
fLowPriorityGradient = [[CTGradient gradientWithBeginningColor: beginningColor endingColor: endingColor] retain];
|
|
|
|
|
2007-12-22 15:49:45 +00:00
|
|
|
endingColor = [NSColor colorWithCalibratedRed: 225.0/255.0 green: 218.0/255.0 blue: 255.0/255.0 alpha: 1.0];
|
|
|
|
beginningColor = [endingColor blendedColorWithFraction: 0.3 ofColor: [NSColor whiteColor]];
|
2007-11-08 12:58:05 +00:00
|
|
|
fMixedPriorityGradient = [[CTGradient gradientWithBeginningColor: beginningColor endingColor: endingColor] retain];
|
2008-01-12 05:09:03 +00:00
|
|
|
|
|
|
|
fMouseRow = -1;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2007-11-08 12:58:05 +00:00
|
|
|
[fHighPriorityGradient release];
|
|
|
|
[fLowPriorityGradient release];
|
|
|
|
[fMixedPriorityGradient release];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2007-10-20 19:13:52 +00:00
|
|
|
- (void) setTorrent: (Torrent *) torrent
|
|
|
|
{
|
|
|
|
fTorrent = torrent;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (Torrent *) torrent
|
|
|
|
{
|
|
|
|
return fTorrent;
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) mouseDown: (NSEvent *) event
|
|
|
|
{
|
|
|
|
[[self window] makeKeyWindow];
|
|
|
|
[super mouseDown: event];
|
|
|
|
}
|
|
|
|
|
2008-05-20 19:34:33 +00:00
|
|
|
- (void) keyDown: (NSEvent *) event
|
|
|
|
{
|
|
|
|
unichar firstChar = [[event charactersIgnoringModifiers] characterAtIndex: 0];
|
|
|
|
if (firstChar == ' ')
|
2008-05-21 15:23:26 +00:00
|
|
|
[[QuickLookController quickLook] toggleQuickLook];
|
2008-05-20 19:34:33 +00:00
|
|
|
else if (firstChar == NSRightArrowFunctionKey)
|
2008-05-21 15:23:26 +00:00
|
|
|
[[QuickLookController quickLook] pressRight];
|
2008-05-20 19:34:33 +00:00
|
|
|
else if (firstChar == NSLeftArrowFunctionKey)
|
2008-05-21 15:23:26 +00:00
|
|
|
[[QuickLookController quickLook] pressLeft];
|
2008-05-20 19:34:33 +00:00
|
|
|
else;
|
|
|
|
|
|
|
|
[super keyDown: event];
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (NSMenu *) menuForEvent: (NSEvent *) event
|
|
|
|
{
|
|
|
|
int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
|
|
|
|
|
|
|
|
if (row >= 0)
|
|
|
|
{
|
|
|
|
if (![self isRowSelected: row])
|
|
|
|
[self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[self deselectAll: self];
|
|
|
|
|
|
|
|
return [self menu];
|
|
|
|
}
|
|
|
|
|
2008-05-21 22:09:05 +00:00
|
|
|
- (NSRect) iconRectForRow: (int) row
|
|
|
|
{
|
2008-06-30 19:52:18 +00:00
|
|
|
FileNameCell * cell = (FileNameCell *)[self preparedCellAtColumn: [self columnWithIdentifier: @"Name"] row: row];
|
|
|
|
NSRect iconRect = [cell imageRectForBounds: [self rectOfRow: row]];
|
|
|
|
|
2008-06-30 19:56:29 +00:00
|
|
|
iconRect.origin.x += [self indentationPerLevel] * (float)([self levelForRow: row] + 1);
|
2008-06-30 19:52:18 +00:00
|
|
|
return iconRect;
|
2008-05-21 22:09:05 +00:00
|
|
|
}
|
|
|
|
|
2008-01-12 03:39:26 +00:00
|
|
|
- (void) updateTrackingAreas
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-01-15 03:33:44 +00:00
|
|
|
[super updateTrackingAreas];
|
|
|
|
|
2008-01-12 03:39:26 +00:00
|
|
|
NSEnumerator * enumerator = [[self trackingAreas] objectEnumerator];
|
|
|
|
NSTrackingArea * area;
|
|
|
|
while ((area = [enumerator nextObject]))
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-01-12 03:39:26 +00:00
|
|
|
if ([area owner] == self && [[area userInfo] objectForKey: @"Row"])
|
|
|
|
[self removeTrackingArea: area];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-01-12 03:53:41 +00:00
|
|
|
NSRange visibleRows = [self rowsInRect: [self visibleRect]];
|
2008-01-12 03:54:00 +00:00
|
|
|
if (visibleRows.length == 0)
|
|
|
|
return;
|
2008-01-12 03:53:41 +00:00
|
|
|
|
2008-01-12 03:39:26 +00:00
|
|
|
NSPoint mouseLocation = [self convertPoint: [[self window] convertScreenToBase: [NSEvent mouseLocation]] fromView: nil];
|
|
|
|
|
2008-10-12 21:38:13 +00:00
|
|
|
for (NSInteger row = visibleRows.location, col = [self columnWithIdentifier: @"Priority"]; row < NSMaxRange(visibleRows); row++)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-01-12 03:39:26 +00:00
|
|
|
FilePriorityCell * cell = (FilePriorityCell *)[self preparedCellAtColumn: col row: row];
|
|
|
|
|
|
|
|
NSDictionary * userInfo = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: row] forKey: @"Row"];
|
|
|
|
[cell addTrackingAreasForView: self inRect: [self frameOfCellAtColumn: col row: row] withUserInfo: userInfo
|
|
|
|
mouseLocation: mouseLocation];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-25 03:17:35 +00:00
|
|
|
- (int) hoveredRow
|
|
|
|
{
|
|
|
|
return fMouseRow;
|
|
|
|
}
|
|
|
|
|
2008-01-12 03:39:26 +00:00
|
|
|
- (void) mouseEntered: (NSEvent *) event
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-01-12 03:39:26 +00:00
|
|
|
NSNumber * row;
|
|
|
|
if ((row = [(NSDictionary *)[event userData] objectForKey: @"Row"]))
|
|
|
|
{
|
2008-03-25 03:17:35 +00:00
|
|
|
fMouseRow = [row intValue];
|
2008-03-25 14:10:05 +00:00
|
|
|
[self setNeedsDisplayInRect: [self frameOfCellAtColumn: [self columnWithIdentifier: @"Priority"] row: fMouseRow]];
|
2008-01-12 03:39:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) mouseExited: (NSEvent *) event
|
|
|
|
{
|
|
|
|
NSNumber * row;
|
|
|
|
if ((row = [(NSDictionary *)[event userData] objectForKey: @"Row"]))
|
|
|
|
{
|
2008-03-25 14:10:05 +00:00
|
|
|
[self setNeedsDisplayInRect: [self frameOfCellAtColumn: [self columnWithIdentifier: @"Priority"] row: [row intValue]]];
|
2008-01-12 03:39:26 +00:00
|
|
|
fMouseRow = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-02 14:04:57 +00:00
|
|
|
- (void) drawRow: (NSInteger) row clipRect: (NSRect) clipRect
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-11-04 16:19:22 +00:00
|
|
|
if (![self isRowSelected: row])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-11-04 16:19:22 +00:00
|
|
|
NSDictionary * item = [self itemAtRow: row];
|
2008-05-22 18:39:49 +00:00
|
|
|
NSIndexSet * indexes = [(FileListNode *)item indexes];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-10-20 19:13:52 +00:00
|
|
|
if ([fTorrent checkForFiles: indexes] != NSOffState)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-11-08 12:58:05 +00:00
|
|
|
CTGradient * gradient = nil;
|
|
|
|
|
2007-10-20 19:13:52 +00:00
|
|
|
NSSet * priorities = [fTorrent filePrioritiesForIndexes: indexes];
|
2007-09-16 01:02:06 +00:00
|
|
|
int count = [priorities count];
|
2007-11-08 12:58:05 +00:00
|
|
|
if (count == 1)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-11-08 12:58:05 +00:00
|
|
|
switch ([[priorities anyObject] intValue])
|
2007-10-11 03:52:35 +00:00
|
|
|
{
|
2007-11-08 12:58:05 +00:00
|
|
|
case TR_PRI_LOW:
|
|
|
|
gradient = fLowPriorityGradient;
|
|
|
|
break;
|
|
|
|
case TR_PRI_HIGH:
|
|
|
|
gradient = fHighPriorityGradient;
|
|
|
|
break;
|
2007-10-11 03:52:35 +00:00
|
|
|
}
|
2007-11-08 12:58:05 +00:00
|
|
|
}
|
|
|
|
else if (count > 1)
|
|
|
|
gradient = fMixedPriorityGradient;
|
|
|
|
else;
|
2007-10-11 03:52:35 +00:00
|
|
|
|
2007-11-08 12:58:05 +00:00
|
|
|
if (gradient)
|
|
|
|
{
|
|
|
|
NSRect rect = [self rectOfRow: row];
|
|
|
|
rect.size.height -= 1.0;
|
|
|
|
[gradient fillRect: rect angle: 90];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[super drawRow: row clipRect: clipRect];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|