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