NSOpenPanel - Set file type?

How about [openDlg setAllowedFileTypes:fileTypes];?


You're looking for a delegate method from NSSaveOpenPanel's delegate

-(BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename
{
        NSString* ext = [filename pathExtension];
        if (ext == @"" || ext == @"/" || ext == nil || ext == NULL || [ext length] < 1) {
                return TRUE;
        }

        NSLog(@"Ext: '%@'", ext);

        NSEnumerator* tagEnumerator = [[NSArray arrayWithObjects:@"png", @"tiff", @"jpg", @"gif", @"jpeg", nil] objectEnumerator];
        NSString* allowedExt;
        while ((allowedExt = [tagEnumerator nextObject]))
        {
                if ([ext caseInsensitiveCompare:allowedExt] == NSOrderedSame)
                {
                        return TRUE;
                }
        }

        return FALSE;
}

Then, set your panel's delegate to "self", or wherever your define this method above.

Tags:

Cocoa