Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

  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
like image 467
papahabla Avatar asked Jan 18 '10 06:01

papahabla


2 Answers

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.

like image 200
CJ. Avatar answered Sep 20 '22 04:09

CJ.


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.

like image 36
John Calsbeek Avatar answered Sep 22 '22 04:09

John Calsbeek