3

When using NSOpenPanel to open files, I am trying to let the user only select iPhoto libraries. An Aperture library, for example, has the extension .aplibrary. An iPhoto library, however, seems to have no extension.

For your information, the Aperture and iPhoto libraries are bundles to be completely correct. The Aperture bundles have an .aplibrary extension while the iPhoto bundles seem to have no extension.

How can I let the user only select iPhoto bundles? Due to the lack of an extension I cannot use "setAllowedFileTypes". iPhoto, however, does seem to be able to make the distinction, but I don't see how that's done in this case.

Bart Jacobs
  • 9,022
  • 7
  • 47
  • 88

1 Answers1

3

NSOpenPanel has a delegate, which should implement NSOpenSavePanelDelegate. One of the methods on that is -panel:shouldEnableURL: - if you implement that method, you can detect whether to let someone open a location based on whatever logic you want.

  • 1
    Thanks for your response, Graham. The problem is that the user only get feedback after clicking the "Open" button. I'm looking for a method to have files that shouldn't be opened being grayed out. – Bart Jacobs Jan 21 '11 at 11:12
  • @bare_nature: `-panel:shouldEnableURL:` is called whenever a file is presented. You're thinking of `-panel:validateURL:error:` which gets called after the user clicks "Open". –  Jan 21 '11 at 11:16