CocoaDev

Edit AllPages

Here’s a simple finder for an NSBrowser view using basic C function calls. You can find many of the icons in the systems folder by searching for “.icns” file extensions. Check out NSBrowserIcons for info on how to create images that are more suited for being displayed in an NSBrowser view –zootbobbalu

I still have to add the hooks for general file extensions, but this NSBrowser delegate works pretty good as is.

The number of levels this delegate will buffer is currently set at 256 (MAX_BROWSER_COLUMNS)

CFinder.h

#import <Cocoa/Cocoa.h> #define MAX_BROWSER_COLUMNS 256 #define MAX_DIRENT_NAMLEN 256

@interface CFinder : NSObject { struct dirent *directoryEntryBuffers[MAX_BROWSER_COLUMNS]; int entryCounts[MAX_BROWSER_COLUMNS]; int bufferCapacities[MAX_BROWSER_COLUMNS]; NSMutableDictionary *fileIcons; NSMutableDictionary *folderIcons; NSImage *genericDocumentIcon, *genericFolderIcon, *applicationIcon, *homeFolderIcon, *privateFolderIcon, *usersFolderIcon, *quickTimeIcon, *developersIcon; NSArray *imageTypes, *movieTypes, *bundles; char *cStringBuffer, *cStringBuffer2; NSMutableDictionary *chalkboard; char homeDir[256];

} @end

CFinder.m

#import “CFinder.h” #import #import <sys/types.h> #import <sys/stat.h> #import "fcntl.h" #import "unistd.h" #import <sys/time.h>

static NSString *ExtensionFromName(struct dirent *entry) { int i = entry->d_namlen; for (; i; –i) { if (entry->d_name[i] == ‘/’) return @””; if ((entry->d_name[i] == ‘.’) && ((i + 1) < entry->d_namlen)) { return [NSString stringWithCString:&entry->d_name[i + 1]]; } } return @””; }

@interface CFinder (Private)

@implementation CFinder

}

}

}

}

@end