• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSOpenPanel Exception/Bug
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSOpenPanel Exception/Bug


  • Subject: NSOpenPanel Exception/Bug
  • From: Seth Willits <email@hidden>
  • Date: Tue, 28 Jul 2009 16:54:58 -0700



I have an exception being thrown when an open panel is open. I can't reproduce it yet, but I really don't see what the problem is either. I think I'm just triggering a bug in NSOpenPanel. Here's the exception:


*** -[NSCFArray objectAtIndex:]: index (-1( or possibly larger)) beyond bounds (2)


_NSArrayRaiseBoundException (in Foundation) + 127
-[NSCFArray objectAtIndex:] (in Foundation) + 72
-[NSNavBrowserDelegate browser:willDisplayCell:atRow:column:] (in AppKit) + 94
-[NSBrowser _sendDelegateWillDisplayCell:atRow:column:] (in AppKit) + 134
-[NSBrowser _loadCell:atRow:col:inMatrix:] (in AppKit) + 561
-[NSMatrix drawRect:] (in AppKit) + 1587
...






The open panel should only allow text files to be selected. To do that, I'm using panel:shouldShowFilename: ....


- (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename
{
NSDictionary * attributes = [[NSFileManager defaultManager] fileAttributesAtPath:filename traverseLink:YES];
if (!attributes) return NO;

NSString * fileType = [attributes objectForKey:NSFileType];
NSString * hfsType = NSFileTypeForHFSTypeCode((OSType)[[attributes objectForKey:NSFileHFSTypeCode] unsignedLongValue]);
NSString * utiType = [[NSWorkspace sharedWorkspace] typeOfFile:filename error:nil];
NSString * extension = [filename pathExtension];

if ([[NSWorkspace sharedWorkspace] isFilePackageAtPath:filename]) {
return NO;
}

if ([fileType isEqual:NSFileTypeDirectory]) {
return YES;
}

if ([hfsType isEqual:NSFileTypeForHFSTypeCode('TEXT')]) {
return YES;
}

if ([[NSWorkspace sharedWorkspace] type:utiType conformsToType: (NSString *)kUTTypePlainText]) {
return YES;
}

if ([[NSArray arrayWithObjects:@"txt", @"text", <etcetera>, nil] containsObject:[extension lowercaseString]]) {
return YES;
}

NSString * usrBinFileType = [[NSFileManager defaultManager] fileTypeForFileAtPath:filename];
if ([[usrBinFileType lowercaseString] containsString:@"text" options: 0]) {
return YES;
}

return NO;
}




It works its way down to the last if statement which launches /usr/bin/ file to figure out the type of the file. It's all straight forward simple code, which simply returns YES or NO, but it's causing an exception apparently, and I don't see how I could do anything different.

Any thoughts?


-- Seth Willits



_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSOpenPanel Exception/Bug
      • From: Andy Lee <email@hidden>
  • Prev by Date: Fun (or not) with NSArrayControllers and CoreData.
  • Next by Date: Use of cells with custom controls
  • Previous by thread: Re: The mystery of the missing inverse relationship (was: Re: Fun (or not) with NSArrayControllers and CoreData.)
  • Next by thread: Re: NSOpenPanel Exception/Bug
  • Index(es):
    • Date
    • Thread