source: trunk/macosx/FileOutlineView.m @ 2183

Last change on this file since 2183 was 2183, checked in by livings124, 15 years ago

don't show priority colors for finished files

File size: 4.5 KB
Line 
1/******************************************************************************
2 * $Id$
3 *
4 * Copyright (c) 2007 Transmission authors and contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#import "FileOutlineView.h"
26#import "FileBrowserCell.h"
27#import "Torrent.h"
28
29@implementation FileOutlineView
30
31- (void) awakeFromNib
32{
33    NSBrowserCell * browserCell = [[[FileBrowserCell alloc] init] autorelease];
34    [[self tableColumnWithIdentifier: @"Name"] setDataCell: browserCell];
35   
36    [self setAutoresizesOutlineColumn: NO];
37    [self setIndentationPerLevel: 14.0];
38   
39    fNormalColor = [self backgroundColor];
40    fHighPriorityColor = [[NSColor colorWithCalibratedRed: 1.0 green: 208.0/255.0 blue: 208.0/255.0 alpha: 1.0] retain];
41    fLowPriorityColor = [[NSColor colorWithCalibratedRed: 1.0 green: 1.0 blue: 224.0/255.0 alpha: 1.0] retain];
42}
43
44- (void) dealloc
45{
46    [fHighPriorityColor release];
47    [fLowPriorityColor release];
48   
49    [super dealloc];
50}
51
52- (void) mouseDown: (NSEvent *) event
53{
54    [[self window] makeKeyWindow];
55    [super mouseDown: event];
56}
57
58- (NSMenu *) menuForEvent: (NSEvent *) event
59{
60    int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
61   
62    if (row >= 0)
63    {
64        if (![self isRowSelected: row])
65            [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO];
66    }
67    else
68        [self deselectAll: self];
69   
70    return [self menu];
71}
72
73- (void) drawRow: (int) row clipRect: (NSRect) clipRect
74{
75    if (![self isRowSelected: row])
76    {
77        NSDictionary * item = [self itemAtRow: row];
78        if ([[item objectForKey: @"IsFolder"] boolValue]
79                || ![[item objectForKey: @"Torrent"] canChangeDownloadCheckForFiles: [item objectForKey: @"Indexes"]])
80            [fNormalColor set];
81        else
82        {
83            int priority = [[item objectForKey: @"Priority"] intValue];
84            if (priority == PRIORITY_HIGH)
85                [fHighPriorityColor set];
86            else if (priority == PRIORITY_LOW)
87                [fLowPriorityColor set];
88            else
89                [fNormalColor set];
90        }
91       
92        NSRect rect = [self rectOfRow: row];
93        rect.size.height -= 1.0;
94       
95        NSRectFill(rect);
96    }
97   
98    [super drawRow: row clipRect: clipRect];
99}
100
101- (void) drawRect: (NSRect) r
102{
103    [super drawRect: r];
104
105    NSDictionary * item;
106    int i, priority;
107    for (i = 0; i < [self numberOfRows]; i++)
108    {
109        if ([self isRowSelected: i])
110        {
111            item = [self itemAtRow: i];
112            if (![[item objectForKey: @"IsFolder"] boolValue]
113                && [[item objectForKey: @"Torrent"] canChangeDownloadCheckForFiles: [item objectForKey: @"Indexes"]])
114            {
115                priority = [[item objectForKey: @"Priority"] intValue];
116                if (priority == PRIORITY_HIGH)
117                    [fHighPriorityColor set];
118                else if (priority == PRIORITY_LOW)
119                    [fLowPriorityColor set];
120                else
121                    continue;
122               
123                NSRect rect = [self rectOfRow: i];
124                float width = 14.0;
125                rect.origin.y += (rect.size.height - width) * 0.5;
126                rect.origin.x += 3.0;
127                rect.size.width = width;
128                rect.size.height = width;
129               
130                [[NSBezierPath bezierPathWithOvalInRect: rect] fill];
131            }
132        }
133    }
134}
135
136@end
Note: See TracBrowser for help on using the repository browser.