How can I prevent the user from choosing certain types of files?


I want to prevent the user to choose some file types when he opens NSOpenpanel. what i can do at the moment is preventing him from accessing all the files and allow some but i want to allow all the files except some.

NSOpenpanel*Openpane = [NSOpenpanl openpanel];
[Openpanel setAllowFileTypes(NSArray*)];

but i want the user to choose all the files except files not choose some files out of all the files.

Implement a delegate for the panel. NSOpenPanel inherits a delegate property from its superclass NSSavePanel.

In the delegate, implement either:

- (BOOL) panel:(id)sender shouldEnableURL:(NSURL*)url;


- (BOOL) panel:(id)sender validateURL:(NSURL*)url error:(NSError**)outError;

You should use the first one if you can decide whether a given URL should be enabled quickly and efficiently. It will be called frequently. It controls whether or not a given URL is selectable in the panel.

You should use the second one if your decision is slow or requires significant CPU or I/O. It is only called when the user clicks the Open button. That's not the best user experience. It's better to prevent the user from making a bad choice than to let them make a bad choice and reject it at the last moment.

All of that said, it's kind of weird to allow a user to select any kind of file except MP3s. Is there really no other restriction?