开发者

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

开发者 https://www.devze.com 2022-12-17 10:48 出处:网络
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 filter

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 do开发者_Python百科cument 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消