source: trunk/macosx/TorrentTableView.m @ 3671

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

trunk: make status bar inactive when window isn't main window

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