NSOpenPanel problem with double-click


#1

I want to use NSOpenPanel to allow users to select ONLY jpeg images (as well as browsing directories). I am using the delegate shouldEnableURL method to selectively enable directories and jpeg files - all others being disabled. The panel shows the disabled entries correctly and simple click selection doesn’t do anything.

HOWEVER by double-clicking a disabled file it IS selected!

This behaviour is contrary to what happens with buttons etc. Double-clicking a disabled button does nothing.

What am I doing wrong?


#2

Answering my own question: the ‘setCanChoose …’ properties for the panel should be left at their default values (NO for directories and YES for files). The panel then works as it should.

The problem was caused by not thoroughly reading the book (Cocoa Programming …" - and thereby discovering that the bulk of the NSOpenPanel stuff is documented in the NSClosePanel reference. ConsequentlyI thought the only way to handle this panel stuff was using the methods of the NSOpenClosePanelDelegate!!

I also discovered the ‘setCanChooseDirectories’ and ‘setCanChooseFiles’ panel properties. Quickly you’ll discover that you must set setCanChooseFiles to YES. I made the MISTAKE of also explicitly setting setCanChooseDirectories = YES.
setCanChooseDirectories must be left at the default or explicitly set to NO. In the delegate method ‘shouldEnableURL’ you must identify directories and return YES for each of them to allow them to be selected in the panel.

A lot of self-inflicted pain but the solution was a little counter-intuitive.