Skip to content

Instantly share code, notes, and snippets.

@nickjs
Created November 21, 2008 10:17
Show Gist options
  • Save nickjs/27408 to your computer and use it in GitHub Desktop.
Save nickjs/27408 to your computer and use it in GitHub Desktop.
@implementation LEProfilePresentation : CPDictionary
{
CPString _name @accessors(property=name);
BOOL _notSizable;
}
+ (id)alloc
{
var object = [CPDictionary alloc];http://gist.github.com/images/modules/gist/paste_button.png
object.isa = [self class];
object._name = nil;
return object;
}
+ (LEProfilePresentation)presentation
{
return [[self alloc] init];
}
- (id)initWithProfilePresentation:(LEProfilePresentation)aPresentation
{
self = [[LEProfilePresentation alloc] init];
if(self)
{
if([aPresentation name])
[self setName:[aPresentation name]];
var key = "";
for (key in aPresentation._buckets)
[self setValue:[aPresentation valueForKey:key] forKey:key];
}
return self;
}
- (id)copy
{
return [[LEProfilePresentation alloc] initWithProfilePresentation:self];
}
- (void)mapToView:(CPView)aView
{
for(var i = 0; i < [[self allKeys] count]; i++)
{
var key = [self allKeys][i];
if([aView respondsToSelector:key])
{
[aView setValue:[self objectForKey:key] forKey:key];
[self addObserver:self forKeyPath:key options:CPKeyValueObservingOptionNew context:aView];
}
}
}
- (void)mapToThumbnail:(CPView)aView
{
if([self backgroundColor])
[aView setBackgroundColor:[self backgroundColor]];
if([self foregroundColor])
[aView setForegroundColor:[self foregroundColor]];
if([self image])
{
[aView setImage:[self image]];
[aView setImageScaling:[self imageScaling]];
}
else
{
[aView setImage:nil];
}
}
- (void)setValue:(id)value forKey:(CPString)key
{
[self willChangeValueForKey:key];
[super setObject:value forKey:key];
[self didChangeValueForKey:key];
}
- (void)observeValueForKeyPath:(CPString)key ofObject:(id)object change:(CPDictionary)change context:(id)aView
{
if(aView)
if([aView respondsToSelector:key])
[aView setValue:[self objectForKey:key] forKey:key];
}
- (CPMethodSignature)methodSignatureForSelector:(SEL)selector
{
return 1;
}
- (void)forwardInvocation:(CPInvocation)invocation
{
var sel = [invocation selector];
if([sel hasSuffix:":"])
sel = [sel substringToIndex:[sel length]-1];
if([sel hasPrefix:"set"])
{
sel = [sel substringFromIndex:3];
var x = [sel substringToIndex:1];
x = [x lowercaseString];
sel = x + [sel substringFromIndex:1];
[invocation setTarget:self];
[invocation setSelector:@selector(setValue:forKey:)];
[invocation setArgument:[invocation argumentAtIndex:2] atIndex:2];
[invocation setArgument:sel atIndex:3];
}
else
{
[invocation setTarget:self];
[invocation setSelector:@selector(valueForKey:)];
[invocation setArgument:sel atIndex:2];
}
[invocation invoke];
}
- (BOOL)notSizable
{
if(self._notSizable)
return self._notSizable;
else
return NO;
}
- (void)setNotSizable:(BOOL)flag
{
self._notSizable = flag;
}
@end
@implementation LEProfilePresentation (CPCoding)
- (id)initWithCoder:(CPCoder)aCoder
{
var dict = [aCoder decodeObjectForKey:"presentation"];
return [[LEProfilePresentation alloc] initWithProfilePresentation:dict];
}
- (void)encodeWithCoder:(CPCoder)aCoder
{
self.isa = CPDictionary;
[aCoder encodeObject:self forKey:"presentation"];
self.isa = LEProfilePresentation;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment