Macintosh C 创建导航窗口以选择应用程序
我正在为 mac 编写一个 C 程序,我需要允许用户选择一个应用程序来发送苹果事件。 我可以使用 NavCreateChooseFileDialog()
创建导航窗口,但无法让它启用任何 .app 文件。 如果我使用 NavDialogSetFilterTypeIdentifiers
限制类型,则它只允许我选择文件夹名称中不包含 .app 的应用程序,例如 MS Office。 其他一切都呈灰色。
有任何想法吗?
I'm writing a C program for mac, and I need to allow the user to choose an application to send an apple event to. I can create a navigation window, using NavCreateChooseFileDialog()
, but I can't get it to enable any .app files. If I restrict the types using NavDialogSetFilterTypeIdentifiers
, it will only allow me to select applications like MS Office, that don't have .app in the folder name. Everything else is greyed out.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
确保在 NavCreateChooseFileDialog 的 inOptions.optionFlags 中设置标志 kNavSupportPackages,并将“APPL”放入类型列表中(可能仍然使用该参数而不是 NavDialogSetFilterTypeIdentifiers(),这样您将在 10.3- 上运行)并且您应该很好,我刚刚尝试过。
或者,如果你不介意使用 Cocoa,你可以使用 -[NSOpenPanel runModalForTypes:[NSArray arrayWithObjects:@"app", nil]] (它也列出了非 .app 应用程序),然后你就只有一个 FSPathMakeRef ((UInt8*)[路径 fileSystemRepresentation], &fsRef, NULL); 远离 FSRef。
请记住,无论哪种情况,您获得的文件都可能是别名,因此您必须尝试解析别名。
Make sure to set the flag kNavSupportPackages in inOptions.optionFlags for NavCreateChooseFileDialog, and put 'APPL' in the types list (might as well still use that param instead of NavDialogSetFilterTypeIdentifiers(), that way you'll run on 10.3-) and you should be good to go, I just tried.
Alternatively, if you don't mind using Cocoa, you can use -[NSOpenPanel runModalForTypes:[NSArray arrayWithObjects:@"app", nil]] (which also lists non-.app applications), and then you're only one FSPathMakeRef((UInt8*)[path fileSystemRepresentation], &fsRef, NULL); away from an FSRef.
Do remember that, in either case, the file you get may be an alias so you will have to try and resolve aliases.
请记住,.app 捆绑包是目录,因此您可能需要启用某种允许目录(或者更可能的是启用捆绑包)选项。
很抱歉我无法提供更具体的帮助。 我从 Carbon 开始,但从未接触过导航服务。
Remember that .app bundles are directories, so you may need to enable some sort of allow-directories (or, more likely, enable-bundles) option.
I'm sorry that I can't offer more specific help. I started with Carbon, but never did touch Navigation Services.
这对我有用:
This works for me: