Question

I have an NSOpenPanel. I want to make it so that PDF-files should not be selectable.

Just as we can set "Allowed File Types":

NSOpenPanel *panel;
NSArray* fileTypes = [[NSArray alloc] initWithObjects:@"pdf", @"PDF", nil];
panel = [NSOpenPanel openPanel];
[panel setFloatingPanel:YES];
[panel setCanChooseDirectories:NO];
[panel setCanChooseFiles:YES];
[panel setAllowsMultipleSelection:YES];
[panel setAllowedFileTypes:fileTypes];
int i = [panel runModal];
if(i == NSOKButton){
    return [panel URLs];
}

my requirement is to disallow a particular file type.

Was it helpful?

Solution

You can use the NSOpenSavePanelDelegate method panel:shouldEnableURL: for this.

The panel will ask its delegate about each URL it is displaying; check the file's extention or UTI, and return NO from that method for PDFs.

Alternatively, just come up with the exhaustive list of file types that you do support and use that for the allowedFileTypes array.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top