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.
I have...
- Added do开发者_Python百科cument types to the project properties window
- Assigned my controller class as the application delegate
- Added the delegate application:openFile: to my controller class
First, make sure your File->Open menu item's selector is connected to the openDocument:
action of the First Responder.
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. 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.
The key is that something along the menu item's responder chain has to respond to the -openDocument: action. Normally it's the NSDocumentController
. I'd take a look at how an empty document-based application sets up that menu item.
精彩评论