2007-01-18 01:19:14 +00:00
|
|
|
#import "FileBrowserCell.h"
|
2007-01-18 22:53:27 +00:00
|
|
|
#import "StringAdditions.h"
|
2007-01-18 01:19:14 +00:00
|
|
|
|
|
|
|
#define SPACE 2.0
|
|
|
|
|
|
|
|
@implementation FileBrowserCell
|
|
|
|
|
2007-01-18 03:54:56 +00:00
|
|
|
- (void) awakeFromNib
|
|
|
|
{
|
|
|
|
[self setLeaf: YES];
|
|
|
|
}
|
|
|
|
|
2007-01-18 01:19:14 +00:00
|
|
|
- (void) setImage: (NSImage *) image
|
|
|
|
{
|
|
|
|
[image setFlipped: YES];
|
2007-01-18 22:00:24 +00:00
|
|
|
[image setScalesWhenResized: YES];
|
2007-01-18 01:19:14 +00:00
|
|
|
[super setImage: image];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) controlView
|
|
|
|
{
|
2007-01-20 03:25:35 +00:00
|
|
|
NSMutableDictionary * item;
|
|
|
|
if (!(item = [self objectValue]))
|
|
|
|
return;
|
|
|
|
|
2007-01-18 01:19:14 +00:00
|
|
|
//image
|
2007-01-18 22:00:24 +00:00
|
|
|
float imageHeight = cellFrame.size.height - 2.0;
|
2007-01-18 01:19:14 +00:00
|
|
|
|
2007-01-18 22:00:24 +00:00
|
|
|
NSImage * image = [self image];
|
|
|
|
[image setSize: NSMakeSize(imageHeight, imageHeight)];
|
|
|
|
NSRect imageRect = NSMakeRect(cellFrame.origin.x + 2.0 * SPACE,
|
|
|
|
cellFrame.origin.y + (cellFrame.size.height - imageHeight) / 2.0,
|
|
|
|
imageHeight, imageHeight);
|
|
|
|
|
|
|
|
[image drawInRect: imageRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
|
2007-01-18 01:19:14 +00:00
|
|
|
|
|
|
|
//text
|
2007-01-18 22:00:24 +00:00
|
|
|
NSMutableParagraphStyle * paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
|
|
|
|
[paragraphStyle setLineBreakMode: NSLineBreakByTruncatingTail];
|
|
|
|
|
|
|
|
BOOL highlighted = [self isHighlighted] && [[self highlightColorWithFrame: cellFrame inView: controlView]
|
|
|
|
isEqual: [NSColor alternateSelectedControlColor]];
|
|
|
|
NSDictionary * nameAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
|
|
|
|
highlighted ? [NSColor whiteColor] : [NSColor controlTextColor], NSForegroundColorAttributeName,
|
|
|
|
[NSFont messageFontOfSize: 12.0], NSFontAttributeName,
|
|
|
|
paragraphStyle, NSParagraphStyleAttributeName, nil];
|
|
|
|
|
2007-01-19 02:06:12 +00:00
|
|
|
NSString * nameString = [item objectForKey: @"Name"];
|
|
|
|
NSRect nameTextRect = NSMakeRect(NSMaxX(imageRect) + SPACE, cellFrame.origin.y + 1.0,
|
|
|
|
NSMaxX(cellFrame) - NSMaxX(imageRect) - 2.0 * SPACE, [nameString sizeWithAttributes: nameAttributes].height);
|
2007-01-18 22:00:24 +00:00
|
|
|
|
2007-01-19 02:06:12 +00:00
|
|
|
[nameString drawInRect: nameTextRect withAttributes: nameAttributes];
|
|
|
|
[nameAttributes release];
|
2007-01-18 01:19:14 +00:00
|
|
|
|
2007-01-19 02:06:12 +00:00
|
|
|
//status text
|
2007-01-18 22:53:27 +00:00
|
|
|
if (![[item objectForKey: @"IsFolder"] boolValue])
|
2007-01-18 01:19:14 +00:00
|
|
|
{
|
2007-01-18 22:00:24 +00:00
|
|
|
NSDictionary * statusAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
|
2007-01-19 15:30:41 +00:00
|
|
|
highlighted ? [NSColor whiteColor] : [NSColor darkGrayColor], NSForegroundColorAttributeName,
|
|
|
|
[NSFont messageFontOfSize: 9.0], NSFontAttributeName,
|
|
|
|
paragraphStyle, NSParagraphStyleAttributeName, nil];
|
2007-01-18 01:19:14 +00:00
|
|
|
|
2007-01-19 02:06:12 +00:00
|
|
|
NSString * statusString = [NSString stringForFileSize: [[item objectForKey: @"Size"] unsignedLongLongValue]];
|
2007-01-18 22:00:24 +00:00
|
|
|
|
2007-01-19 02:06:12 +00:00
|
|
|
NSRect statusTextRect = nameTextRect;
|
|
|
|
statusTextRect.size.height = [statusString sizeWithAttributes: statusAttributes].height;
|
|
|
|
statusTextRect.origin.y += (cellFrame.size.height + nameTextRect.size.height - statusTextRect.size.height) * 0.5 - 1.0;
|
2007-01-18 01:19:14 +00:00
|
|
|
|
2007-01-19 02:06:12 +00:00
|
|
|
[statusString drawInRect: statusTextRect withAttributes: statusAttributes];
|
2007-01-18 22:00:24 +00:00
|
|
|
[statusAttributes release];
|
|
|
|
}
|
|
|
|
|
|
|
|
[paragraphStyle release];
|
2007-01-18 01:19:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|