How to launch "Choose Application" dialog on Mac?
I am using LSOpenItemsWithRole()
to open any file from my application. It works 开发者_如何学JAVAfine for all files which has a default application on Mac, but for the files which cannot be opened with any default application this method returns an error kLSApplicationNotFoundErr
and does nothing.
For such cases, I want my application to launch the "Choose Application" dialog box, so that end users can choose any application from there to open the file. This dialog box pops up whenever any such file is directly opened by double clicking. Is there is any direct API call to do the same?
I don't want to use Objective C call, is there any way to do it using Carbon API calls?
You should use an NSOpenPanel
, starting the user in the Applications folder use and the panel:shouldEnableURL:
delegate method to filter out paths that don't end in .app. You can use setAccessoryView:
to add any custom options to the dialog. This is what the Finder is doing when you click on the "Other..." option when selecting which application to use.
I think you can do it by using NavCreateChooseFileDialog, with NavCustomControl to set the initial location and NavDialogSetFilterTypeIdentifiers to filter out non-apps. (Why don't you want to use Objective-C? You know that you can mix Carbon and Cocoa in one app, right?)
精彩评论