objective-ccocoafile-typensdocument

Open any folder with NSDocument


I am trying to write an application that can open any folder in the NSDocument subclass but can't figure out the right Info.plist settings. It is important that my app should not use bundles, neither folders with a particular file extensions, just be able to open any folder.

What I tried:

How can I open any folder in open file dialog?


Solution

  • You probably can't do this without writing some custom code.

    You need to present an NSOpenPanel manually, like this:

    NSOpenPanel *panel = [NSOpenPanel openPanel];
    [panel setCanChooseFiles:NO];
    [panel setCanChooseDirectories:YES];
    
    [panel beginSheetForDirectory:nil
                             file:nil
                   modalForWindow:[self window]
                    modalDelegate:self
                   didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:)
                      contextInfo:nil];
    

    An open panel presented in this way will let the use choose any directory they wish. You can implement NSOpenPanel's delegate methods to validate each folder and en/disable if if you need to.