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 document-based Cocoa application. At startup, the user is presented
I have a simple document-based Cocoa app that acts as a viewer for .wav
I'm developing a Cocoa/Objective C application that reads the active document from any application
I'm working with CoreData in Cocoa (not document-based). My problem is, that I want
I'm going through a refactoring and reorganization of my application at the moment. I've
I'm working on my first major Cocoa app for an undergraduate research project. The
Apple has a nice little tutorial for making a simple master-detail interface. Interface Builder
I'm following a tutorial on how to use Interface Builder from Chapter 2 of
I found there are at least three ways to launch an app with Mac
When executing the following code I receive a run time error when the code

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.