Changeset 112


Ignore:
Timestamp:
Feb 9, 2006, 12:58:10 PM (16 years ago)
Author:
titer
Message:

Cache icons in NameCell? (fixes #1)

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/NameCell.h

    r56 r112  
    3737    NSString * fPeersString;
    3838
    39     NSImage * fIcon;
     39    NSMutableArray * fFileTypes;
     40    NSMutableArray * fIcons;
     41    NSImage        * fCurrentIcon;
    4042}
    4143- (void) setStat: (tr_stat_t *) stat whiteText: (BOOL) w;
  • trunk/macosx/NameCell.m

    r94 r112  
    2727@implementation NameCell
    2828
     29- (id) init
     30{
     31    [super init];
     32
     33    fFileTypes = [[NSMutableArray alloc] initWithCapacity: 10];
     34    fIcons     = [[NSMutableArray alloc] initWithCapacity: 10];
     35
     36    return self;
     37}
     38
     39- (NSImage *) iconForFileType: (NSString *) type
     40{
     41    unsigned i;
     42
     43    /* See if we have this icon cached */
     44    for( i = 0; i < [fFileTypes count]; i++ )
     45        if( [[fFileTypes objectAtIndex: i] isEqualToString: type] )
     46            break;
     47
     48    if( i == [fFileTypes count] )
     49    {
     50        /* Unknown file type, get its icon and cache it */
     51        NSImage * icon;
     52        icon = [[NSWorkspace sharedWorkspace] iconForFileType: type];
     53        [icon setFlipped: YES];
     54        [fFileTypes addObject: type];
     55        [fIcons     addObject: icon];
     56    }
     57
     58    return [fIcons objectAtIndex: i];
     59}
     60
    2961- (void) setStat: (tr_stat_t *) stat whiteText: (BOOL) w
    3062{
     
    3567                    [NSString stringForFileSize: stat->info.totalSize]];
    3668
    37     if( stat->info.fileCount > 1 )
    38         fIcon = [[NSWorkspace sharedWorkspace] iconForFileType:
    39             NSFileTypeForHFSTypeCode('fldr')];
    40     else
    41         fIcon = [[NSWorkspace sharedWorkspace] iconForFileType:
    42             [fNameString pathExtension]];
    43     [fIcon setFlipped: YES];
     69    fCurrentIcon = [self iconForFileType: stat->info.fileCount > 1 ?
     70        NSFileTypeForHFSTypeCode('fldr') : [fNameString pathExtension]];
    4471
    4572    fTimeString  = @"";
     
    111138    pen.x += 5;
    112139    pen.y += 5;                                                                 
    113     [fIcon drawAtPoint: pen fromRect:
    114         NSMakeRect(0,0,[fIcon size].width,[fIcon size].height)
     140    [fCurrentIcon drawAtPoint: pen fromRect:
     141        NSMakeRect(0,0,[fCurrentIcon size].width,[fCurrentIcon size].height)
    115142        operation: NSCompositeSourceOver fraction: 1.0];
    116143
Note: See TracChangeset for help on using the changeset viewer.