Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MorphingDragon

macrumors 603
Original poster
I'm having issues getting an NSOpenPanel to only select folders. File selection is false but for some reason I can still select files.

Code:
//Create open panel dialog
NSOpenPanel *open = [NSOpenPanel openPanel];

//Disable file selection
[open setCanChooseFiles: false];

//Enable folder selection
[open setCanChooseDirectories: true];

//Enable alias resolving
[open setResolvesAliases: true];

//Disable multiple selection
[open setAllowsMultipleSelection: false];

//Display open panel
[open runModal];

//Get source folder name
NSURL* source = [[[open URLs] objectAtIndex: 0] retain];
 
Works for me under Mac OS X 10.6.7. Files are grayed-out. The open button is always enabled. If nothing is selected, then the "current folder" is chosen.

BTW NSOpenPanel inherits URL from NSSavePanel. So instead of [[open URLs] objectAtIndex: 0], you can simply use [open URL].

And don't forget to check the return value of runModal. It will be NSFileHandlingPanelOKButton if the user clicks Open, otherwise it will be NSFileHandlingPanelCancelButton.
 
Last edited:
Works for me under Mac OS X 10.6.7. Files are grayed-out. The open button is always enabled. If nothing is selected, then the "current folder" is chosen.

BTW NSOpenPanel inherits URL from NSSavePanel. So instead of [[open URLs] objectAtIndex: 0], you can simply use [open URL].

And don't forget to check the return value of runModal. It will be NSFileHandlingPanelOKButton if the user clicks Open, otherwise it will be NSFileHandlingPanelCancelButton.

I cleaned my project build and now it works fine. 😕
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.