Skip to content

Commit

Permalink
Added ability to specify bundle, which makes this usable with non-mai…
Browse files Browse the repository at this point in the history
…n bundle images.
  • Loading branch information
aparajita committed Apr 6, 2012
1 parent d76706b commit 129a8cb
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion AppKit/Cib/_CPCibCustomResource.j
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ var _CPCibCustomResourceClassNameKey = @"_CPCibCustomResourceClassNameKey",
return [[self alloc] initWithClassName:@"CPImage" resourceName:aResourceName properties:[CPDictionary dictionaryWithObject:aSize forKey:@"size"]];
}

+ (id)imageResourceWithName:(CPString)aResourceName size:(CGSize)aSize bundleClass:(CPString)aBundleClass
{
return [[self alloc] initWithClassName:@"CPImage" resourceName:aResourceName properties:[CPDictionary dictionaryWithObjects:[aSize, aBundleClass] forKeys:[@"size", @"bundleClass"]]];
}

- (id)initWithClassName:(CPString)aClassName resourceName:(CPString)aResourceName properties:(CPDictionary)properties
{
self = [super init];
Expand Down Expand Up @@ -89,7 +94,18 @@ var _CPCibCustomResourceClassNameKey = @"_CPCibCustomResourceClassNameKey",
else if (_resourceName == "CPRemoveTemplate")
return [[CPImage alloc] initWithContentsOfFile:[[CPBundle bundleForClass:[CPButtonBar class]] pathForResource:@"minus_button.png"] size:CGSizeMake(11, 4)];

return [[CPImage alloc] initWithContentsOfFile:[[aCoder bundle] pathForResource:_resourceName] size:_properties.valueForKey(@"size")];
var bundleClass = _properties.valueForKey(@"bundleClass"),
bundle = nil;

if (bundleClass)
{
bundleClass = CPClassFromString(bundleClass);

if (bundleClass)
bundle = [CPBundle bundleForClass:bundleClass];
}

return [[CPImage alloc] initWithContentsOfFile:[(bundle || [aCoder bundle]) pathForResource:_resourceName] size:_properties.valueForKey(@"size")];
}

return self;
Expand Down

0 comments on commit 129a8cb

Please sign in to comment.