1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-29 11:06:23 +00:00
transmission/macosx/FileOutlineView.m

139 lines
4.3 KiB
Mathematica
Raw Normal View History

2006-07-16 19:39:23 +00:00
/******************************************************************************
2007-04-03 02:15:24 +00:00
* $Id$
2006-07-16 19:39:23 +00:00
*
2007-04-03 02:15:24 +00:00
* Copyright (c) 2007 Transmission authors and contributors
2006-07-16 19:39:23 +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"
2007-01-18 01:19:14 +00:00
#import "FileBrowserCell.h"
#import "InfoWindowController.h"
#import "Torrent.h"
2006-07-16 19:39:23 +00:00
@implementation FileOutlineView
2006-07-16 19:39:23 +00:00
- (void) awakeFromNib
{
NSBrowserCell * browserCell = [[FileBrowserCell alloc] init];
[[self tableColumnWithIdentifier: @"Name"] setDataCell: browserCell];
[browserCell release];
[self setAutoresizesOutlineColumn: NO];
2007-01-17 20:50:42 +00:00
[self setIndentationPerLevel: 14.0];
fNormalColor = [self backgroundColor];
fHighPriorityColor = [[NSColor colorWithCalibratedRed: 0.8588 green: 0.9961 blue: 0.8311 alpha: 1.0] retain];
fLowPriorityColor = [[NSColor colorWithCalibratedRed: 1.0 green: 0.9529 blue: 0.8078 alpha: 1.0] retain];
fMixedPriorityColor = [[NSColor colorWithCalibratedRed: 0.9216 green: 0.9059 blue: 1.0 alpha: 1.0] retain];
fHoverRow = -1;
}
- (void) dealloc
{
[fHighPriorityColor release];
[fLowPriorityColor release];
[fMixedPriorityColor release];
[super dealloc];
}
- (void) mouseDown: (NSEvent *) event
{
[[self window] makeKeyWindow];
[super mouseDown: event];
}
- (NSMenu *) menuForEvent: (NSEvent *) event
2006-07-16 19:39:23 +00:00
{
int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
2006-07-16 19:39:23 +00:00
if (row >= 0)
{
if (![self isRowSelected: row])
2006-07-16 19:39:23 +00:00
[self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO];
}
else
[self deselectAll: self];
return [self menu];
2006-07-16 19:39:23 +00:00
}
- (void) setHoverRowForEvent: (NSEvent *) event
{
int row = -1;
if (event)
{
NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil];
if ([self columnAtPoint: point] == [self columnWithIdentifier: @"Priority"])
row = [self rowAtPoint: point];
}
if (row != fHoverRow)
{
if (fHoverRow != -1)
[self reloadItem: [self itemAtRow: fHoverRow]];
fHoverRow = row;
if (fHoverRow != -1)
[self reloadItem: [self itemAtRow: fHoverRow]];
}
}
- (int) hoverRow
{
return fHoverRow;
}
- (void) drawRow: (int) row clipRect: (NSRect) clipRect
{
if (![self isRowSelected: row])
{
NSDictionary * item = [self itemAtRow: row];
Torrent * torrent = [(InfoWindowController *)[[self window] windowController] selectedTorrent];
NSSet * priorities = [torrent filePrioritiesForIndexes: [item objectForKey: @"Indexes"]];
int count = [priorities count];
if (count == 0)
[fNormalColor set];
else if (count > 1)
[fMixedPriorityColor set];
else
{
int priority = [[priorities anyObject] intValue];
if (priority == TR_PRI_LOW)
[fLowPriorityColor set];
else if (priority == TR_PRI_HIGH)
[fHighPriorityColor set];
else
[fNormalColor set];
}
NSRect rect = [self rectOfRow: row];
rect.size.height -= 1.0;
NSRectFill(rect);
}
[super drawRow: row clipRect: clipRect];
}
2006-07-16 19:39:23 +00:00
@end