Methods to customize directory in NSOpenPanel do not work

Originator:jerrykrinock
Number:rdar://19496899 Date Originated:2015-Jan-16
Status:Open Resolved:
Product:OS X SDK Product Version:10.10.1
Classification:Serious Bug Reproducible:Always
 
Summary:
-[NSDocumentController currentDirectory] has no effect.
-[NSOpenPanel setDirectoryURL:] has no effect.

Steps to Reproduce:
1.  Open Apple's TextEdit Sample Project in Xcode.
2.  Open the DocumentController.m file.
3.  Insert the following code at line 315:

NSString* path = [NSHomeDirectory() stringByAppendingPathComponent:@"Desktop"] ;
[openPanel setDirectoryURL:[NSURL fileURLWithPath:path]] ;
    
4.  Insert the following override somewhere in the implementation:

- (NSString*)currentDirectory {
    return [NSHomeDirectory() stringByAppendingPathComponent:@"Desktop"] ;
}

5.  Build and run.

6.  Click in the menu: File > Open.

Expected Results:
Based on the documentation of -[NSDocumentController currentDirectory] and
-[NSOpenPanel setDirectoryURL:], either of the changes made in the code should cause the open panel to navigate to your Desktop.

Actual Results:
The open panel will navigate to either the last file opened (NSNavLastRootDirectory in user defaults) or ~/Documents.   The inserted code will never have the effect which the documentation indicates it should.

Version:
Xcode 6.1.1

Notes:
The documented behavior is necessary for (1) "semi-shoebox" apps for which users typically create one or a few documents, or for apps that might use a directory of templates or scripts as documents.  To work around this bug, the developer may set the value of key "NSNavLastRootDirectory" in NSUserDefaults standardUserDefaults to the desired directory.

I suggest that -[NSDocumentController currentDirectory] be marked as either deprecated or ignored, and that -[NSOpenPanel setDirectoryURL:] be fixed.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!