Adium
Show
Ignore:
Timestamp:
08/16/2008 10:50:06 PM (5 months ago)
Author:
boredzo
Message:

Factored AXCFileCell's retrieval of the icon and filename of its object value into two separate methods, so that subclasses of AXCFileCell can override those methods in order to support other kinds of objects (e.g., Xcode items).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Other/XtrasCreator/AXCFileCell.h

    r13979 r24846  
    3434- (void)setIconSourceMask:(enum AXCFileCellIconSourceMask)mask; 
    3535 
     36//These are the methods that the cell uses to determine the icon and filename that it should draw. You can override them in subclasses. The cell calls them with its current object value, which (in AXCFileCell) is a path. 
     37- (NSImage *) iconForObjectValue:(id)objValue; 
     38- (NSString *) filenameForObjectValue:(id)objectValue; 
     39 
    3640@end 
  • trunk/Other/XtrasCreator/AXCFileCell.m

    r16369 r24846  
    3838#pragma mark - 
    3939 
     40- (NSImage *) iconForObjectValue:(id)objectValue { 
     41        NSImage *icon = nil; 
     42 
     43        NSString *path = objectValue; 
     44 
     45        //First try to get a preview (AXCAbstractXtraDocument creates these). 
     46        if (iconSource.iconSourceBitfield.getPreviewsByFullPath) 
     47                icon = [NSImage imageNamed:[@"Preview of " stringByAppendingString:path]]; 
     48 
     49        //If there's no preview for the absolute path, try the filename. 
     50        if (iconSource.iconSourceBitfield.getPreviewsByFilename && (!icon) && [path isAbsolutePath]) 
     51                icon = [NSImage imageNamed:[@"Preview of " stringByAppendingString:[path lastPathComponent]]]; 
     52 
     53        //If there isn't a preview for either path, just get the file's icon. 
     54        if (iconSource.iconSourceBitfield.getPreviewsFromFileIcons && !icon) { 
     55                icon = [[NSWorkspace sharedWorkspace] iconForFile:path]; 
     56                [icon setFlipped:YES]; 
     57        } 
     58 
     59        //Fallback on generic file icon. 
     60        if (!icon) { 
     61                icon = [[NSWorkspace sharedWorkspace] iconForFileType:@"'docu'"]; 
     62                [icon setFlipped:YES]; 
     63        } 
     64 
     65        return icon; 
     66} 
     67 
     68- (NSString *) filenameForObjectValue:(id)objectValue { 
     69        NSString *path = objectValue; 
     70 
     71        return [[NSFileManager defaultManager] displayNameAtPath:path]; 
     72} 
     73 
    4074- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)view { 
    41         NSString *path = [self stringValue]; 
    42  
    4375        float gutter = 0.0, contentHeight = 16.0; 
    4476        static const float visualSeparation = 8.0; 
    4577 
    4678        /*draw the icon*/ { 
    47                 //first try to get a preview (AXCAbstractXtraDocument creates these). 
    48                 NSImage *icon = nil; 
    49                 if (iconSource.iconSourceBitfield.getPreviewsByFullPath) 
    50                         icon = [NSImage imageNamed:[@"Preview of " stringByAppendingString:path]]; 
    51                 //if there's no preview for the absolute path, try the filename. 
    52                 if (iconSource.iconSourceBitfield.getPreviewsByFilename && (!icon) && [path isAbsolutePath]) 
    53                         icon = [NSImage imageNamed:[@"Preview of " stringByAppendingString:[path lastPathComponent]]]; 
    54                 //if there isn't a preview for either path, just get the file's icon. 
    55                 if (iconSource.iconSourceBitfield.getPreviewsFromFileIcons && !icon) { 
    56                         icon = [[NSWorkspace sharedWorkspace] iconForFile:path]; 
    57                         [icon setFlipped:YES]; 
    58                 } 
    59                 //fallback on generic file icon. 
    60                 if (!icon) { 
    61                         icon = [[NSWorkspace sharedWorkspace] iconForFileType:@"'docu'"]; 
    62                         [icon setFlipped:YES]; 
    63                 } 
     79                NSImage *icon = [self iconForObjectValue:[self objectValue]]; 
    6480 
    6581                //get the largest size that will fit entirely within the frame. 
     
    100116 
    101117        /*draw the filename*/ { 
    102                 NSString *filename = [[NSFileManager defaultManager] displayNameAtPath:path]; 
     118                NSString *filename = [self filenameForObjectValue:[self objectValue]]; 
    103119 
    104120                float leftMargin = gutter + (visualSeparation * 2.0) + contentHeight;