Mantas Laurinavičius
Mantas Laurinavičius

Reputation: 951

How to access default NSOPenPanel actions?

Which actions are fired when user uses default NSOpenPanel from Main Menu? How to get the selection from it without creating NSOpenPanel in the code?

Upvotes: 0

Views: 119

Answers (1)

Amin Negm-Awad
Amin Negm-Awad

Reputation: 16660

A.

Which actions are fired when user uses default NSOpenPanel from Main Menu?

There is no NSOpenPanel in the main menu. There is a menu item "Open…"

The automatism you might "feel" is implemented project dependently. But it is not there automatically. I think that some points has to be clearified:

a. Open Menu Item

The menu item "Open…" sends and only sends the action message openDocument: to the first responder. "Open…" does not open a panel, window dialog or $whatever.

Please get some information about first responders and the responder chain. It is a pity, that even the responder chain is one of the core concept of Cocoa, it is very unknown.

b. Open Panel

If you choosed to have a document based application, when you created the project, some additions are made to your project. In particular,

Since NSDocumentController implements -openDocument:, it will catch the action message and

  • run an open panel
  • creates an instance of NSDocument. (More precise: of the subclass you selected as the document class.)

B.

How to get the selection from it without creating NSOpenPanel in the code?

  • Create a document-based app and let Cocoa do what it has to do. The base implementation of Cocoa matches 99 % of the cases and can be customized highly.
  • Do not create a document-based app: Handle the action message yourself, open a open panel yourself, after finishing that, create the instance of a document class and so on.

Upvotes: 1

Related Questions