views:

159

answers:

2

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...

  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
+1  A: 

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.

John Calsbeek
It's hooked up to first responder in MainMenu.xib. It should also be so hooked up in the non-document-based-app template's MainMenu.xib. If not, hook it up, then be in the responder chain and respond to `openDocument:`.
Peter Hosey
+1  A: 

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.

CJ