1

In our Cocoa NSDocument-based application we have a Save (saveDocument:) button on a context menu, but we want the text of the menu-item to change depending on the circumstances of the NSDocument, in the same way that the main menu Save (saveDocument:) menu-item changes. Does anyone know a clean solution to update this menu-item text, ideally calling on the same Cocoa functionality that the main menu uses?

Details:

The main menu in a Cocoa NSDocument-based application usually has a Save menu item that fires First Responder - saveDocument:. The title of this menu item changes depending on the circumstances of the document, for example:

  • In Lion (OS X 10.7) the menu-item text starts out as 'Save', but becomes 'Save a Version' (eg after the document has been saved).
  • In Mountain Lion (OS X 10.8), the menu item text starts out as 'Save...', but because 'Save' (eg after the document has been saved).

In our app, we display a context menu with a Save menu-item, and so we want the text to change in the same way as in the main menu (listed above). We don't want to have to write code that contains complicated logic (check the NSDocument... check the OSX version and show a string accordingly) and we are really looking to be able to call the same code that the Cocoa main menu uses to change the menu-item title.

4

0 に答える 0