Re: NSOpenPanel runModalForTypes: trouble (was: lowercaseString on Jaguar)
Re: NSOpenPanel runModalForTypes: trouble (was: lowercaseString on Jaguar)
- Subject: Re: NSOpenPanel runModalForTypes: trouble (was: lowercaseString on Jaguar)
- From: Stephane Sudre <email@hidden>
- Date: Wed, 16 Jun 2004 14:19:05 +0200
On mercredi, juin 16, 2004, at 12:42 PM, Michael Becker wrote:
Hi!
I found the ACTUAL problem. NSOpenPanel's
runModalForDirectory:file:types: takes an NSArray for the 'filetypes'
parameter. However, it seems to be case-sensitive on 10.2.8, whereas
it is case-insensitive on 10.3.
I want people to only load JPEG-Images, do I have to provide an array
with all possible versions of capitalization of the words 'JPG' and
'JPEG'? Or is there something I am missing?
#import "MainController.h"
@implementation MainController
- (void) awakeFromNib
{
NSOpenPanel * tOpenPanel;
tOpenPanel=[NSOpenPanel openPanel];
[tOpenPanel setDelegate:self];
[tOpenPanel runModalForDirectory:nil file:nil types:nil];
}
- (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename
{
static NSFileManager * sFileManager=nil;
NSDictionary * tDictionary;
if (sFileManager==nil)
{
sFileManager=[NSFileManager defaultManager];
}
tDictionary=[sFileManager fileAttributesAtPath:filename
traverseLink:YES];
if (tDictionary!=nil)
{
NSString * tFileType;
tFileType=[tDictionary objectForKey:NSFileType];
if ([tFileType isEqualToString:NSFileTypeDirectory]==YES)
{
return YES;
}
else if ([tFileType isEqualToString:NSFileTypeRegular]==YES)
{
NSNumber * tFileTypeCode;
NSString * tFileExtension;
tFileTypeCode=[tDictionary objectForKey:NSFileHFSTypeCode];
if (tFileTypeCode!=nil)
{
if ([tFileTypeCode unsignedLongValue]=='JPEG')
{
return YES;
}
}
tFileExtension=[filename pathExtension];
if ([tFileExtension
caseInsensitiveCompare:@"JPEG"]==NSOrderedSame ||
[tFileExtension
caseInsensitiveCompare:@"JPG"]==NSOrderedSame)
{
return YES;
}
// If you really want to, you can also check the Magic
cookie at the beginning of the JPEG file if there's any.
// To be continued
}
}
return NO;
}
@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.