source: trunk/macosx/FileOutlineView.m @ 3700

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

commit some changes that have been sitting in by checkout

  • Property Id set to /Users/mitchell/Desktop/Transmission/macosx/ActionMenuRatioToDisplayRatioTransformer.h
  • Property svn:keywords set to Date Rev Author Id
File size: 5.0 KB
Line 
1/******************************************************************************
2 * $Id: FileOutlineView.m 3700 2007-11-04 16:12:49Z livings124 $
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 "FileNameCell.h"
27#import "FilePriorityCell.h"
28#import "NSApplicationAdditions.h"
29#import "Torrent.h"
30
31@implementation FileOutlineView
32
33- (void) awakeFromNib
34{
35    FileNameCell * nameCell = [[FileNameCell alloc] init];
36    [[self tableColumnWithIdentifier: @"Name"] setDataCell: nameCell];
37    [nameCell release];
38   
39    FilePriorityCell * priorityCell = [[FilePriorityCell alloc] init];
40    [[self tableColumnWithIdentifier: @"Priority"] setDataCell: priorityCell];
41    [priorityCell release];
42   
43    [self setAutoresizesOutlineColumn: NO];
44    [self setIndentationPerLevel: 14.0];
45   
46    fHighPriorityColor = [[NSColor colorWithCalibratedRed: 0.8588 green: 0.9961 blue: 0.8311 alpha: 1.0] retain];
47    fLowPriorityColor = [[NSColor colorWithCalibratedRed: 1.0 green: 0.9529 blue: 0.8078 alpha: 1.0] retain];
48    fMixedPriorityColor = [[NSColor colorWithCalibratedRed: 0.9216 green: 0.9059 blue: 1.0 alpha: 1.0] retain];
49   
50    fHoverRow = -1;
51}
52
53- (void) dealloc
54{
55    [fHighPriorityColor release];
56    [fLowPriorityColor release];
57    [fMixedPriorityColor release];
58   
59    [super dealloc];
60}
61
62- (void) setTorrent: (Torrent *) torrent
63{
64    fTorrent = torrent;
65}
66
67- (Torrent *) torrent
68{
69    return fTorrent;
70}
71
72- (void) mouseDown: (NSEvent *) event
73{
74    [[self window] makeKeyWindow];
75    [super mouseDown: event];
76}
77
78- (NSMenu *) menuForEvent: (NSEvent *) event
79{
80    int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
81   
82    if (row >= 0)
83    {
84        if (![self isRowSelected: row])
85            [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO];
86    }
87    else
88        [self deselectAll: self];
89   
90    return [self menu];
91}
92
93- (void) setHoverRowForEvent: (NSEvent *) event
94{
95    int row = -1;
96    if (event)
97    {
98        NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil];
99        if ([self columnAtPoint: point] == [self columnWithIdentifier: @"Priority"])
100            row = [self rowAtPoint: point];
101    }
102   
103    if (row != fHoverRow)
104    {
105        if (fHoverRow != -1)
106            [self reloadItem: [self itemAtRow: fHoverRow]];
107        fHoverRow = row;
108        if (fHoverRow != -1)
109            [self reloadItem: [self itemAtRow: fHoverRow]];
110    }
111}
112
113- (int) hoverRow
114{
115    return fHoverRow;
116}
117
118#warning remove unneeded code
119- (void) drawRow: (int) row clipRect: (NSRect) clipRect
120{
121    NSDictionary * item = [self itemAtRow: row];
122    if (![self isRowSelected: row] && (![NSApp isOnLeopardOrBetter] || ![[item objectForKey: @"IsFolder"] boolValue]))
123    {
124        NSIndexSet * indexes = [item objectForKey: @"Indexes"];
125       
126        if ([fTorrent checkForFiles: indexes] != NSOffState)
127        {
128            NSSet * priorities = [fTorrent filePrioritiesForIndexes: indexes];
129            int count = [priorities count];
130            if (count > 0)
131            {
132                BOOL custom = YES;
133                if (count > 1)
134                    [fMixedPriorityColor set];
135                else
136                {
137                    switch ([[priorities anyObject] intValue])
138                    {
139                        case TR_PRI_LOW:
140                            [fLowPriorityColor set];
141                            break;
142                        case TR_PRI_HIGH:
143                            [fHighPriorityColor set];
144                            break;
145                        default:
146                            custom = NO;
147                    }
148                }
149               
150                if (custom)
151                {
152                    NSRect rect = [self rectOfRow: row];
153                    rect.size.height -= 1.0;
154           
155                    NSRectFill(rect);
156                }
157            }
158        }
159    }
160   
161    [super drawRow: row clipRect: clipRect];
162}
163
164@end
Note: See TracBrowser for help on using the repository browser.