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.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2007-01-17 17:44:03 +00:00
|
|
|
#import "FileOutlineView.h"
|
2007-01-18 01:19:14 +00:00
|
|
|
#import "FileBrowserCell.h"
|
2007-06-29 01:49:41 +00:00
|
|
|
#import "InfoWindowController.h"
|
2007-06-18 03:40:41 +00:00
|
|
|
#import "Torrent.h"
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-01-17 17:44:03 +00:00
|
|
|
@implementation FileOutlineView
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-01-17 17:49:22 +00:00
|
|
|
- (void) awakeFromNib
|
|
|
|
{
|
2007-01-18 01:19:14 +00:00
|
|
|
NSBrowserCell * browserCell = [[[FileBrowserCell alloc] init] autorelease];
|
2007-01-17 17:49:22 +00:00
|
|
|
[[self tableColumnWithIdentifier: @"Name"] setDataCell: browserCell];
|
|
|
|
|
|
|
|
[self setAutoresizesOutlineColumn: NO];
|
2007-01-17 20:50:42 +00:00
|
|
|
[self setIndentationPerLevel: 14.0];
|
2007-06-18 03:40:41 +00:00
|
|
|
|
|
|
|
fNormalColor = [self backgroundColor];
|
2007-06-23 15:14:37 +00:00
|
|
|
fHighPriorityColor = [[NSColor colorWithCalibratedRed: 0.678 green: 0.937 blue: 0.451 alpha: 1.0] retain];
|
|
|
|
fLowPriorityColor = [[NSColor colorWithCalibratedRed: 0.984 green: 0.878 blue: 0.431 alpha: 1.0] retain];
|
2007-06-23 22:00:09 +00:00
|
|
|
|
|
|
|
fHoverRow = -1;
|
2007-06-18 03:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[fHighPriorityColor release];
|
|
|
|
[fLowPriorityColor release];
|
|
|
|
|
|
|
|
[super dealloc];
|
2007-01-17 17:49:22 +00:00
|
|
|
}
|
|
|
|
|
2006-08-14 03:13:34 +00:00
|
|
|
- (void) mouseDown: (NSEvent *) event
|
|
|
|
{
|
|
|
|
[[self window] makeKeyWindow];
|
|
|
|
[super mouseDown: event];
|
|
|
|
}
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
- (NSMenu *) menuForEvent: (NSEvent *) event
|
2006-07-16 19:39:23 +00:00
|
|
|
{
|
2007-06-18 03:40:41 +00:00
|
|
|
int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
if (row >= 0)
|
|
|
|
{
|
2007-06-18 03:40:41 +00:00
|
|
|
if (![self isRowSelected: row])
|
2006-07-16 19:39:23 +00:00
|
|
|
[self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[self deselectAll: self];
|
|
|
|
|
2007-01-17 17:44:03 +00:00
|
|
|
return [self menu];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
2007-06-23 22:00:09 +00:00
|
|
|
- (void) setHoverRowForEvent: (NSEvent *) event
|
|
|
|
{
|
|
|
|
int row = -1;
|
|
|
|
if (event)
|
|
|
|
{
|
|
|
|
NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil];
|
2007-06-24 14:13:57 +00:00
|
|
|
if ([self columnAtPoint: point] == [self columnWithIdentifier: @"Priority"])
|
2007-06-23 22:00:09 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
- (void) drawRow: (int) row clipRect: (NSRect) clipRect
|
|
|
|
{
|
|
|
|
if (![self isRowSelected: row])
|
|
|
|
{
|
|
|
|
NSDictionary * item = [self itemAtRow: row];
|
2007-06-22 01:16:50 +00:00
|
|
|
if ([[item objectForKey: @"IsFolder"] boolValue]
|
2007-06-29 01:49:41 +00:00
|
|
|
|| ![[(InfoWindowController *)[[self window] windowController] selectedTorrent]
|
|
|
|
canChangeDownloadCheckForFiles: [item objectForKey: @"Indexes"]])
|
2007-06-18 03:40:41 +00:00
|
|
|
[fNormalColor set];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int priority = [[item objectForKey: @"Priority"] intValue];
|
|
|
|
if (priority == PRIORITY_HIGH)
|
|
|
|
[fHighPriorityColor set];
|
|
|
|
else if (priority == PRIORITY_LOW)
|
|
|
|
[fLowPriorityColor set];
|
|
|
|
else
|
|
|
|
[fNormalColor set];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSRect rect = [self rectOfRow: row];
|
|
|
|
rect.size.height -= 1.0;
|
|
|
|
|
|
|
|
NSRectFill(rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
[super drawRow: row clipRect: clipRect];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) drawRect: (NSRect) r
|
|
|
|
{
|
|
|
|
[super drawRect: r];
|
|
|
|
|
|
|
|
NSDictionary * item;
|
|
|
|
int i, priority;
|
2007-06-29 01:49:41 +00:00
|
|
|
Torrent * torrent = [(InfoWindowController *)[[self window] windowController] selectedTorrent];
|
2007-06-18 03:40:41 +00:00
|
|
|
for (i = 0; i < [self numberOfRows]; i++)
|
|
|
|
{
|
|
|
|
if ([self isRowSelected: i])
|
|
|
|
{
|
|
|
|
item = [self itemAtRow: i];
|
2007-06-22 01:16:50 +00:00
|
|
|
if (![[item objectForKey: @"IsFolder"] boolValue]
|
2007-06-29 01:49:41 +00:00
|
|
|
&& [torrent canChangeDownloadCheckForFiles: [item objectForKey: @"Indexes"]])
|
2007-06-18 03:40:41 +00:00
|
|
|
{
|
|
|
|
priority = [[item objectForKey: @"Priority"] intValue];
|
|
|
|
if (priority == PRIORITY_HIGH)
|
|
|
|
[fHighPriorityColor set];
|
|
|
|
else if (priority == PRIORITY_LOW)
|
|
|
|
[fLowPriorityColor set];
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
|
|
|
|
NSRect rect = [self rectOfRow: i];
|
|
|
|
float width = 14.0;
|
|
|
|
rect.origin.y += (rect.size.height - width) * 0.5;
|
|
|
|
rect.origin.x += 3.0;
|
|
|
|
rect.size.width = width;
|
|
|
|
rect.size.height = width;
|
|
|
|
|
|
|
|
[[NSBezierPath bezierPathWithOvalInRect: rect] fill];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
@end
|