Skip to content

Instantly share code, notes, and snippets.

@toddfreese
Created December 23, 2011 03:37
Show Gist options
  • Select an option

  • Save toddfreese/1513053 to your computer and use it in GitHub Desktop.

Select an option

Save toddfreese/1513053 to your computer and use it in GitHub Desktop.
CPOutlineView dataView
@implementation FolderListCell : CPView
{
CPString folderNameText;
CPImage icon;
CPImageView iconView;
CPTextField label;
BOOL isSelected;
JSObject folderObject;
}
- (void)setObjectValue:(id)anObject
{
folderObject = anObject;
folderNameText = [folderObject folderName];
// Create and setup label text object.
label = [[CPTextField alloc] initWithFrame:CGRectInset([self bounds], 4, 4)];
[label setFont:[CPFont systemFontOfSize:12.0]];
if(isSelected) {
[label setTextColor:[CPColor blackColor]];
} else {
[label setTextColor:[CPColor colorWithHexString:folderItemTypeColor]];
}
[self addSubview:label];
[label setStringValue:[self folderNameText]];
[label sizeToFit];
// Create and setup icon view object.
iconView = [[CPImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
[iconView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[iconView setImageScaling:CPScaleProportionally];
[iconView setHasShadow:NO];
[self addSubview:iconView];
// Create and setup icon image object.
icon = [[CPImage alloc] initWithContentsOfFile:folderIconImagePath];
[icon setDelegate: self];
if([icon loadStatus] == CPImageLoadStatusCompleted) {
[iconView setImage:icon]; // If image is loaded, then display in icon view.
} else {
[iconView setImage:nil]; // If image is not loaded, then let delegate callback load the image into the view.
}
}
- (void)encodeWithCoder:(CPCoder)coder
{
[super encodeWithCoder:coder];
[coder encodeObject:[self folderNameText] forKey:@"folderNameText"];
[coder encodeObject:label forKey:@"label"];
[coder encodeObject:iconView forKey:@"iconView"];
}
- (id)initWithCoder:(CPCoder)coder
{
self = [super initWithCoder:coder];
if (self) {
[self setFolderNameText:[[coder decodeObjectForKey:@"folderNameText"] retain]];
label = [coder decodeObjectForKey:@"label"];
iconView = [coder decodeObjectForKey:@"iconView"];
}
return self;
}
- (void)imageDidLoad:(CPImage)anImage
{
////CPLog("imageDidLoad called");
// This method is the callback delegate for the icon image object.
// It is called when an image finishes loading.
if(anImage == icon) {
[iconView setImage:anImage];
}
[self setNeedsDisplay:YES];
}
// Accessor Methods
// ----------------
- (CPString)folderNameText
{
return folderNameText;
}
- (void)setFolderNameText:(CPString)aFolderNameText
{
folderNameText = aFolderNameText;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment