source: trunk/macosx/TorrentTableView.m @ 4032

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

adjust per-torrent action button placement

  • Property svn:keywords set to Date Rev Author Id
File size: 21.8 KB
Line 
1/******************************************************************************
2 * $Id: TorrentTableView.m 4032 2007-12-01 16:23:29Z 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 44.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- (NSString *) tableView: (NSTableView *) tableView typeSelectStringForTableColumn: (NSTableColumn *) tableColumn row: (int) row
98{
99    return [[fTorrents objectAtIndex: row] name];
100}
101
102- (void) mouseDown: (NSEvent *) event
103{
104    fClickPoint = [self convertPoint: [event locationInWindow] fromView: nil];
105
106    if ([self pointInActionRect: fClickPoint])
107    {
108        int row = [self rowAtPoint: fClickPoint];
109        [self setNeedsDisplayInRect: [self rectOfRow: row]]; //ensure button is pushed down
110       
111        [self displayTorrentMenuForEvent: event];
112       
113        fClickPoint = NSZeroPoint;
114        [self setNeedsDisplayInRect: [self rectOfRow: row]];
115    }
116    else if ([self pointInPauseRect: fClickPoint] || [self pointInRevealRect: fClickPoint])
117    {
118        fClickIn = YES;
119        [self setNeedsDisplayInRect: [self rectOfRow: [self rowAtPoint: fClickPoint]]];
120    }
121    else
122    {
123        if ([self pointInMinimalStatusRect: fClickPoint])
124        {
125            [fDefaults setBool: ![fDefaults boolForKey: @"DisplaySmallStatusRegular"] forKey: @"DisplaySmallStatusRegular"];
126            fClickPoint = NSZeroPoint;
127            [self reloadData];
128        }
129
130        [super mouseDown: event];
131    }
132}
133
134#warning not working on Leopard
135- (void) mouseUp: (NSEvent *) event
136{
137    //NSLog(@"up");
138    NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil];
139    int row = [self rowAtPoint: point], oldRow = [self rowAtPoint: fClickPoint];
140   
141    if (row == oldRow && [self pointInPauseRect: point] && [self pointInPauseRect: fClickPoint])
142    {
143        Torrent * torrent = [fTorrents objectAtIndex: row];
144       
145        if ([torrent isActive])
146            [fController stopTorrents: [NSArray arrayWithObject: torrent]];
147        else
148        {
149            if ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask)
150                [fController resumeTorrentsNoWait: [NSArray arrayWithObject: torrent]];
151            else if ([torrent waitingToStart])
152                [fController stopTorrents: [NSArray arrayWithObject: torrent]];
153            else
154                [fController resumeTorrents: [NSArray arrayWithObject: torrent]];
155        }
156    }
157    else if (row == oldRow && [self pointInRevealRect: point] && [self pointInRevealRect: fClickPoint])
158        [[fTorrents objectAtIndex: row] revealData];
159    else if ([event clickCount] == 2 && !NSEqualPoints(fClickPoint, NSZeroPoint))
160    {
161        if ([self pointInProgressRect: fClickPoint])
162        {
163            [fDefaults setBool: ![fDefaults boolForKey: @"DisplayStatusProgressSelected"] forKey: @"DisplayStatusProgressSelected"];
164            [self reloadData];
165        }
166        else if ([self pointInIconRect: point])
167            [[fTorrents objectAtIndex: row] revealData];
168        else if (![self pointInActionRect: point])
169            [fController showInfo: nil];
170        else;
171    }
172    else;
173   
174    [super mouseUp: event];
175
176    fClickPoint = NSZeroPoint;
177    fClickIn = NO;
178    [self setNeedsDisplayInRect: [self rectOfRow: oldRow]];
179}
180
181- (void) mouseDragged: (NSEvent *) event
182{
183    if (NSEqualPoints(fClickPoint, NSZeroPoint))
184    {
185        [super mouseDragged: event];
186        return;
187    }
188   
189    NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil];
190    int oldRow = [self rowAtPoint: fClickPoint];
191   
192    BOOL inRect;
193    if ([self pointInRevealRect: fClickPoint])
194        inRect = oldRow == [self rowAtPoint: point] && [self pointInRevealRect: point];
195    else if ([self pointInPauseRect: fClickPoint])
196        inRect = oldRow == [self rowAtPoint: point] && [self pointInPauseRect: point];
197    else
198    {
199        [super mouseDragged: event];
200        return;
201    }
202   
203    if (inRect != fClickIn)
204    {
205        fClickIn = inRect;
206        [self setNeedsDisplayInRect: [self rectOfRow: oldRow]];
207    }
208}
209
210- (NSMenu *) menuForEvent: (NSEvent *) event
211{
212    int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
213   
214    if (row >= 0)
215    {
216        if (![self isRowSelected: row])
217            [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO];
218        return fContextRow;
219    }
220    else
221    {
222        [self deselectAll: self];
223        return fContextNoRow;
224    }
225}
226
227- (void) flagsChanged: (NSEvent *) event
228{
229    [self display];
230    [super flagsChanged: event];
231}
232
233- (void) keyDown: (NSEvent *) event
234{
235    //this is handled by the delegate in Leopard
236    if ([NSApp isOnLeopardOrBetter])
237    {
238        [super keyDown: event];
239        return;
240    }
241   
242    if (!fKeyStrokes)
243        fKeyStrokes = [[NSMutableArray alloc] init];
244   
245    unichar newChar = [[event characters] characterAtIndex: 0];
246    if (newChar == ' ' || [[NSCharacterSet alphanumericCharacterSet] characterIsMember: newChar]
247        || [[NSCharacterSet symbolCharacterSet] characterIsMember: newChar]
248        || [[NSCharacterSet punctuationCharacterSet] characterIsMember: newChar])
249    {
250        if ([fKeyStrokes count] > 0 && [event timestamp] - [[fKeyStrokes lastObject] timestamp] > 1.0)
251            [fKeyStrokes removeAllObjects];
252        [fKeyStrokes addObject: event];
253   
254        [self interpretKeyEvents: fKeyStrokes];
255    }
256    else
257    {
258        [fKeyStrokes removeAllObjects];
259        [super keyDown: event];
260    }
261}
262
263- (void) insertText: (NSString *) text
264{
265    //this is handled by the delegate in Leopard
266    if ([NSApp isOnLeopardOrBetter])
267    {
268        [super insertText: text];
269        return;
270    }
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    text = [text lowercaseString];
281   
282    //select torrent closest to text that isn't before text alphabetically
283    NSEnumerator * enumerator = [tempTorrents objectEnumerator];
284    Torrent * torrent;
285    while ((torrent = [enumerator nextObject]))
286        if ([[[torrent name] lowercaseString] hasPrefix: text])
287        {
288            int row = [fTorrents indexOfObject: torrent];
289            [self selectRow: row byExtendingSelection: NO];
290            [self scrollRowToVisible: row];
291            return;
292        }
293}
294
295- (void) displayTorrentMenuForEvent: (NSEvent *) event
296{
297    int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
298    if (row < 0)
299        return;
300   
301    //get and update file menu
302    fMenuTorrent = [[fTorrents objectAtIndex: row] retain];
303    NSMenu * fileMenu = [fMenuTorrent fileMenu];
304    [self updateFileMenu: fileMenu forFiles: [fMenuTorrent fileList]];
305   
306    //add file menu items to action menu
307    NSRange range = NSMakeRange(0, [fileMenu numberOfItems]);
308    [fActionMenu appendItemsFromMenu: fileMenu atIndexes: [NSIndexSet indexSetWithIndexesInRange: range]];
309   
310    //place menu below button
311    NSRect rect = [self actionRectForRow: row];
312    NSPoint location = rect.origin;
313    location.y += rect.size.height + 5.0;
314    location = [self convertPoint: location toView: nil];
315   
316    NSEvent * newEvent = [NSEvent mouseEventWithType: [event type] location: location
317        modifierFlags: [event modifierFlags] timestamp: [event timestamp] windowNumber: [event windowNumber]
318        context: [event context] eventNumber: [event eventNumber] clickCount: [event clickCount] pressure: [event pressure]];
319   
320    [NSMenu popUpContextMenu: fActionMenu withEvent: newEvent forView: self];
321   
322    //move file menu items back to the torrent's file menu
323    range.location = [fActionMenu numberOfItems] - range.length;
324    [fileMenu appendItemsFromMenu: fActionMenu atIndexes: [NSIndexSet indexSetWithIndexesInRange: range]];
325   
326    [fMenuTorrent release];
327    fMenuTorrent = nil;
328}
329
330- (void) menuNeedsUpdate: (NSMenu *) menu
331{
332    //this method seems to be called when it shouldn't be
333    if (!fMenuTorrent || ![menu supermenu])
334        return;
335   
336    if (menu == fUploadMenu || menu == fDownloadMenu)
337    {
338        BOOL upload = menu == fUploadMenu;
339        int mode = [fMenuTorrent speedMode: upload];
340       
341        NSMenuItem * item = [menu itemWithTag: ACTION_MENU_LIMIT_TAG];
342        [item setState: mode == TR_SPEEDLIMIT_SINGLE ? NSOnState : NSOffState];
343        [item setTitle: [NSString stringWithFormat: NSLocalizedString(@"Limit (%d KB/s)",
344                    "torrent action context menu -> upload/download limit"), [fMenuTorrent speedLimit: upload]]];
345       
346        item = [menu itemWithTag: ACTION_MENU_UNLIMITED_TAG];
347        [item setState: mode == TR_SPEEDLIMIT_UNLIMITED ? NSOnState : NSOffState];
348       
349        item = [menu itemWithTag: ACTION_MENU_GLOBAL_TAG];
350        [item setState: mode == TR_SPEEDLIMIT_GLOBAL ? NSOnState : NSOffState];
351    }
352    else if (menu == fRatioMenu)
353    {
354        int mode = [fMenuTorrent ratioSetting];
355       
356        NSMenuItem * item = [menu itemWithTag: ACTION_MENU_LIMIT_TAG];
357        [item setState: mode == NSOnState ? NSOnState : NSOffState];
358        [item setTitle: [NSString stringWithFormat: NSLocalizedString(@"Stop at Ratio (%.2f)",
359                    "torrent action context menu -> ratio stop"), [fMenuTorrent ratioLimit]]];
360       
361        item = [menu itemWithTag: ACTION_MENU_UNLIMITED_TAG];
362        [item setState: mode == NSOffState ? NSOnState : NSOffState];
363       
364        item = [menu itemWithTag: ACTION_MENU_GLOBAL_TAG];
365        [item setState: mode == NSMixedState ? NSOnState : NSOffState];
366    }
367    else if ([menu supermenu]) //assume the menu is part of the file list
368    {
369        NSMenu * supermenu = [menu supermenu];
370        [self updateFileMenu: menu forFiles: [[[supermenu itemAtIndex: [supermenu indexOfItemWithSubmenu: menu]]
371                                                    representedObject] objectForKey: @"Children"]];
372    }
373    else;
374}
375
376- (void) setQuickLimitMode: (id) sender
377{
378    int mode;
379    switch ([sender tag])
380    {
381        case ACTION_MENU_UNLIMITED_TAG:
382            mode = TR_SPEEDLIMIT_UNLIMITED;
383            break;
384        case ACTION_MENU_LIMIT_TAG:
385            mode = TR_SPEEDLIMIT_SINGLE;
386            break;
387        case ACTION_MENU_GLOBAL_TAG:
388            mode = TR_SPEEDLIMIT_GLOBAL;
389            break;
390        default:
391            return;
392    }
393   
394    [fMenuTorrent setSpeedMode: mode upload: [sender menu] == fUploadMenu];
395   
396    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptions" object: nil];
397}
398
399- (void) setQuickLimit: (id) sender
400{
401    BOOL upload = [sender menu] == fUploadMenu;
402    [fMenuTorrent setSpeedMode: TR_SPEEDLIMIT_SINGLE upload: upload];
403    [fMenuTorrent setSpeedLimit: [[sender title] intValue] upload: upload];
404   
405    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptions" object: nil];
406}
407
408- (void) setQuickRatioMode: (id) sender
409{
410    int mode;
411    switch ([sender tag])
412    {
413        case ACTION_MENU_UNLIMITED_TAG:
414            mode = NSOffState;
415            break;
416        case ACTION_MENU_LIMIT_TAG:
417            mode = NSOnState;
418            break;
419        case ACTION_MENU_GLOBAL_TAG:
420            mode = NSMixedState;
421            break;
422        default:
423            return;
424    }
425   
426    [fMenuTorrent setRatioSetting: mode];
427   
428    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptions" object: nil];
429}
430
431- (void) setQuickRatio: (id) sender
432{
433    [fMenuTorrent setRatioSetting: NSOnState];
434    [fMenuTorrent setRatioLimit: [[sender title] floatValue]];
435   
436    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptions" object: nil];
437}
438
439- (void) checkFile: (id) sender
440{
441    NSIndexSet * indexSet = [[sender representedObject] objectForKey: @"Indexes"];
442    [fMenuTorrent setFileCheckState: [sender state] != NSOnState ? NSOnState : NSOffState forIndexes: indexSet];
443   
444    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateStats" object: nil];
445}
446
447- (void) drawRow: (int) row clipRect: (NSRect) rect
448{
449    [super drawRow: row clipRect: rect];
450   
451    Torrent * torrent = [fTorrents objectAtIndex: row];
452   
453    //pause/resume icon
454    NSImage * pauseImage = nil;
455    NSRect pauseRect  = [self pauseRectForRow: row];
456    if ([torrent isActive])
457        pauseImage = fClickIn && NSPointInRect(fClickPoint, pauseRect) ? [NSImage imageNamed: @"PauseOn.png"]
458                                                                        : [NSImage imageNamed: @"PauseOff.png"];
459    else
460    {
461        BOOL inPauseRect = fClickIn && NSPointInRect(fClickPoint, pauseRect);
462        if ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask && [fDefaults boolForKey: @"Queue"])
463            pauseImage = inPauseRect ? [NSImage imageNamed: @"ResumeNoWaitOn.png"] : [NSImage imageNamed: @"ResumeNoWaitOff.png"];
464        else if ([torrent waitingToStart])
465            pauseImage = inPauseRect ? [NSImage imageNamed: @"PauseOn.png"] : [NSImage imageNamed: @"PauseOff.png"];
466        else
467            pauseImage = inPauseRect ? [NSImage imageNamed: @"ResumeOn.png"] : [NSImage imageNamed: @"ResumeOff.png"];
468    }
469   
470    if (pauseImage)
471        [pauseImage compositeToPoint: NSMakePoint(pauseRect.origin.x, NSMaxY(pauseRect)) operation: NSCompositeSourceOver];
472   
473    //reveal icon
474    NSRect revealRect = [self revealRectForRow: row];
475    NSImage * revealImage = fClickIn && NSPointInRect(fClickPoint, revealRect) ? [NSImage imageNamed: @"RevealOn.png"]
476                                                                                : [NSImage imageNamed: @"RevealOff.png"];
477    [revealImage compositeToPoint: NSMakePoint(revealRect.origin.x, NSMaxY(revealRect)) operation: NSCompositeSourceOver];
478   
479    //action icon
480    if (![fDefaults boolForKey: @"SmallView"])
481    {
482        NSRect actionRect = [self actionRectForRow: row];
483        NSImage * actionImage = NSPointInRect(fClickPoint, actionRect) ? [NSImage imageNamed: @"ActionOn.png"]
484                                                                        : [NSImage imageNamed: @"ActionOff.png"];
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                icon = [[NSWorkspace sharedWorkspace] iconForFileType: [name pathExtension]];
612            else
613            {
614                NSMenu * itemMenu = [[NSMenu alloc] initWithTitle: name];
615                [itemMenu setAutoenablesItems: NO];
616                [item setSubmenu: itemMenu];
617                [itemMenu setDelegate: self];
618                [itemMenu release];
619               
620                icon = [[NSWorkspace sharedWorkspace] iconForFileType: NSFileTypeForHFSTypeCode('fldr')];
621            }
622           
623            [item setRepresentedObject: dict];
624           
625            [icon setScalesWhenResized: YES];
626            [icon setSize: NSMakeSize(16.0, 16.0)];
627            [item setImage: icon];
628           
629            [item setAction: @selector(checkFile:)];
630           
631            [menu addItem: item];
632            [item release];
633        }
634        else
635            item = [menu itemWithTitle: name];
636       
637        NSIndexSet * indexSet = [dict objectForKey: @"Indexes"];
638        [item setState: [fMenuTorrent checkForFiles: indexSet]];
639        [item setEnabled: [fMenuTorrent canChangeDownloadCheckForFiles: indexSet]];
640    }
641}
642
643@end
Note: See TracBrowser for help on using the repository browser.