source: trunk/macosx/TorrentTableView.m @ 3485

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

eliminate the redundant isPaused, instead using !isActive

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