source: trunk/macosx/FileOutlineView.m @ 2149

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

Merge file selection and torrent creation into the main branch.

The new code for these features is under a new license.

File size: 4.3 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            [fNormalColor set];
80        else
81        {
82            int priority = [[item objectForKey: @"Priority"] intValue];
83            if (priority == PRIORITY_HIGH)
84                [fHighPriorityColor set];
85            else if (priority == PRIORITY_LOW)
86                [fLowPriorityColor set];
87            else
88                [fNormalColor set];
89        }
90       
91        NSRect rect = [self rectOfRow: row];
92        rect.size.height -= 1.0;
93       
94        NSRectFill(rect);
95    }
96   
97    [super drawRow: row clipRect: clipRect];
98}
99
100- (void) drawRect: (NSRect) r
101{
102    [super drawRect: r];
103
104    NSDictionary * item;
105    int i, priority;
106    for (i = 0; i < [self numberOfRows]; i++)
107    {
108        if ([self isRowSelected: i])
109        {
110            item = [self itemAtRow: i];
111            if (![[item objectForKey: @"IsFolder"] boolValue])
112            {
113                priority = [[item objectForKey: @"Priority"] intValue];
114                if (priority == PRIORITY_HIGH)
115                    [fHighPriorityColor set];
116                else if (priority == PRIORITY_LOW)
117                    [fLowPriorityColor set];
118                else
119                    continue;
120               
121                NSRect rect = [self rectOfRow: i];
122                float width = 14.0;
123                rect.origin.y += (rect.size.height - width) * 0.5;
124                rect.origin.x += 3.0;
125                rect.size.width = width;
126                rect.size.height = width;
127               
128                [[NSBezierPath bezierPathWithOvalInRect: rect] fill];
129            }
130        }
131    }
132}
133
134@end
Note: See TracBrowser for help on using the repository browser.