source: trunk/macosx/TorrentTableView.m @ 2833

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

dynamically show the files for file selection in the top-level action menu

  • Property svn:keywords set to Date Rev Author Id
File size: 22.1 KB
Line 
1/******************************************************************************
2 * $Id: TorrentTableView.m 2833 2007-08-18 05:46:20Z 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
30#define PADDING 3.0
31
32#define BUTTON_TO_TOP_REGULAR 33.0
33#define BUTTON_TO_TOP_SMALL 20.0
34
35#define ACTION_BUTTON_TO_TOP 47.0
36
37#define ACTION_MENU_GLOBAL_TAG 101
38#define ACTION_MENU_UNLIMITED_TAG 102
39#define ACTION_MENU_LIMIT_TAG 103
40
41@interface TorrentTableView (Private)
42
43- (NSRect) pauseRectForRow: (int) row;
44- (NSRect) revealRectForRow: (int) row;
45- (NSRect) actionRectForRow: (int) row;
46
47- (BOOL) pointInIconRect: (NSPoint) point;
48- (BOOL) pointInMinimalStatusRect: (NSPoint) point;
49
50- (BOOL) pointInPauseRect: (NSPoint) point;
51- (BOOL) pointInRevealRect: (NSPoint) point;
52- (BOOL) pointInActionRect: (NSPoint) point;
53
54- (void) updateFileMenu: (NSMenu *) menu forFiles: (NSArray *) files;
55
56- (void) moveItemsFromMenu: (NSMenu *) oldMenu inRange: (NSRange) range toMenu: (NSMenu *) newMenu;
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        fKeyStrokes = [[NSMutableArray alloc] init];
83       
84        fSmallStatusAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
85                                        [NSFont messageFontOfSize: 9.0], NSFontAttributeName, nil];
86       
87        fDefaults = [NSUserDefaults standardUserDefaults];
88       
89        [self setDelegate: self];
90    }
91   
92    return self;
93}
94   
95- (void) awakeFromNib
96{
97    [fContextRow setTitle: @"Context"];
98    [fContextNoRow setTitle: @"Context"];
99}
100
101- (void) dealloc
102{
103    [fKeyStrokes release];
104    [fSmallStatusAttributes release];
105   
106    [fMenuTorrent release];
107   
108    [super dealloc];
109}
110
111- (void) setTorrents: (NSArray *) torrents
112{
113    fTorrents = torrents;
114}
115
116- (void) tableView: (NSTableView *) tableView willDisplayCell: (id) cell
117        forTableColumn: (NSTableColumn *) tableColumn row: (int) row
118{
119    [cell setRepresentedObject: [fTorrents objectAtIndex: row]];
120}
121
122- (void) mouseDown: (NSEvent *) event
123{
124    fClickPoint = [self convertPoint: [event locationInWindow] fromView: nil];
125
126    if ([self pointInActionRect: fClickPoint])
127    {
128        int row = [self rowAtPoint: fClickPoint];
129        [self setNeedsDisplayInRect: [self rectOfRow: row]]; //ensure button is pushed down
130       
131        [self displayTorrentMenuForEvent: event];
132       
133        fClickPoint = NSZeroPoint;
134        [self setNeedsDisplayInRect: [self rectOfRow: row]];
135    }
136    else if ([self pointInPauseRect: fClickPoint] || [self pointInRevealRect: fClickPoint])
137    {
138        fClickIn = YES;
139        [self setNeedsDisplayInRect: [self rectOfRow: [self rowAtPoint: fClickPoint]]];
140    }
141    else
142    {
143        if ([event modifierFlags] & NSAlternateKeyMask)
144        {
145            [fDefaults setBool: ![fDefaults boolForKey: @"UseAdvancedBar"] forKey: @"UseAdvancedBar"];
146            fClickPoint = NSZeroPoint;
147            [self reloadData];
148        }
149        else
150        {
151            if ([self pointInMinimalStatusRect: fClickPoint])
152            {
153                [fDefaults setBool: ![fDefaults boolForKey: @"SmallStatusRegular"] forKey: @"SmallStatusRegular"];
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    unichar newChar = [[event characters] characterAtIndex: 0];
255    if (newChar == ' ' || [[NSCharacterSet alphanumericCharacterSet] characterIsMember: newChar]
256        || [[NSCharacterSet symbolCharacterSet] characterIsMember: newChar]
257        || [[NSCharacterSet punctuationCharacterSet] characterIsMember: newChar])
258    {
259        if ([fKeyStrokes count] > 0 && [event timestamp] - [[fKeyStrokes lastObject] timestamp] > 1.0)
260            [fKeyStrokes removeAllObjects];
261        [fKeyStrokes addObject: event];
262   
263        [self interpretKeyEvents: fKeyStrokes];
264    }
265    else
266    {
267        if ([fKeyStrokes count] > 0)
268            [fKeyStrokes removeAllObjects];
269       
270        [super keyDown: event];
271    }
272}
273
274- (void) flagsChanged: (NSEvent *) event
275{
276    [self display];
277    [super flagsChanged: event];
278}
279
280- (void) insertText: (NSString *) text
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    //select torrent closest to text that isn't before text alphabetically
291    int row;
292    NSEnumerator * enumerator = [tempTorrents objectEnumerator];
293    Torrent * torrent;
294    while ((torrent = [enumerator nextObject]))
295        if ([[torrent name] caseInsensitiveCompare: text] != NSOrderedAscending)
296        {
297            row = [fTorrents indexOfObject: torrent];
298            break;
299        }
300   
301    //select last torrent alphabetically if no match found
302    if (!torrent)
303        row = [fTorrents indexOfObject: [tempTorrents lastObject]];
304   
305    [self selectRow: row byExtendingSelection: NO];
306    [self scrollRowToVisible: row];
307}
308
309- (void) displayTorrentMenuForEvent: (NSEvent *) event
310{
311    int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
312    if (row < 0)
313        return;
314   
315    //get and update file menu
316    fMenuTorrent = [[fTorrents objectAtIndex: row] retain];
317    NSMenu * fileMenu = [fMenuTorrent fileMenu];
318    [self updateFileMenu: fileMenu forFiles: [fMenuTorrent fileList]];
319   
320    //add file menu items to action menu
321    NSRange range = NSMakeRange(0, [fileMenu numberOfItems]);
322    [self moveItemsFromMenu: fileMenu inRange: range toMenu: fActionMenu];
323   
324    //place menu below button
325    NSRect rect = [self actionRectForRow: row];
326    NSPoint location = rect.origin;
327    location.y += rect.size.height + 5.0;
328    location = [self convertPoint: location toView: nil];
329   
330    NSEvent * newEvent = [NSEvent mouseEventWithType: [event type] location: location
331        modifierFlags: [event modifierFlags] timestamp: [event timestamp] windowNumber: [event windowNumber]
332        context: [event context] eventNumber: [event eventNumber] clickCount: [event clickCount] pressure: [event pressure]];
333   
334    [NSMenu popUpContextMenu: fActionMenu withEvent: newEvent forView: self];
335   
336    //move file menu items back to the torrent's file menu
337    range.location = [fActionMenu numberOfItems] - range.length;
338    [self moveItemsFromMenu: fActionMenu inRange: range toMenu: fileMenu];
339   
340    [fMenuTorrent release];
341    fMenuTorrent = nil;
342}
343
344- (void) menuNeedsUpdate: (NSMenu *) menu
345{
346    //this method seems to be called when it shouldn't be
347    if (!fMenuTorrent || ![menu supermenu])
348        return;
349   
350    if (menu == fUploadMenu || menu == fDownloadMenu)
351    {
352        BOOL upload = menu == fUploadMenu;
353        tr_speedlimit_t mode = [fMenuTorrent speedMode: upload];
354       
355        NSMenuItem * item = [menu itemWithTag: ACTION_MENU_LIMIT_TAG];
356        [item setState: mode == TR_SPEEDLIMIT_SINGLE ? NSOnState : NSOffState];
357        [item setTitle: [NSString stringWithFormat: NSLocalizedString(@"Limit (%d KB/s)",
358                    "torrent action context menu -> upload/download limit"), [fMenuTorrent speedLimit: upload]]];
359       
360        item = [menu itemWithTag: ACTION_MENU_UNLIMITED_TAG];
361        [item setState: mode == TR_SPEEDLIMIT_UNLIMITED ? NSOnState : NSOffState];
362       
363        item = [menu itemWithTag: ACTION_MENU_GLOBAL_TAG];
364        [item setState: mode == TR_SPEEDLIMIT_GLOBAL ? NSOnState : NSOffState];
365    }
366    else if (menu == fRatioMenu)
367    {
368        int mode = [fMenuTorrent ratioSetting];
369       
370        NSMenuItem * item = [menu itemWithTag: ACTION_MENU_LIMIT_TAG];
371        [item setState: mode == NSOnState ? NSOnState : NSOffState];
372        [item setTitle: [NSString stringWithFormat: NSLocalizedString(@"Stop at Ratio (%.2f)",
373                    "torrent action context menu -> ratio stop"), [fMenuTorrent ratioLimit]]];
374       
375        item = [menu itemWithTag: ACTION_MENU_UNLIMITED_TAG];
376        [item setState: mode == NSOffState ? NSOnState : NSOffState];
377       
378        item = [menu itemWithTag: ACTION_MENU_GLOBAL_TAG];
379        [item setState: mode == NSMixedState ? NSOnState : NSOffState];
380    }
381    #warning better way?
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    tr_speedlimit_t 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: @"UpdateSettings" 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: @"UpdateSettings" 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: @"UpdateSettings" 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: @"UpdateSettings" object: nil];
439}
440
441- (void) checkFile: (id) sender
442{
443    #warning get working
444    NSIndexSet * indexSet;
445    if ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask)
446        indexSet = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [fMenuTorrent fileCount])];
447    else
448        indexSet = [[sender representedObject] objectForKey: @"Indexes"];
449   
450    [fMenuTorrent setFileCheckState: [sender state] != NSOnState ? NSOnState : NSOffState forIndexes: indexSet];
451   
452    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateStats" object: nil];
453}
454
455- (void) drawRow: (int) row clipRect: (NSRect) rect
456{
457    [super drawRow: row clipRect: rect];
458   
459    Torrent * torrent = [fTorrents objectAtIndex: row];
460   
461    //pause/resume icon
462    NSImage * pauseImage = nil;
463    NSRect pauseRect  = [self pauseRectForRow: row];
464    if ([torrent isActive])
465    {
466        if (![torrent isChecking])
467            pauseImage = fClickIn && NSPointInRect(fClickPoint, pauseRect) ? fPauseOnIcon : fPauseOffIcon;
468    }
469    else if ([torrent isPaused])
470    {
471        BOOL inPauseRect = fClickIn && NSPointInRect(fClickPoint, pauseRect);
472        if ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask && [fDefaults boolForKey: @"Queue"])
473            pauseImage = inPauseRect ? fResumeNoWaitOnIcon : fResumeNoWaitOffIcon;
474        else if ([torrent waitingToStart])
475            pauseImage = inPauseRect ? fPauseOnIcon : fPauseOffIcon;
476        else
477            pauseImage = inPauseRect ? fResumeOnIcon : fResumeOffIcon;
478    }
479    else;
480   
481    if (pauseImage)
482        [pauseImage compositeToPoint: NSMakePoint(pauseRect.origin.x, NSMaxY(pauseRect)) operation: NSCompositeSourceOver];
483   
484    //reveal icon
485    NSRect revealRect = [self revealRectForRow: row];
486    NSImage * revealImage = fClickIn && NSPointInRect(fClickPoint, revealRect) ? fRevealOnIcon : fRevealOffIcon;
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) ? fActionOnIcon : fActionOffIcon;
494        [actionImage compositeToPoint: NSMakePoint(actionRect.origin.x, NSMaxY(actionRect)) operation: NSCompositeSourceOver];
495    }
496}
497
498@end
499
500@implementation TorrentTableView (Private)
501
502- (NSRect) pauseRectForRow: (int) row
503{
504    if (row < 0)
505        return NSZeroRect;
506   
507    NSRect cellRect = [self frameOfCellAtColumn: 0 row: row];
508   
509    float buttonToTop = [fDefaults boolForKey: @"SmallView"] ? BUTTON_TO_TOP_SMALL : BUTTON_TO_TOP_REGULAR;
510   
511    return NSMakeRect(NSMaxX(cellRect) - PADDING - BUTTON_WIDTH - PADDING - BUTTON_WIDTH,
512                        cellRect.origin.y + buttonToTop, BUTTON_WIDTH, BUTTON_WIDTH);
513}
514
515- (NSRect) revealRectForRow: (int) row
516{
517    if (row < 0)
518        return NSZeroRect;
519   
520    NSRect cellRect = [self frameOfCellAtColumn: 0 row: row];
521   
522    float buttonToTop = [fDefaults boolForKey: @"SmallView"] ? BUTTON_TO_TOP_SMALL : BUTTON_TO_TOP_REGULAR;
523   
524    return NSMakeRect(NSMaxX(cellRect) - PADDING - BUTTON_WIDTH,
525                        cellRect.origin.y + buttonToTop, BUTTON_WIDTH, BUTTON_WIDTH);
526}
527
528- (NSRect) actionRectForRow: (int) row
529{
530    if (row < 0)
531        return NSZeroRect;
532   
533    TorrentCell * cell = [[self tableColumnWithIdentifier: @"Torrent"] dataCell];
534    NSRect cellRect = [self frameOfCellAtColumn: 0 row: row],
535            iconRect = [cell iconRectForBounds: cellRect];
536   
537    if ([fDefaults boolForKey: @"SmallView"])
538        return iconRect;
539    else
540        return NSMakeRect(iconRect.origin.x + (iconRect.size.width - ACTION_BUTTON_WIDTH) * 0.5,
541                        cellRect.origin.y + ACTION_BUTTON_TO_TOP, ACTION_BUTTON_WIDTH, ACTION_BUTTON_HEIGHT);
542}
543
544- (BOOL) pointInIconRect: (NSPoint) point
545{
546    int row = [self rowAtPoint: point];
547    if (row < 0)
548        return NO;
549   
550    TorrentCell * cell = [[self tableColumnWithIdentifier: @"Torrent"] dataCell];
551    return NSPointInRect(point, [cell iconRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
552}
553
554- (BOOL) pointInMinimalStatusRect: (NSPoint) point
555{
556    int row = [self rowAtPoint: point];
557    if (row < 0 || ![fDefaults boolForKey: @"SmallView"])
558        return NO;
559   
560    TorrentCell * cell = [[self tableColumnWithIdentifier: @"Torrent"] dataCell];
561    [cell setRepresentedObject: [fTorrents objectAtIndex: row]];
562    return NSPointInRect(point, [cell minimalStatusRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
563}
564
565- (BOOL) pointInPauseRect: (NSPoint) point
566{
567    int row = [self rowAtPoint: point];
568    if (row < 0)
569        return NO;
570   
571    return NSPointInRect(point, [self pauseRectForRow: row]);
572}
573
574- (BOOL) pointInRevealRect: (NSPoint) point
575{
576    int row = [self rowAtPoint: point];
577    if (row < 0)
578        return NO;
579   
580    return NSPointInRect(point, [self revealRectForRow: row]);
581}
582
583- (BOOL) pointInActionRect: (NSPoint) point
584{
585    int row = [self rowAtPoint: point];
586    if (row < 0)
587        return NO;
588   
589    return NSPointInRect(point, [self actionRectForRow: row]);
590}
591
592- (void) updateFileMenu: (NSMenu *) menu forFiles: (NSArray *) files
593{
594    BOOL create = [menu numberOfItems] <= 0;
595   
596    NSEnumerator * enumerator = [files objectEnumerator];
597    NSDictionary * dict;
598    NSMenuItem * item;
599    while ((dict = [enumerator nextObject]))
600    {
601        NSString * name = [dict objectForKey: @"Name"];
602       
603        if (create)
604        {
605            item = [[NSMenuItem alloc] initWithTitle: name action: NULL keyEquivalent: @""];
606           
607            NSImage * icon;
608            if (![[dict objectForKey: @"IsFolder"] boolValue])
609            {
610                icon = [[dict objectForKey: @"Icon"] copy];
611                [icon setFlipped: NO];
612            }
613            else
614            {
615                NSMenu * itemMenu = [[NSMenu alloc] initWithTitle: name];
616                [itemMenu setAutoenablesItems: NO];
617                [item setSubmenu: itemMenu];
618                [itemMenu setDelegate: self];
619                [itemMenu release];
620               
621                icon = [[[NSWorkspace sharedWorkspace] iconForFileType: NSFileTypeForHFSTypeCode('fldr')] copy];
622            }
623           
624            [item setRepresentedObject: dict];
625           
626            [icon setScalesWhenResized: YES];
627            [icon setSize: NSMakeSize(16.0, 16.0)];
628            [item setImage: icon];
629            [icon release];
630           
631            [item setAction: @selector(checkFile:)];
632           
633            [menu addItem: item];
634            [item release];
635        }
636        else
637            item = [menu itemWithTitle: name];
638       
639        NSIndexSet * indexSet = [dict objectForKey: @"Indexes"];
640        [item setState: [fMenuTorrent checkForFiles: indexSet]];
641        [item setEnabled: [fMenuTorrent canChangeDownloadCheckForFiles: indexSet]];
642    }
643}
644
645#warning move to additions
646- (void) moveItemsFromMenu: (NSMenu *) oldMenu inRange: (NSRange) range toMenu: (NSMenu *) newMenu
647{
648    NSMenuItem * item;
649    int i;
650    for (i=0; i<range.length; i++)
651    {
652        item = [[oldMenu itemAtIndex: range.location] retain];
653        [oldMenu removeItem: item];
654        [newMenu addItem: item];
655        [item release];
656    }
657}
658
659@end
Note: See TracBrowser for help on using the repository browser.