Just as an updated summary of how one does that today, here's a step-by-step guide of what I had to do:
Create an application project from the Cocoa Application template using Xcode.
Check Create Document-based Application and leave whatever it suggests there for the "Document Extension" (it will refuse to enable the "Next" button if you delete the filename extension it right here, so we'll do that later).
Click your project's icon, go to the Info tab and to Document Types.
Delete the contents of the Extensions field. Our folders don't need a particular filename suffix
Write public.folder into the Identifier field.
Under Additional document type properties in the CFBundleTypeOSTypes array add one entry, fold (just those four lowercase letters). Not sure if that is necessary, but it's at least correct.
Make sure document is distributed as a bundle is not checked.
Create an NSDocumentController
subclass containing the following method to your project. Name it E.g. ULIFolderDocumentController
.
-(void)openDocument:(id)sender
{
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setCanChooseFiles:NO];
[panel setCanChooseDirectories:YES];
[panel setAllowsMultipleSelection:NO];
[panel beginWithCompletionHandler: ^( NSInteger result )
{
if (result == NSFileHandlingPanelOKButton)
{
NSURL* selectedURL = [[panel URLs] objectAtIndex:0];
NSLog(@"selected URL: %@", selectedURL);
[self openDocumentWithContentsOfURL: selectedURL
display: YES
completionHandler: ^(NSDocument * _Nullable document, BOOL documentWasAlreadyOpen, NSError * _Nullable error)
{
NSLog(@"%spened document %@ (%@)", (documentWasAlreadyOpen? "Reo" : "O"), document, error);
}];
}
}];
}
- Add a line to your app delegate's
-init
method that loads your subclass instead of NSDocumentController
. This is easy, just request the shared object:
[ULIFolderDocumentController sharedDocumentController]; // Override system's NSDocumentController with ours.
- Try it! :)