source: trunk/macosx/TorrentTableView.m @ 3193

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

say goodbye to the often-misunderstood "advanced progress bar"

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