简体   繁体   English

在非基于文档的应用程序中启用打开文件菜单项

[英]Enabling open file menu item in a non-document-based application

I would like to enable the grayed out open file menu item within a non-document-based application.我想在非基于文档的应用程序中启用灰色的打开文件菜单项。 Document-based applications automatically give you a nice open file dialog with file extension filters based on plist entries etc... Surely, a simple elegant method exist to re-enable this functionality.基于文档的应用程序会自动为您提供一个漂亮的打开文件对话框,其中包含基于 plist 条目等的文件扩展名过滤器......当然,存在一种简单优雅的方法来重新启用此功能。

I have...我有...

  1. Added document types to the project properties window将文档类型添加到项目属性窗口
  2. Assigned my controller class as the application delegate将我的控制器类分配为应用程序委托
  3. Added the delegate application:openFile: to my controller class将委托应用程序:openFile:添加到我的控制器类

The key is that something along the menu item's responder chain has to respond to the -openDocument: action.关键是菜单项的响应者链中的某些东西必须响应-openDocument:操作。 Normally it's the NSDocumentController .通常它是NSDocumentController I'd take a look at how an empty document-based application sets up that menu item.我会看看一个空的基于文档的应用程序是如何设置该菜单项的。

First, make sure your File->Open menu item's selector is connected to the openDocument: action of the First Responder.首先,确保您的文件->打开菜单项的选择器连接到第一响应者的openDocument:操作。

Second, make sure you are responding to the action.其次,确保你对行动做出反应。 Take a look at the Responder chain of a non-document application with an NSWindowController object .看一下带有 NSWindowController 对象的非文档应用程序的 Responder 链 Any object within your responder chain can respond to the message, but it is best to pick the object which is the most capable and appropriate.响应者链中的任何对象都可以响应消息,但最好选择最有能力和最合适的对象。 Once you have decided which class in your responder chain is the most appropriate to handle the message, add the openDocument: action to it's implementation and write your code to respond to it accordingly.一旦您决定了响应者链中的哪个类最适合处理消息,请将openDocument:操作添加到它的实现中并编写代码以相应地响应它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM