diff --git a/Frameworks/OakAppKit/src/NSImage Additions.mm b/Frameworks/OakAppKit/src/NSImage Additions.mm index 33b639fb..6ee975c7 100644 --- a/Frameworks/OakAppKit/src/NSImage Additions.mm +++ b/Frameworks/OakAppKit/src/NSImage Additions.mm @@ -3,7 +3,23 @@ @implementation NSImage (ImageFromBundle) + (NSImage*)imageNamed:(NSString*)aName inSameBundleAsClass:(id)aClass { - return [[NSBundle bundleForClass:aClass] imageForResource:aName]; + if(!aName) + return nil; + + NSBundle* bundle = [NSBundle bundleForClass:aClass]; + NSString* name = [NSString stringWithFormat:@"%@.%@", [bundle bundleIdentifier], aName]; + + static NSMutableDictionary* cache = [NSMutableDictionary new]; + if(NSImage* res = [cache objectForKey:name]) + return res; + + if(NSImage* image = [[NSBundle bundleForClass:aClass] imageForResource:aName]) + { + [cache setObject:image forKey:name]; + return image; + } + + return nil; } // ===================================================