Question

I have an application with multiple documents opened at once (as different tabs), but not implemented the Cocoa way, with NSDocument etc

So, let's say, that application is a text editor : e.g. an NSTextView in each document/tab and a menu (in the MainMenu) with options (on/off) related to that particular document.

Scenarios :

  • The user clicks a menu item (option) and the option is applied to the current tab
  • Now, the user switches tab and the options (of the menu) should be update according to current document's settings

How should I go about that in the most Cocoa-friendly way?

(I certainly CAN do it; though I'm interested in what could be a more efficient way (and my definitely isn't))

Was it helpful?

Solution

You can implement validateUserInterfaceItem: on NSDocument. Menu and toolbar items call it to check if they should be enabled or not. Read about Implementing Validation in general and Enabling Menu Items specifically.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top