source: trunk/macosx/TorrentTableView.m @ 3597

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

on Leopard us the built-in delegate to select a row while typing, and make Tiger's behavior similar to the new behavior

  • Property svn:keywords set to Date Rev Author Id
File size: 22.5 KB
Line 
1/******************************************************************************
2 * $Id: TorrentTableView.m 3597 2007-10-27 14:57:46Z livings124 $
3 *
4 * Copyright (c) 2005-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 "TorrentTableView.h"
26#import "TorrentCell.h"
27#import "Controller.h"
28#import "Torrent.h"
29#import "NSApplicationAdditions.h"
30#import "NSMenuAdditions.h"
31
32#define PADDING 3.0
33
34#define BUTTON_TO_TOP_REGULAR 33.0
35#define BUTTON_TO_TOP_SMALL 20.0
36
37#define ACTION_BUTTON_TO_TOP 47.0
38
39#define ACTION_MENU_GLOBAL_TAG 101
40#define ACTION_MENU_UNLIMITED_TAG 102
41#define ACTION_MENU_LIMIT_TAG 103
42
43@interface TorrentTableView (Private)
44
45- (NSRect) pauseRectForRow: (int) row;
46- (NSRect) revealRectForRow: (int) row;
47- (NSRect) actionRectForRow: (int) row;
48
49- (BOOL) pointInIconRect: (NSPoint) point;
50- (BOOL) pointInProgressRect: (NSPoint) point;
51- (BOOL) pointInMinimalStatusRect: (NSPoint) point;
52
53- (BOOL) pointInPauseRect: (NSPoint) point;
54- (BOOL) pointInRevealRect: (NSPoint) point;
55- (BOOL) pointInActionRect: (NSPoint) point;
56
57- (void) updateFileMenu: (NSMenu *) menu forFiles: (NSArray *) files;
58
59@end
60
61@implementation TorrentTableView
62
63- (id) initWithCoder: (NSCoder *) decoder
64{
65    if ((self = [super initWithCoder: decoder]))
66    {
67        fResumeOnIcon = [NSImage imageNamed: @"ResumeOn.png"];
68        fResumeOffIcon = [NSImage imageNamed: @"ResumeOff.png"];
69        fPauseOnIcon = [NSImage imageNamed: @"PauseOn.png"];
70        fPauseOffIcon = [NSImage imageNamed: @"PauseOff.png"];
71        fResumeNoWaitOnIcon = [NSImage imageNamed: @"ResumeNoWaitOn.png"];
72        fResumeNoWaitOffIcon = [NSImage imageNamed: @"ResumeNoWaitOff.png"];
73       
74        fRevealOnIcon = [NSImage imageNamed: @"RevealOn.png"];
75        fRevealOffIcon = [NSImage imageNamed: @"RevealOff.png"];
76       
77        fActionOnIcon = [NSImage imageNamed: @"ActionOn.png"];
78        fActionOffIcon = [NSImage imageNamed: @"ActionOff.png"];
79       
80        fClickPoint = NSZeroPoint;
81        fClickIn = NO;
82       
83        fDefaults = [NSUserDefaults standardUserDefaults];
84       
85        [self setDelegate: self];
86    }
87   
88    return self;
89}
90
91- (void) dealloc
92{
93    [fKeyStrokes release];
94    [fMenuTorrent release];
95   
96    [super dealloc];
97}
98
99- (void) setTorrents: (NSArray *) torrents
100{
101    fTorrents = torrents;
102}
103
104- (void) tableView: (NSTableView *) tableView willDisplayCell: (id) cell
105        forTableColumn: (NSTableColumn *) tableColumn row: (int) row
106{
107    [cell setRepresentedObject: [fTorrents objectAtIndex: row]];
108}
109
110
111- (NSString *) tableView: (NSTableView *) tableView typeSelectStringForTableColumn: (NSTableColumn *) tableColumn row: (int) row
112{
113    return [[fTorrents objectAtIndex: row] name];
114}
115
116- (void) mouseDown: (NSEvent *) event
117{
118    //NSLog(@"down");
119    fClickPoint = [self convertPoint: [event locationInWindow] fromView: nil];
120
121    if ([self pointInActionRect: fClickPoint])
122    {
123        int row = [self rowAtPoint: fClickPoint];
124        [self setNeedsDisplayInRect: [self rectOfRow: row]]; //ensure button is pushed down
125       
126        [self displayTorrentMenuForEvent: event];
127       
128        fClickPoint = NSZeroPoint;
129        [self setNeedsDisplayInRect: [self rectOfRow: row]];
130    }
131    else if ([self pointInPauseRect: fClickPoint] || [self pointInRevealRect: fClickPoint])
132    {
133        fClickIn = YES;
134        [self setNeedsDisplayInRect: [self rectOfRow: [self rowAtPoint: fClickPoint]]];
135    }
136    else
137    {
138        if (/*[event modifierFlags] & NSAlternateKeyMask*/NO)
139        {
140            [fDefaults setBool: ![fDefaults boolForKey: @"UseAdvancedBar"] forKey: @"UseAdvancedBar"];
141            fClickPoint = NSZeroPoint;
142            [self reloadData];
143        }
144        else
145        {
146            if ([self pointInMinimalStatusRect: fClickPoint])
147            {
148                [fDefaults setBool: ![fDefaults boolForKey: @"DisplaySmallStatusRegular"] forKey: @"DisplaySmallStatusRegular"];
149                fClickPoint = NSZeroPoint;
150                [self reloadData];
151            }
152
153            [super mouseDown: event];
154        }
155    }
156}
157
158#warning not always working
159- (void) mouseUp: (NSEvent *) event
160{
161    //NSLog(@"up");
162    NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil];
163    int row = [self rowAtPoint: point], oldRow = [self rowAtPoint: fClickPoint];
164   
165    if (row == oldRow && [self pointInPauseRect: point] && [self pointInPauseRect: fClickPoint])
166    {
167        Torrent * torrent = [fTorrents objectAtIndex: row];
168       
169        if ([torrent isActive])
170            [fController stopTorrents: [NSArray arrayWithObject: torrent]];
171        else
172        {
173            if ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask)
174                [fController resumeTorrentsNoWait: [NSArray arrayWithObject: torrent]];
175            else if ([torrent waitingToStart])
176                [fController stopTorrents: [NSArray arrayWithObject: torrent]];
177            else
178                [fController resumeTorrents: [NSArray arrayWithObject: torrent]];
179        }
180    }
181    else if (row == oldRow && [self pointInRevealRect: point] && [self pointInRevealRect: fClickPoint])
182        [[fTorrents objectAtIndex: row] revealData];
183    else if ([event clickCount] == 2 && !NSEqualPoints(fClickPoint, NSZeroPoint))
184    {
185        if ([self pointInProgressRect: fClickPoint])
186        {
187            [fDefaults setBool: ![fDefaults boolForKey: @"DisplayStatusProgressSelected"] forKey: @"DisplayStatusProgressSelected"];
188            [self reloadData];
189        }
190        else if ([self pointInIconRect: point])
191            [[fTorrents objectAtIndex: row] revealData];
192        else if (![self pointInActionRect: point])
193            [fController showInfo: nil];
194        else;
195    }
196    else;
197   
198    [super mouseUp: event];
199
200    fClickPoint = NSZeroPoint;
201    fClickIn = NO;
202    [self setNeedsDisplayInRect: [self rectOfRow: oldRow]];
203}
204
205- (void) mouseDragged: (NSEvent *) event
206{
207    if (NSEqualPoints(fClickPoint, NSZeroPoint))
208    {
209        [super mouseDragged: event];
210        return;
211    }
212   
213    NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil];
214    int oldRow = [self rowAtPoint: fClickPoint];
215   
216    BOOL inRect;
217    if ([self pointInRevealRect: fClickPoint])
218        inRect = oldRow == [self rowAtPoint: point] && [self pointInRevealRect: point];
219    else if ([self pointInPauseRect: fClickPoint])
220        inRect = oldRow == [self rowAtPoint: point] && [self pointInPauseRect: point];
221    else
222    {
223        [super mouseDragged: event];
224        return;
225    }
226   
227    if (inRect != fClickIn)
228    {
229        fClickIn = inRect;
230        [self setNeedsDisplayInRect: [self rectOfRow: oldRow]];
231    }
232}
233
234- (NSMenu *) menuForEvent: (NSEvent *) event
235{
236    int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
237   
238    if (row >= 0)
239    {
240        if (![self isRowSelected: row])
241            [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO];
242        return fContextRow;
243    }
244    else
245    {
246        [self deselectAll: self];
247        return fContextNoRow;
248    }
249}
250
251- (void) flagsChanged: (NSEvent *) event
252{
253    [self display];
254    [super flagsChanged: event];
255}
256
257- (void) keyDown: (NSEvent *) event
258{
259    //this is handled by the delegate in Leopard
260    if ([NSApp isOnLeopardOrBetter])
261    {
262        [super keyDown: event];
263        return;
264    }
265   
266    if (!fKeyStrokes)
267        fKeyStrokes = [[NSMutableArray alloc] init];
268   
269    unichar newChar = [[event characters] characterAtIndex: 0];
270    if (newChar == ' ' || [[NSCharacterSet alphanumericCharacterSet] characterIsMember: newChar]
271        || [[NSCharacterSet symbolCharacterSet] characterIsMember: newChar]
272        || [[NSCharacterSet punctuationCharacterSet] characterIsMember: newChar])
273    {
274        if ([fKeyStrokes count] > 0 && [event timestamp] - [[fKeyStrokes lastObject] timestamp] > 1.0)
275            [fKeyStrokes removeAllObjects];
276        [fKeyStrokes addObject: event];
277   
278        [self interpretKeyEvents: fKeyStrokes];
279    }
280    else
281    {
282        [fKeyStrokes removeAllObjects];
283        [super keyDown: event];
284    }
285}
286
287- (void) insertText: (NSString *) text
288{
289    //this is handled by the delegate in Leopard
290    if ([NSApp isOnLeopardOrBetter])
291    {
292        [super insertText: text];
293        return;
294    }
295   
296    //sort torrents by name before finding closest match
297    NSSortDescriptor * nameDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: YES
298                                            selector: @selector(caseInsensitiveCompare:)] autorelease];
299    NSArray * descriptors = [[NSArray alloc] initWithObjects: nameDescriptor, nil];
300
301    NSArray * tempTorrents = [fTorrents sortedArrayUsingDescriptors: descriptors];
302    [descriptors release];
303   
304    text = [text lowercaseString];
305   
306    //select torrent closest to text that isn't before text alphabetically
307    int row;
308    NSEnumerator * enumerator = [tempTorrents objectEnumerator];
309    Torrent * torrent;
310    while ((torrent = [enumerator nextObject]))
311        if ([[[torrent name] lowercaseString] hasPrefix: text])
312        {
313            row = [fTorrents indexOfObject: torrent];
314            break;
315        }
316   
317    //select last torrent alphabetically if no match found
318    if (!torrent)
319        row = [fTorrents indexOfObject: [tempTorrents lastObject]];
320   
321    [self selectRow: row byExtendingSelection: NO];
322    [self scrollRowToVisible: row];
323}
324
325- (void) displayTorrentMenuForEvent: (NSEvent *) event
326{
327    int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
328    if (row < 0)
329        return;
330   
331    //get and update file menu
332    fMenuTorrent = [[fTorrents objectAtIndex: row] retain];
333    NSMenu * fileMenu = [fMenuTorrent fileMenu];
334    [self updateFileMenu: fileMenu forFiles: [fMenuTorrent fileList]];
335   
336    //add file menu items to action menu
337    NSRange range = NSMakeRange(0, [fileMenu numberOfItems]);
338    [fActionMenu appendItemsFromMenu: fileMenu atIndexes: [NSIndexSet indexSetWithIndexesInRange: range]];
339   
340    //place menu below button
341    NSRect rect = [self actionRectForRow: row];
342    NSPoint location = rect.origin;
343    location.y += rect.size.height + 5.0;
344    location = [self convertPoint: location toView: nil];
345   
346    NSEvent * newEvent = [NSEvent mouseEventWithType: [event type] location: location
347        modifierFlags: [event modifierFlags] timestamp: [event timestamp] windowNumber: [event windowNumber]
348        context: [event context] eventNumber: [event eventNumber] clickCount: [event clickCount] pressure: [event pressure]];
349   
350    [NSMenu popUpContextMenu: fActionMenu withEvent: newEvent forView: self];
351   
352    //move file menu items back to the torrent's file menu
353    range.location = [fActionMenu numberOfItems] - range.length;
354    [fileMenu appendItemsFromMenu: fActionMenu atIndexes: [NSIndexSet indexSetWithIndexesInRange: range]];
355   
356    [fMenuTorrent release];
357    fMenuTorrent = nil;
358}
359
360- (void) menuNeedsUpdate: (NSMenu *) menu
361{
362    //this method seems to be called when it shouldn't be
363    if (!fMenuTorrent || ![menu supermenu])
364        return;
365   
366    if (menu == fUploadMenu || menu == fDownloadMenu)
367    {
368        BOOL upload = menu == fUploadMenu;
369        int mode = [fMenuTorrent speedMode: upload];
370       
371        NSMenuItem * item = [menu itemWithTag: ACTION_MENU_LIMIT_TAG];
372        [item setState: mode == TR_SPEEDLIMIT_SINGLE ? NSOnState : NSOffState];
373        [item setTitle: [NSString stringWithFormat: NSLocalizedString(@"Limit (%d KB/s)",
374                    "torrent action context menu -> upload/download limit"), [fMenuTorrent speedLimit: upload]]];
375       
376        item = [menu itemWithTag: ACTION_MENU_UNLIMITED_TAG];
377        [item setState: mode == TR_SPEEDLIMIT_UNLIMITED ? NSOnState : NSOffState];
378       
379        item = [menu itemWithTag: ACTION_MENU_GLOBAL_TAG];
380        [item setState: mode == TR_SPEEDLIMIT_GLOBAL ? NSOnState : NSOffState];
381    }
382    else if (menu == fRatioMenu)
383    {
384        int mode = [fMenuTorrent ratioSetting];
385       
386        NSMenuItem * item = [menu itemWithTag: ACTION_MENU_LIMIT_TAG];
387        [item setState: mode == NSOnState ? NSOnState : NSOffState];
388        [item setTitle: [NSString stringWithFormat: NSLocalizedString(@"Stop at Ratio (%.2f)",
389                    "torrent action context menu -> ratio stop"), [fMenuTorrent ratioLimit]]];
390       
391        item = [menu itemWithTag: ACTION_MENU_UNLIMITED_TAG];
392        [item setState: mode == NSOffState ? NSOnState : NSOffState];
393       
394        item = [menu itemWithTag: ACTION_MENU_GLOBAL_TAG];
395        [item setState: mode == NSMixedState ? NSOnState : NSOffState];
396    }
397    else if ([menu supermenu]) //assume the menu is part of the file list
398    {
399        NSMenu * supermenu = [menu supermenu];
400        [self updateFileMenu: menu forFiles: [[[supermenu itemAtIndex: [supermenu indexOfItemWithSubmenu: menu]]
401                                                    representedObject] objectForKey: @"Children"]];
402    }
403    else;
404}
405
406- (void) setQuickLimitMode: (id) sender
407{
408    int mode;
409    switch ([sender tag])
410    {
411        case ACTION_MENU_UNLIMITED_TAG:
412            mode = TR_SPEEDLIMIT_UNLIMITED;
413            break;
414        case ACTION_MENU_LIMIT_TAG:
415            mode = TR_SPEEDLIMIT_SINGLE;
416            break;
417        case ACTION_MENU_GLOBAL_TAG:
418            mode = TR_SPEEDLIMIT_GLOBAL;
419            break;
420        default:
421            return;
422    }
423   
424    [fMenuTorrent setSpeedMode: mode upload: [sender menu] == fUploadMenu];
425   
426    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateStats" object: nil];
427}
428
429- (void) setQuickLimit: (id) sender
430{
431    BOOL upload = [sender menu] == fUploadMenu;
432    [fMenuTorrent setSpeedMode: TR_SPEEDLIMIT_SINGLE upload: upload];
433    [fMenuTorrent setSpeedLimit: [[sender title] intValue] upload: upload];
434   
435    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateStats" object: nil];
436}
437
438- (void) setQuickRatioMode: (id) sender
439{
440    int mode;
441    switch ([sender tag])
442    {
443        case ACTION_MENU_UNLIMITED_TAG:
444            mode = NSOffState;
445            break;
446        case ACTION_MENU_LIMIT_TAG:
447            mode = NSOnState;
448            break;
449        case ACTION_MENU_GLOBAL_TAG:
450            mode = NSMixedState;
451            break;
452        default:
453            return;
454    }
455   
456    [fMenuTorrent setRatioSetting: mode];
457   
458    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateStats" object: nil];
459}
460
461- (void) setQuickRatio: (id) sender
462{
463    [fMenuTorrent setRatioSetting: NSOnState];
464    [fMenuTorrent setRatioLimit: [[sender title] floatValue]];
465   
466    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateStats" object: nil];
467}
468
469- (void) checkFile: (id) sender
470{
471    NSIndexSet * indexSet = [[sender representedObject] objectForKey: @"Indexes"];
472    [fMenuTorrent setFileCheckState: [sender state] != NSOnState ? NSOnState : NSOffState forIndexes: indexSet];
473   
474    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateStats" object: nil];
475}
476
477- (void) drawRow: (int) row clipRect: (NSRect) rect
478{
479    [super drawRow: row clipRect: rect];
480   
481    Torrent * torrent = [fTorrents objectAtIndex: row];
482   
483    //pause/resume icon
484    NSImage * pauseImage = nil;
485    NSRect pauseRect  = [self pauseRectForRow: row];
486    if ([torrent isActive])
487        pauseImage = fClickIn && NSPointInRect(fClickPoint, pauseRect) ? fPauseOnIcon : fPauseOffIcon;
488    else
489    {
490        BOOL inPauseRect = fClickIn && NSPointInRect(fClickPoint, pauseRect);
491        if ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask && [fDefaults boolForKey: @"Queue"])
492            pauseImage = inPauseRect ? fResumeNoWaitOnIcon : fResumeNoWaitOffIcon;
493        else if ([torrent waitingToStart])
494            pauseImage = inPauseRect ? fPauseOnIcon : fPauseOffIcon;
495        else
496            pauseImage = inPauseRect ? fResumeOnIcon : fResumeOffIcon;
497    }
498   
499    if (pauseImage)
500        [pauseImage compositeToPoint: NSMakePoint(pauseRect.origin.x, NSMaxY(pauseRect)) operation: NSCompositeSourceOver];
501   
502    //reveal icon
503    NSRect revealRect = [self revealRectForRow: row];
504    NSImage * revealImage = fClickIn && NSPointInRect(fClickPoint, revealRect) ? fRevealOnIcon : fRevealOffIcon;
505    [revealImage compositeToPoint: NSMakePoint(revealRect.origin.x, NSMaxY(revealRect)) operation: NSCompositeSourceOver];
506   
507    //action icon
508    if (![fDefaults boolForKey: @"SmallView"])
509    {
510        NSRect actionRect = [self actionRectForRow: row];
511        NSImage * actionImage = NSPointInRect(fClickPoint, actionRect) ? fActionOnIcon : fActionOffIcon;
512        [actionImage compositeToPoint: NSMakePoint(actionRect.origin.x, NSMaxY(actionRect)) operation: NSCompositeSourceOver];
513    }
514}
515
516@end
517
518@implementation TorrentTableView (Private)
519
520- (NSRect) pauseRectForRow: (int) row
521{
522    if (row < 0)
523        return NSZeroRect;
524   
525    NSRect cellRect = [self frameOfCellAtColumn: 0 row: row];
526   
527    float buttonToTop = [fDefaults boolForKey: @"SmallView"] ? BUTTON_TO_TOP_SMALL : BUTTON_TO_TOP_REGULAR;
528   
529    return NSMakeRect(NSMaxX(cellRect) - PADDING - BUTTON_WIDTH - PADDING - BUTTON_WIDTH,
530                        cellRect.origin.y + buttonToTop, BUTTON_WIDTH, BUTTON_WIDTH);
531}
532
533- (NSRect) revealRectForRow: (int) row
534{
535    if (row < 0)
536        return NSZeroRect;
537   
538    NSRect cellRect = [self frameOfCellAtColumn: 0 row: row];
539   
540    float buttonToTop = [fDefaults boolForKey: @"SmallView"] ? BUTTON_TO_TOP_SMALL : BUTTON_TO_TOP_REGULAR;
541   
542    return NSMakeRect(NSMaxX(cellRect) - PADDING - BUTTON_WIDTH,
543                        cellRect.origin.y + buttonToTop, BUTTON_WIDTH, BUTTON_WIDTH);
544}
545
546- (NSRect) actionRectForRow: (int) row
547{
548    if (row < 0)
549        return NSZeroRect;
550   
551    TorrentCell * cell = [[self tableColumnWithIdentifier: @"Torrent"] dataCell];
552    NSRect cellRect = [self frameOfCellAtColumn: 0 row: row],
553            iconRect = [cell iconRectForBounds: cellRect];
554   
555    if ([fDefaults boolForKey: @"SmallView"])
556        return iconRect;
557    else
558        return NSMakeRect(iconRect.origin.x + (iconRect.size.width - ACTION_BUTTON_WIDTH) * 0.5,
559                        cellRect.origin.y + ACTION_BUTTON_TO_TOP, ACTION_BUTTON_WIDTH, ACTION_BUTTON_HEIGHT);
560}
561
562- (BOOL) pointInIconRect: (NSPoint) point
563{
564    int row = [self rowAtPoint: point];
565    if (row < 0)
566        return NO;
567   
568    TorrentCell * cell = [[self tableColumnWithIdentifier: @"Torrent"] dataCell];
569    return NSPointInRect(point, [cell iconRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
570}
571
572- (BOOL) pointInProgressRect: (NSPoint) point
573{
574    int row = [self rowAtPoint: point];
575    if (row < 0 || [fDefaults boolForKey: @"SmallView"])
576        return NO;
577   
578    TorrentCell * cell = [[self tableColumnWithIdentifier: @"Torrent"] dataCell];
579    [cell setRepresentedObject: [fTorrents objectAtIndex: row]];
580    return NSPointInRect(point, [cell progressRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
581}
582
583- (BOOL) pointInMinimalStatusRect: (NSPoint) point
584{
585    int row = [self rowAtPoint: point];
586    if (row < 0 || ![fDefaults boolForKey: @"SmallView"])
587        return NO;
588   
589    TorrentCell * cell = [[self tableColumnWithIdentifier: @"Torrent"] dataCell];
590    [cell setRepresentedObject: [fTorrents objectAtIndex: row]];
591    return NSPointInRect(point, [cell minimalStatusRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
592}
593
594- (BOOL) pointInPauseRect: (NSPoint) point
595{
596    int row = [self rowAtPoint: point];
597    if (row < 0)
598        return NO;
599   
600    return NSPointInRect(point, [self pauseRectForRow: row]);
601}
602
603- (BOOL) pointInRevealRect: (NSPoint) point
604{
605    int row = [self rowAtPoint: point];
606    if (row < 0)
607        return NO;
608   
609    return NSPointInRect(point, [self revealRectForRow: row]);
610}
611
612- (BOOL) pointInActionRect: (NSPoint) point
613{
614    int row = [self rowAtPoint: point];
615    if (row < 0)
616        return NO;
617   
618    return NSPointInRect(point, [self actionRectForRow: row]);
619}
620
621- (void) updateFileMenu: (NSMenu *) menu forFiles: (NSArray *) files
622{
623    BOOL create = [menu numberOfItems] <= 0;
624   
625    NSEnumerator * enumerator = [files objectEnumerator];
626    NSDictionary * dict;
627    NSMenuItem * item;
628    while ((dict = [enumerator nextObject]))
629    {
630        NSString * name = [dict objectForKey: @"Name"];
631       
632        if (create)
633        {
634            item = [[NSMenuItem alloc] initWithTitle: name action: NULL keyEquivalent: @""];
635           
636            NSImage * icon;
637            if (![[dict objectForKey: @"IsFolder"] boolValue])
638            {
639                icon = [[dict objectForKey: @"Icon"] copy];
640                [icon setFlipped: NO];
641            }
642            else
643            {
644                NSMenu * itemMenu = [[NSMenu alloc] initWithTitle: name];
645                [itemMenu setAutoenablesItems: NO];
646                [item setSubmenu: itemMenu];
647                [itemMenu setDelegate: self];
648                [itemMenu release];
649               
650                icon = [[[NSWorkspace sharedWorkspace] iconForFileType: NSFileTypeForHFSTypeCode('fldr')] copy];
651            }
652           
653            [item setRepresentedObject: dict];
654           
655            [icon setScalesWhenResized: YES];
656            [icon setSize: NSMakeSize(16.0, 16.0)];
657            [item setImage: icon];
658            [icon release];
659           
660            [item setAction: @selector(checkFile:)];
661           
662            [menu addItem: item];
663            [item release];
664        }
665        else
666            item = [menu itemWithTitle: name];
667       
668        NSIndexSet * indexSet = [dict objectForKey: @"Indexes"];
669        [item setState: [fMenuTorrent checkForFiles: indexSet]];
670        [item setEnabled: [fMenuTorrent canChangeDownloadCheckForFiles: indexSet]];
671    }
672}
673
674@end
Note: See TracBrowser for help on using the repository browser.