get around a bug in table views to keep consistent row colors by creating a blank row when no torrent is selected

This commit is contained in:
Mitchell Livingston 2007-01-20 03:25:35 +00:00
parent 2b7d630d54
commit 63913686d5
2 changed files with 35 additions and 18 deletions

View File

@ -19,6 +19,10 @@
- (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) controlView - (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) controlView
{ {
NSMutableDictionary * item;
if (!(item = [self objectValue]))
return;
//image //image
float imageHeight = cellFrame.size.height - 2.0; float imageHeight = cellFrame.size.height - 2.0;
@ -31,8 +35,6 @@
[image drawInRect: imageRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0]; [image drawInRect: imageRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
//text //text
NSMutableDictionary * item = [self objectValue];
NSMutableParagraphStyle * paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; NSMutableParagraphStyle * paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[paragraphStyle setLineBreakMode: NSLineBreakByTruncatingTail]; [paragraphStyle setLineBreakMode: NSLineBreakByTruncatingTail];

View File

@ -661,29 +661,55 @@
- (int) outlineView: (NSOutlineView *) outlineView numberOfChildrenOfItem: (id) item - (int) outlineView: (NSOutlineView *) outlineView numberOfChildrenOfItem: (id) item
{ {
if (!item) if (!item)
return [fFiles count]; return fFiles ? [fFiles count] : 1;
return [[item objectForKey: @"IsFolder"] boolValue] ? [[item objectForKey: @"Children"] count] : 0; return [[item objectForKey: @"IsFolder"] boolValue] ? [[item objectForKey: @"Children"] count] : 0;
} }
- (BOOL) outlineView: (NSOutlineView *) outlineView isItemExpandable: (id) item - (BOOL) outlineView: (NSOutlineView *) outlineView isItemExpandable: (id) item
{ {
return [[item objectForKey: @"IsFolder"] boolValue]; return item && [[item objectForKey: @"IsFolder"] boolValue];
} }
- (id) outlineView: (NSOutlineView *) outlineView child: (int) index ofItem: (id) item - (id) outlineView: (NSOutlineView *) outlineView child: (int) index ofItem: (id) item
{ {
if (!fFiles)
return nil;
return [(item ? [item objectForKey: @"Children"] : fFiles) objectAtIndex: index]; return [(item ? [item objectForKey: @"Children"] : fFiles) objectAtIndex: index];
} }
- (id) outlineView: (NSOutlineView *) outlineView objectValueForTableColumn: (NSTableColumn *) tableColumn - (id) outlineView: (NSOutlineView *) outlineView objectValueForTableColumn: (NSTableColumn *) tableColumn
byItem: (id) item byItem: (id) item
{ {
if (!item)
return nil;
if ([[tableColumn identifier] isEqualToString: @"Check"]) if ([[tableColumn identifier] isEqualToString: @"Check"])
return [item objectForKey: @"Check"]; return [item objectForKey: @"Check"];
else else
return item; return item;
} }
- (void) outlineView: (NSOutlineView *) outlineView willDisplayCell: (id) cell
forTableColumn: (NSTableColumn *) tableColumn item:(id) item
{
if ([[tableColumn identifier] isEqualToString: @"Name"])
{
if (!item)
return;
NSImage * icon = [[NSWorkspace sharedWorkspace] iconForFileType: ![[item objectForKey: @"IsFolder"] boolValue]
? [[item objectForKey: @"Name"] pathExtension] : NSFileTypeForHFSTypeCode('fldr')];
[cell setImage: icon];
}
else if ([[tableColumn identifier] isEqualToString: @"Check"])
{
[(NSButtonCell *)cell setImagePosition: item ? NSImageOnly : NSNoImage];
[cell setEnabled: NO];
}
else;
}
- (void) outlineView: (NSOutlineView *) outlineView setObjectValue: (id) object - (void) outlineView: (NSOutlineView *) outlineView setObjectValue: (id) object
forTableColumn: (NSTableColumn *) tableColumn byItem: (id) item forTableColumn: (NSTableColumn *) tableColumn byItem: (id) item
{ {
@ -744,23 +770,12 @@
return originalChild; return originalChild;
} }
- (void) outlineView: (NSOutlineView *) outlineView willDisplayCell: (id) cell
forTableColumn: (NSTableColumn *) tableColumn item:(id) item
{
if ([[tableColumn identifier] isEqualToString: @"Name"])
{
NSImage * icon = [[NSWorkspace sharedWorkspace] iconForFileType: ![[item objectForKey: @"IsFolder"] boolValue]
? [[item objectForKey: @"Name"] pathExtension] : NSFileTypeForHFSTypeCode('fldr')];
[cell setImage: icon];
}
else if ([[tableColumn identifier] isEqualToString: @"Check"])
[cell setEnabled: NO];
else;
}
- (NSString *) outlineView: (NSOutlineView *) outlineView toolTipForCell: (NSCell *) cell rect: (NSRectPointer) rect - (NSString *) outlineView: (NSOutlineView *) outlineView toolTipForCell: (NSCell *) cell rect: (NSRectPointer) rect
tableColumn: (NSTableColumn *) tableColumn item: (id) item mouseLocation: (NSPoint) mouseLocation tableColumn: (NSTableColumn *) tableColumn item: (id) item mouseLocation: (NSPoint) mouseLocation
{ {
if (!item)
return nil;
NSString * ident = [tableColumn identifier]; NSString * ident = [tableColumn identifier];
if ([ident isEqualToString: @"Name"]) if ([ident isEqualToString: @"Name"])
return [[[fTorrents objectAtIndex: 0] downloadFolder] stringByAppendingPathComponent: [item objectForKey: @"Path"]]; return [[[fTorrents objectAtIndex: 0] downloadFolder] stringByAppendingPathComponent: [item objectForKey: @"Path"]];