This is how I have my code set up: an Objective-C protocol that has a class 
function that returns an NSArray of UTIs that it can handle, and a member 
function that handles the file type:

@protocol PcsxrFileHandle <NSObject>

+ (NSArray *)utisCanHandle;
- (BOOL)handleFile:(NSString *)theFile;

@end

However, as my code is currently set up, the UTIs are used in a few special 
cases and are not called in determining what UTI opens what file. The code is 
set up like so:

- (BOOL)application:(NSApplication *)theApplication openFile:(NSString 
*)filename
{
        NSString *utiFile = [[NSWorkspace sharedWorkspace] typeOfFile:filename 
error:nil];
        NSObject<PcsxrFileHandle> *hand = nil;
        BOOL isHandled = NO;
        if(UTTypeEqual(CFSTR("com.codeplex.pcsxr.plugin"), 
(CFStringRef)utiFile)) {
                hand = [[PcsxrPluginHandler alloc] init];
                isHandled = [hand handleFile:filename];
        } else if(UTTypeEqual(CFSTR("com.codeplex.pcsxr.memcard"), 
(CFStringRef)utiFile)) {
                hand = [[PcsxrMemCardHandler alloc] init];
                isHandled = [hand handleFile:filename];
        } else if(UTTypeEqual(CFSTR("com.codeplex.pcsxr.freeze"), 
(CFStringRef)utiFile)) {
                hand = [[PcsxrFreezeStateHandler alloc] init];
                isHandled = [hand handleFile:filename];
        } else if(UTTypeEqual(CFSTR("com.alcohol-soft.mdfdisc"), 
(CFStringRef)utiFile) || UTTypeEqual(CFSTR("com.apple.disk-image-ndif"), 
(CFStringRef)utiFile) || UTTypeEqual(CFSTR("public.iso-image"), 
(CFStringRef)utiFile) || UTTypeEqual(CFSTR("com.codeplex.pcsxr.cuefile"), 
(CFStringRef)utiFile)) {
                hand = [[PcsxrDiscHandler alloc] init];
                isHandled = [hand handleFile:HandleBinCue(filename)];
        }
        if (hand) [hand release];
        return isHandled;
}

The PcsxrPluginHandler, PcsxrMemCardHandler, PcsxrFreezeStateHandler, and 
PcsxrDiscHandler all implement the PcsxrFileHandle protocol.
Is there a way to put classes into some sort of array to go through and check 
if the UTI of a file matches up to any of the UTIs that the class can handle?

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to