> On 2015 Jan 16, at 21:34, Ken Thomases <k...@codeweavers.com> wrote:
> 
> How about, instead of calling through to super, you simply implement those 
> methods in the straightforward way by running the Open panel.  For 
> -runModalOpenPanel:forTypes:, set the directoryURL as you want, set 
> allowedFileTypes with the types array that was passed in, and call -runModal 
> on the panel and return its result.  For 
> -beginOpenPanel:forTypes:completionHandler:, set the same two properties and 
> then call -beginWithCompletionHandler: on the panel with the passed-in 
> completion handler.
> 
> The theory is that, if you call through to super, it will do the same thing 
> except it will set the directoryURL to whatever it thinks is best, replacing 
> the one you set in your override.  So, just don't give it that opportunity.

Hello again, Ken.  I think that the method -runModalOpenPanel:forTypes: is only 
there for legacy purposes.  The method that gets called in Yosemite is instead 
-beginOpenPanel:forTypes:completionHandler:.  So I performed the experiment you 
have suggested here on that method instead.

The TextEdit Apple sample code already overrides this method, and this is where 
I tried to -setDiretoryURL: the other day.  However, it calls through to super. 
 To experiment as you suggested, I replaced TextEdit’s DocumentController.m 
line 315, which calls to super…

    [super beginOpenPanel:openPanel forTypes:types 
completionHandler:^(NSInteger result) {

with three lines of code that instead run the open panel directly, giving it 
the same completion handler, and, of course, set the directory URL…

    [openPanel setDirectoryURL:[NSURL fileURLWithPath:@“/path/to/whatever"]] ;
    [openPanel setAllowedFileTypes:types] ;
    [openPanel beginWithCompletionHandler:^(NSInteger result) {

I built, ran, and clicked in the menu: File > Open.  Result: It works as 
expected.  The dialog navigates to /path/to/whatever.

So, yes, this is another workaround that one should consider, with the warning 
that I’ve not tested it fully.  It is certainly more robust, but more 
complicated than my first workaround, setting the NSNavLastRootDirectory in 
NSUserDefaults.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to