문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top