Changeset 5235


Ignore:
Timestamp:
Mar 11, 2008, 3:37:09 AM (14 years ago)
Author:
livings124
Message:

it's faster to lazily generate the torrent action menu each time you need it

Location:
trunk/macosx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Torrent.h

    r5149 r5235  
    6161    tr_file_stat * fileStat;
    6262    NSArray * fFileList;
    63    
    64     NSMenu * fFileMenu;
    6563   
    6664    float * fPreviousFinishedPieces;
     
    245243- (NSSet *) filePrioritiesForIndexes: (NSIndexSet *) indexSet;
    246244
    247 - (NSMenu *) fileMenu;
    248 
    249245- (NSDate *) dateAdded;
    250246- (NSDate *) dateCompleted;
  • trunk/macosx/Torrent.m

    r5149 r5235  
    191191   
    192192    [fFileList release];
    193     [fFileMenu release];
    194193   
    195194    [fQuickPauseDict release];
     
    285284    //check if stalled (stored because based on time and needs to check if it was previously stalled)
    286285    fStalled = [self isActive] && [fDefaults boolForKey: @"CheckStalled"]
    287                 && [fDefaults integerForKey: @"StalledMinutes"] < [self stalledMinutes];
     286                && [self stalledMinutes] > [fDefaults integerForKey: @"StalledMinutes"];
    288287   
    289288    //update queue for checking (from downloading to seeding), stalled, or error
     
    14201419}
    14211420
    1422 - (NSMenu *) fileMenu
    1423 {
    1424     if (!fFileMenu)
    1425     {
    1426         fFileMenu = [[NSMenu alloc] initWithTitle: [@"TorrentMenu:" stringByAppendingString: [self name]]];
    1427         [fFileMenu setAutoenablesItems: NO];
    1428     }
    1429     return fFileMenu;
    1430 }
    1431 
    14321421- (NSDate *) dateAdded
    14331422{
     
    14611450            * activity = [self dateActivity];
    14621451   
    1463     NSDate * laterDate = (!activity || [started compare: activity] == NSOrderedDescending) ? started : activity;
     1452    NSDate * laterDate = activity ? [started laterDate: activity] : started;
    14641453    return -1 * [laterDate timeIntervalSinceNow] / 60;
    14651454}
  • trunk/macosx/TorrentTableView.m

    r5190 r5235  
    5151- (void) setGroupStatusColumns;
    5252
    53 - (void) updateFileMenu: (NSMenu *) menu forFiles: (NSArray *) files;
     53- (void) createFileMenu: (NSMenu *) menu forFiles: (NSArray *) files;
    5454
    5555- (void) resizePiecesBarIncrement;
     
    532532    //get and update file menu
    533533    fMenuTorrent = [[self itemAtRow: row] retain];
    534     NSMenu * fileMenu = [fMenuTorrent fileMenu];
    535     [self updateFileMenu: fileMenu forFiles: [fMenuTorrent fileList]];
     534   
     535    NSMenu * fileMenu = [[NSMenu alloc] initWithTitle: @"TorrentMenu"];
     536    [fileMenu setAutoenablesItems: NO];
     537    [self createFileMenu: fileMenu forFiles: [fMenuTorrent fileList]];
    536538   
    537539    //add file menu items to action menu
    538     NSRange range = NSMakeRange(0, [fileMenu numberOfItems]);
    539     [fActionMenu appendItemsFromMenu: fileMenu atIndexes: [NSIndexSet indexSetWithIndexesInRange: range] atBottom: YES];
     540    NSInteger numberOfItems = [fileMenu numberOfItems];
     541    [fActionMenu appendItemsFromMenu: fileMenu atIndexes: [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, numberOfItems)]
     542        atBottom: YES];
     543    [fileMenu release];
    540544   
    541545    //place menu below button
     
    551555    [NSMenu popUpContextMenu: fActionMenu withEvent: newEvent forView: self];
    552556   
    553     //move file menu items back to the torrent's file menu
    554     range.location = [fActionMenu numberOfItems] - range.length;
    555     [fileMenu appendItemsFromMenu: fActionMenu atIndexes: [NSIndexSet indexSetWithIndexesInRange: range] atBottom: YES];
     557    NSInteger i;
     558    for (i = 0; i < numberOfItems; i++)
     559        [fActionMenu removeItemAtIndex: [fActionMenu numberOfItems]-1];
    556560   
    557561    [fMenuTorrent release];
     
    634638    {
    635639        NSMenu * supermenu = [menu supermenu];
    636         [self updateFileMenu: menu forFiles: [[[supermenu itemAtIndex: [supermenu indexOfItemWithSubmenu: menu]]
     640        [self createFileMenu: menu forFiles: [[[supermenu itemAtIndex: [supermenu indexOfItemWithSubmenu: menu]]
    637641                                                    representedObject] objectForKey: @"Children"]];
    638642    }
     
    821825}
    822826
    823 - (void) updateFileMenu: (NSMenu *) menu forFiles: (NSArray *) files
    824 {
    825     BOOL create = [menu numberOfItems] <= 0;
     827- (void) createFileMenu: (NSMenu *) menu forFiles: (NSArray *) files
     828{
     829    if ([menu numberOfItems] > 0)
     830        return;
    826831   
    827832    NSEnumerator * enumerator = [files objectEnumerator];
     
    832837        NSString * name = [dict objectForKey: @"Name"];
    833838       
    834         if (create)
     839        item = [[NSMenuItem alloc] initWithTitle: name action: @selector(checkFile:) keyEquivalent: @""];
     840       
     841        NSImage * icon;
     842        if (![[dict objectForKey: @"IsFolder"] boolValue])
     843            icon = [[NSWorkspace sharedWorkspace] iconForFileType: [name pathExtension]];
     844        else
    835845        {
    836             item = [[NSMenuItem alloc] initWithTitle: name action: @selector(checkFile:) keyEquivalent: @""];
     846            NSMenu * itemMenu = [[NSMenu alloc] initWithTitle: name];
     847            [itemMenu setAutoenablesItems: NO];
     848            [item setSubmenu: itemMenu];
     849            [itemMenu setDelegate: self];
     850            [itemMenu release];
    837851           
    838             NSImage * icon;
    839             if (![[dict objectForKey: @"IsFolder"] boolValue])
    840                 icon = [[NSWorkspace sharedWorkspace] iconForFileType: [name pathExtension]];
    841             else
    842             {
    843                 NSMenu * itemMenu = [[NSMenu alloc] initWithTitle: name];
    844                 [itemMenu setAutoenablesItems: NO];
    845                 [item setSubmenu: itemMenu];
    846                 [itemMenu setDelegate: self];
    847                 [itemMenu release];
    848                
    849                 icon = [[NSWorkspace sharedWorkspace] iconForFileType: NSFileTypeForHFSTypeCode('fldr')];
    850             }
    851            
    852             [item setRepresentedObject: dict];
    853            
    854             [icon setScalesWhenResized: YES];
    855             [icon setSize: NSMakeSize(16.0, 16.0)];
    856             [item setImage: icon];
    857            
    858             [menu addItem: item];
    859             [item release];
     852            icon = [[NSWorkspace sharedWorkspace] iconForFileType: NSFileTypeForHFSTypeCode('fldr')];
    860853        }
    861         else
    862             item = [menu itemWithTitle: name];
     854       
     855        [item setRepresentedObject: dict];
     856       
     857        [icon setScalesWhenResized: YES];
     858        [icon setSize: NSMakeSize(16.0, 16.0)];
     859        [item setImage: icon];
     860       
     861        [menu addItem: item];
     862        [item release];
    863863       
    864864        NSIndexSet * indexSet = [dict objectForKey: @"Indexes"];
Note: See TracChangeset for help on using the changeset viewer.