Permalink
Browse files

A dir with ext could be a bundle with its own icon.

  • Loading branch information...
1 parent 3d1fa1c commit 5cbd2470d8dc34788df0db0b950dc69fc1055939 @alloy committed Sep 10, 2012
Showing with 12 additions and 4 deletions.
  1. +12 −4 src/MacVim/MMFileBrowserController.m
@@ -53,9 +53,8 @@ - (MMFileBrowserFSItem *)_itemAtPath:(NSArray *)components;
@implementation MMFileBrowserFSItem
+// TODO remove this from the global namespace, have one instance shared by all fs items for one file browser instance
static NSMutableDictionary *iconCache = nil;
-
-// TODO use dispatch_once
+ (void)initialize {
if (self == [MMFileBrowserFSItem class]) {
iconCache = [NSMutableDictionary new];
@@ -319,8 +318,17 @@ - (NSImage *)icon {
if (icon == nil) {
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
NSString *type;
+ NSString *path = nil;
if (isDir) {
- type = @"MMFileBrowserFolder";
+ type = [[self relativePath] pathExtension];
+ if (type.length > 0) {
+ // This is possibly a 'bundle' dir (e.g. Foo.xcodeproj).
+ path = [self fullPath];
+ } else {
+ // It's not a 'bundle' dir, so use a normal folder icon.
+ type = @"MMFileBrowserFolder";
+ path = @"/var"; // Just pick a dir that's guaranteed to have a normal folder icon.
+ }
} else {
if (![ws getInfoForFile:[self fullPath] application:NULL type:&type]) {
NSLog(@"FAILED TO FIND INFO FOR %@", [self fullPath]);
@@ -330,7 +338,7 @@ - (NSImage *)icon {
icon = [iconCache valueForKey:type];
if (icon == nil) {
if (isDir) {
- icon = [ws iconForFile:[self fullPath]];
+ icon = [ws iconForFile:path];
} else {
icon = [ws iconForFileType:type];
}

0 comments on commit 5cbd247

Please sign in to comment.