From: Adam M. <ama...@us...> - 2006-02-21 04:58:37
|
Update of /cvsroot/bibdesk/bibdesk In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18988 Modified Files: Tag: BR_1x NSWorkspace_BDSKExtensions.h NSWorkspace_BDSKExtensions.m Log Message: Add methods for dealing with UTI in the NSWorkspace category. Add a method for comparing strings as UTI (NSString category). Index: NSWorkspace_BDSKExtensions.m =================================================================== RCS file: /cvsroot/bibdesk/bibdesk/Attic/NSWorkspace_BDSKExtensions.m,v retrieving revision 1.1.2.7 retrieving revision 1.1.2.8 diff -C2 -d -r1.1.2.7 -r1.1.2.8 *** NSWorkspace_BDSKExtensions.m 3 Jan 2006 21:52:09 -0000 1.1.2.7 --- NSWorkspace_BDSKExtensions.m 21 Feb 2006 04:58:24 -0000 1.1.2.8 *************** *** 158,160 **** --- 158,192 ---- } + - (NSString *)UTIForURL:(NSURL *)fileURL; + { + NSParameterAssert([fileURL isFileURL]); + + fileURL = [fileURL fileURLByResolvingAliases]; + FSRef fileRef; + CFURLGetFSRef((CFURLRef)fileURL, &fileRef); + CFTypeRef theUTI = NULL; + OSStatus err = LSCopyItemAttribute(&fileRef, kLSRolesAll, kLSItemContentType, &theUTI); + + [(id)theUTI autorelease]; + + NSAssert((CFGetTypeID(theUTI) == CFStringGetTypeID()), @"Unexpected CF type returned from LSCopyItemAttribute"); + + return err == noErr ? (NSString *)theUTI : nil; + } + + - (NSString *)UTIForPathExtension:(NSString *)extension; + { + return [(id)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (CFStringRef)extension, NULL) autorelease]; + } + + + @end + + @implementation NSString (UTIExtensions) + + - (BOOL)isEqualToUTI:(NSString *)UTIString; + { + return (UTIString == nil || UTTypeEqual((CFStringRef)self, (CFStringRef)UTIString) == FALSE) ? NO : YES; + } + @end Index: NSWorkspace_BDSKExtensions.h =================================================================== RCS file: /cvsroot/bibdesk/bibdesk/Attic/NSWorkspace_BDSKExtensions.h,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** NSWorkspace_BDSKExtensions.h 2 Jan 2006 20:22:51 -0000 1.1.2.2 --- NSWorkspace_BDSKExtensions.h 21 Feb 2006 04:58:24 -0000 1.1.2.3 *************** *** 52,54 **** - (BOOL)openURL:(NSURL *)fileURL withSearchString:(NSString *)searchString; ! @end \ No newline at end of file --- 52,78 ---- - (BOOL)openURL:(NSURL *)fileURL withSearchString:(NSString *)searchString; ! /*! ! @method UTIForURL: ! @abstract Uses LaunchServices to find the UTI for a given file URL. ! @discussion (comprehensive description) ! @param fileURL (description) ! @result (description) ! */ ! - (NSString *)UTIForURL:(NSURL *)fileURL; ! ! /*! ! @method UTIForPathExtension: ! @abstract Returns the UTI for the given path extension, or nil if no UTI is found. ! @discussion (comprehensive description) ! @param extension (description) ! @result (description) ! */ ! - (NSString *)UTIForPathExtension:(NSString *)extension; ! ! @end ! ! @interface NSString (UTIExtensions) ! ! - (BOOL)isEqualToUTI:(NSString *)UTIString; ! ! @end |