Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3341954
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:46:56+00:00 2026-05-18T00:46:56+00:00

In a Cocoa document-based application, what’s the best way to keep the menu item

  • 0

In a Cocoa document-based application, what’s the best way to keep the menu item states in the menu bar in sync with the currently visible document?

For example, say you have a document with a ruler view that can be hidden/shown via “Show Rulers” (off state) and “Hide Rulers” (on state) menu items. The user has two documents open at the same time. He/she has hidden the rulers in one document, but not on the other. When the user moves between the documents the menu item should reflect the state for that document, not for the application as a whole.

How does one do this cleanly? I’ve googled around but it doesn’t seem like there’s a predefined “out of the box” way to do this. It would be nice if NSDocument had some sort of “didRegainFocus” type method where such logic can be added.

My actual implementation is a bit trickier since it’s actually a NSViewController inside my NSDocument that deals with these particular menu items.

@interface MyDocument : NSDocument {
  SomeViewController *myCustomizedTextViewController;
}

When MyDocument is the currently active document, I need methods in myCustomizedTextViewController to ensure the state of a couple of NSMenuItems in the application’s main menu. One is genuinely a ruler. The other is a similar temporary setting.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:46:57+00:00Added an answer on May 18, 2026 at 12:46 am

    Have the target of the menu items implement the validateUserInterfaceItem: method to enable/disable them. See the User Interface Validation reference for more info.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a Cocoa document based application. I have a menu item
I have a Cocoa, Document-based Mac OS X application. One feature that I have
I am working on a document-based Cocoa application. At startup, the user is presented
Environment: xcode 3.2.1, document-based core-data application. I have a document-based cocoa app which uses
I am trying to implement a delegate method for my Cocoa document-based application which
I'm creating a simple Cocoa non-document based application. I want to show visually that
I have created a Cocoa document based picture drawing application. I want that the
Editing my nib for a document-based Cocoa application, I see that when I have
In a Document-based Cocoa application, handled file extensions are listed in the application's Info.plist
My document-based Cocoa application uses a NSOutlineView/NSTreeController combo, bound to the document's Core Data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.