source: trunk/macosx/FileOutlineView.m @ 8533

Last change on this file since 8533 was 8533, checked in by livings124, 13 years ago

#1942 Space in Add Torrent dialog box opens Quick Look on selected torrent in main window

  • Property Id set to /Users/mitchell/Desktop/Transmission/macosx/ActionMenuRatioToDisplayRatioTransformer.h
  • Property svn:keywords set to Date Rev Author Id
File size: 7.5 KB
Line 
1/******************************************************************************
2 * $Id: FileOutlineView.m 8533 2009-05-26 00:29:36Z livings124 $
3 *
4 * Copyright (c) 2007-2009 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 "InfoWindowController.h"
26#import "FileOutlineView.h"
27#import "FileNameCell.h"
28#import "FilePriorityCell.h"
29#import "Torrent.h"
30#import "FileListNode.h"
31#import "QuickLookController.h"
32
33@implementation FileOutlineView
34
35- (void) awakeFromNib
36{
37    FileNameCell * nameCell = [[FileNameCell alloc] init];
38    [[self tableColumnWithIdentifier: @"Name"] setDataCell: nameCell];
39    [nameCell release];
40   
41    FilePriorityCell * priorityCell = [[FilePriorityCell alloc] init];
42    [[self tableColumnWithIdentifier: @"Priority"] setDataCell: priorityCell];
43    [priorityCell release];
44   
45    [self setAutoresizesOutlineColumn: NO];
46    [self setIndentationPerLevel: 14.0];
47   
48    NSColor * endingColor = [NSColor colorWithCalibratedRed: 217.0/255.0 green: 250.0/255.0 blue: 211.0/255.0 alpha: 1.0];
49    NSColor * beginningColor = [endingColor blendedColorWithFraction: 0.3 ofColor: [NSColor whiteColor]];
50    fHighPriorityGradient = [[NSGradient alloc] initWithStartingColor: beginningColor endingColor: endingColor];
51   
52    endingColor = [NSColor colorWithCalibratedRed: 255.0/255.0 green: 243.0/255.0 blue: 206.0/255.0 alpha: 1.0];
53    beginningColor = [endingColor blendedColorWithFraction: 0.3 ofColor: [NSColor whiteColor]];
54    fLowPriorityGradient = [[NSGradient alloc] initWithStartingColor: beginningColor endingColor: endingColor];
55   
56    endingColor = [NSColor colorWithCalibratedRed: 225.0/255.0 green: 218.0/255.0 blue: 255.0/255.0 alpha: 1.0];
57    beginningColor = [endingColor blendedColorWithFraction: 0.3 ofColor: [NSColor whiteColor]];
58    fMixedPriorityGradient = [[NSGradient alloc] initWithStartingColor: beginningColor endingColor: endingColor];
59   
60    fMouseRow = -1;
61}
62
63- (void) dealloc
64{
65    [fHighPriorityGradient release];
66    [fLowPriorityGradient release];
67    [fMixedPriorityGradient release];
68   
69    [super dealloc];
70}
71
72- (void) setTorrent: (Torrent *) torrent
73{
74    fTorrent = torrent;
75}
76
77- (Torrent *) torrent
78{
79    return fTorrent;
80}
81
82- (void) mouseDown: (NSEvent *) event
83{
84    [[self window] makeKeyWindow];
85    [super mouseDown: event];
86}
87
88- (void) keyDown: (NSEvent *) event
89{
90    const unichar firstChar = [[event charactersIgnoringModifiers] characterAtIndex: 0];
91   
92    //don't allow quick look on add window
93    if (firstChar == ' ' && [[[self window] windowController] isKindOfClass: [InfoWindowController class]])
94        [[QuickLookController quickLook] toggleQuickLook];
95    else if (firstChar == NSRightArrowFunctionKey)
96        [[QuickLookController quickLook] pressRight];
97    else if (firstChar == NSLeftArrowFunctionKey)
98        [[QuickLookController quickLook] pressLeft];
99    else;
100   
101    [super keyDown: event]; 
102}
103
104- (NSMenu *) menuForEvent: (NSEvent *) event
105{
106    int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
107   
108    if (row >= 0)
109    {
110        if (![self isRowSelected: row])
111            [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO];
112    }
113    else
114        [self deselectAll: self];
115   
116    return [self menu];
117}
118
119- (NSRect) iconRectForRow: (int) row
120{
121    FileNameCell * cell = (FileNameCell *)[self preparedCellAtColumn: [self columnWithIdentifier: @"Name"] row: row];
122    NSRect iconRect = [cell imageRectForBounds: [self rectOfRow: row]];
123   
124    iconRect.origin.x += [self indentationPerLevel] * (float)([self levelForRow: row] + 1);
125    return iconRect;
126}
127
128- (void) updateTrackingAreas
129{
130    [super updateTrackingAreas];
131   
132    for (NSTrackingArea * area in [self trackingAreas])
133    {
134        if ([area owner] == self && [[area userInfo] objectForKey: @"Row"])
135            [self removeTrackingArea: area];
136    }
137   
138    NSRange visibleRows = [self rowsInRect: [self visibleRect]];
139    if (visibleRows.length == 0)
140        return;
141   
142    NSPoint mouseLocation = [self convertPoint: [[self window] convertScreenToBase: [NSEvent mouseLocation]] fromView: nil];
143   
144    for (NSInteger row = visibleRows.location, col = [self columnWithIdentifier: @"Priority"]; row < NSMaxRange(visibleRows); row++)
145    {
146        FilePriorityCell * cell = (FilePriorityCell *)[self preparedCellAtColumn: col row: row];
147       
148        NSDictionary * userInfo = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: row] forKey: @"Row"];
149        [cell addTrackingAreasForView: self inRect: [self frameOfCellAtColumn: col row: row] withUserInfo: userInfo
150                mouseLocation: mouseLocation];
151    }
152}
153
154- (int) hoveredRow
155{
156    return fMouseRow;
157}
158
159- (void) mouseEntered: (NSEvent *) event
160{
161    NSNumber * row;
162    if ((row = [(NSDictionary *)[event userData] objectForKey: @"Row"]))
163    {
164        fMouseRow = [row intValue];
165        [self setNeedsDisplayInRect: [self frameOfCellAtColumn: [self columnWithIdentifier: @"Priority"] row: fMouseRow]];
166    }
167}
168
169- (void) mouseExited: (NSEvent *) event
170{
171    NSNumber * row;
172    if ((row = [(NSDictionary *)[event userData] objectForKey: @"Row"]))
173    {
174        [self setNeedsDisplayInRect: [self frameOfCellAtColumn: [self columnWithIdentifier: @"Priority"] row: [row intValue]]];
175        fMouseRow = -1;
176    }
177}
178
179- (void) drawRow: (NSInteger) row clipRect: (NSRect) clipRect
180{
181    if (![self isRowSelected: row])
182    {
183        NSDictionary * item = [self itemAtRow: row];
184        NSIndexSet * indexes = [(FileListNode *)item indexes];
185       
186        if ([fTorrent checkForFiles: indexes] != NSOffState)
187        {
188            NSGradient * gradient = nil;
189           
190            NSSet * priorities = [fTorrent filePrioritiesForIndexes: indexes];
191            int count = [priorities count];
192            if (count == 1)
193            {
194                switch ([[priorities anyObject] intValue])
195                {
196                    case TR_PRI_LOW:
197                        gradient = fLowPriorityGradient;
198                        break;
199                    case TR_PRI_HIGH:
200                        gradient = fHighPriorityGradient;
201                        break;
202                }
203            }
204            else if (count > 1)
205                gradient = fMixedPriorityGradient;
206            else;
207           
208            if (gradient)
209            {
210                NSRect rect = [self rectOfRow: row];
211                rect.size.height -= 1.0;
212                [gradient drawInRect: rect angle: 90];
213            }
214        }
215    }
216   
217    [super drawRow: row clipRect: clipRect];
218}
219
220@end
Note: See TracBrowser for help on using the repository browser.