file table rows for files are now larger with the size displayed under it

This commit is contained in:
Mitchell Livingston 2007-01-18 22:00:24 +00:00
parent 4bffa20e5c
commit 271badba8b
3 changed files with 68 additions and 27 deletions

View File

@ -12,37 +12,68 @@
- (void) setImage: (NSImage *) image - (void) setImage: (NSImage *) image
{ {
[image setFlipped: YES]; [image setFlipped: YES];
[image setScalesWhenResized: YES];
[super setImage: image]; [super setImage: image];
} }
- (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) controlView - (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) controlView
{ {
//image //image
NSImage * icon = [self image]; float imageHeight = cellFrame.size.height - 2.0;
NSSize iconSize = [icon size];
NSRect imageRect = NSMakeRect(cellFrame.origin.x + 2.0 * SPACE, cellFrame.origin.y, iconSize.width, iconSize.height);
[icon drawInRect: imageRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0]; 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];
//text //text
NSRect textRect = NSMakeRect(NSMaxX(imageRect) + SPACE, cellFrame.origin.y, NSArray * strings = [[self stringValue] componentsSeparatedByString: @"\n"];
cellFrame.size.width - 4.0 * SPACE, cellFrame.size.height);
if ([self isHighlighted] && [[self highlightColorWithFrame: cellFrame inView: controlView] NSMutableParagraphStyle * paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
isEqual: [NSColor alternateSelectedControlColor]]) [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];
float textHeight = [(NSTableView *)controlView rowHeight];
NSRect textRect = NSMakeRect(NSMaxX(imageRect) + SPACE, cellFrame.origin.y + 2.0,
NSMaxX(cellFrame) - NSMaxX(imageRect) - 2.0 * SPACE, textHeight);
NSAttributedString * text = [[NSAttributedString alloc] initWithString: [strings objectAtIndex: 0]
attributes: nameAttributes];
[text drawInRect: textRect];
[text release];
//bottomText
if ([strings count] > 1)
{ {
NSMutableAttributedString * text = [[self attributedStringValue] mutableCopy]; NSDictionary * statusAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
NSDictionary * attributes = [[NSDictionary alloc] initWithObjectsAndKeys: highlighted ? [NSColor whiteColor] : [NSColor darkGrayColor], NSForegroundColorAttributeName,
[NSColor whiteColor], NSForegroundColorAttributeName, nil]; [NSFont messageFontOfSize: 9.0], NSFontAttributeName,
[text addAttributes: attributes range: NSMakeRange(0, [text length])]; paragraphStyle, NSParagraphStyleAttributeName, nil];
[text drawInRect: textRect];
[attributes release]; NSRect bottomTextRect = textRect;
[text release]; bottomTextRect.origin.y += textHeight;
bottomTextRect.size.height = cellFrame.size.height - textHeight;
NSMutableAttributedString * bottomText = [[NSMutableAttributedString alloc] initWithString: [strings objectAtIndex: 1]
attributes: statusAttributes];
[bottomText drawInRect: bottomTextRect];
[bottomText release];
[statusAttributes release];
} }
else
[[self attributedStringValue] drawInRect: textRect]; [paragraphStyle release];
[nameAttributes release];
} }
@end @end

View File

@ -676,13 +676,16 @@
- (id) outlineView: (NSOutlineView *) outlineView objectValueForTableColumn: (NSTableColumn *) tableColumn - (id) outlineView: (NSOutlineView *) outlineView objectValueForTableColumn: (NSTableColumn *) tableColumn
byItem: (id) item byItem: (id) item
{ {
if ([[tableColumn identifier] isEqualToString: @"Size"]) if ([[tableColumn identifier] isEqualToString: @"Check"])
return ![[item objectForKey: @"IsFolder"] boolValue]
? [NSString stringForFileSize: [[item objectForKey: @"Size"] unsignedLongLongValue]] : @"";
else if ([[tableColumn identifier] isEqualToString: @"Check"])
return [item objectForKey: @"Check"]; return [item objectForKey: @"Check"];
else else
return [item objectForKey: @"Name"]; {
if ([[item objectForKey: @"IsFolder"] boolValue])
return [item objectForKey: @"Name"];
else
return [NSString stringWithFormat: @"%@\n%@", [item objectForKey: @"Name"],
[NSString stringForFileSize: [[item objectForKey: @"Size"] unsignedLongLongValue]]];
}
} }
- (void) outlineView: (NSOutlineView *) outlineView setObjectValue: (id) object - (void) outlineView: (NSOutlineView *) outlineView setObjectValue: (id) object
@ -752,8 +755,6 @@
{ {
NSImage * icon = [[NSWorkspace sharedWorkspace] iconForFileType: ![[item objectForKey: @"IsFolder"] boolValue] NSImage * icon = [[NSWorkspace sharedWorkspace] iconForFileType: ![[item objectForKey: @"IsFolder"] boolValue]
? [[item objectForKey: @"Name"] pathExtension] : NSFileTypeForHFSTypeCode('fldr')]; ? [[item objectForKey: @"Name"] pathExtension] : NSFileTypeForHFSTypeCode('fldr')];
[icon setScalesWhenResized: YES];
[icon setSize: NSMakeSize(16.0, 16.0)];
[cell setImage: icon]; [cell setImage: icon];
} }
else if ([[tableColumn identifier] isEqualToString: @"Check"]) else if ([[tableColumn identifier] isEqualToString: @"Check"])
@ -768,16 +769,25 @@
tableColumn: (NSTableColumn *) tableColumn item: (id) item mouseLocation: (NSPoint) mouseLocation tableColumn: (NSTableColumn *) tableColumn item: (id) item mouseLocation: (NSPoint) mouseLocation
{ {
NSString * ident = [tableColumn identifier]; NSString * ident = [tableColumn identifier];
if ([ident isEqualToString: @"Size"]) #warning change
/*if ([ident isEqualToString: @"Size"])
return ![[item objectForKey: @"IsFolder"] boolValue] return ![[item objectForKey: @"IsFolder"] boolValue]
? [[[item objectForKey: @"Size"] stringValue] stringByAppendingString: NSLocalizedString(@" bytes", ? [[[item objectForKey: @"Size"] stringValue] stringByAppendingString: NSLocalizedString(@" bytes",
"Inspector -> Files tab -> table row tooltip")] : nil; "Inspector -> Files tab -> table row tooltip")] : nil;
else if ([ident isEqualToString: @"Name"]) else*/ if ([ident isEqualToString: @"Name"])
return [[[fTorrents objectAtIndex: 0] downloadFolder] stringByAppendingPathComponent: [item objectForKey: @"Path"]]; return [[[fTorrents objectAtIndex: 0] downloadFolder] stringByAppendingPathComponent: [item objectForKey: @"Path"]];
else else
return nil; return nil;
} }
- (float) outlineView: (NSOutlineView *) outlineView heightOfRowByItem: (id) item
{
float height = [outlineView rowHeight];
if (![[item objectForKey: @"IsFolder"] boolValue])
height = 34.0;
return height;
}
- (NSArray *) peerSortDescriptors - (NSArray *) peerSortDescriptors
{ {
NSMutableArray * descriptors = [NSMutableArray array]; NSMutableArray * descriptors = [NSMutableArray array];