• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Kludges when binding to 'value' of Menu Items
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Kludges when binding to 'value' of Menu Items


  • Subject: Kludges when binding to 'value' of Menu Items
  • From: Jerry Krinock <email@hidden>
  • Date: Tue, 16 Oct 2007 05:05:14 -0700

I'm beginning to think that, in general, using the 'value' bindings in main menu items is not very well supported and maybe not a good idea.

Issue #1...

My main menu has an item which reflects a boolean value (checkmark), bound to an attribute of the frontmost document via my document controller. However, invoking will/did change was complicated because, besides observing changes in this document attribute, I also have to observe for possible changes in the frontmost document itself, and I can't find any "willChange" notification for the latter.

I've gotten it working by remembering as an ivar the "previous" document, observing NSWindowDidBecomeMainNotification, and writing what seems like alot of code to detect changes, etc. I don't like it. In order to ^properly^ invoke willChangeValueForKey:, I would need to know ^beforehand^ when the frontmost document will change. Note that this is usually caused by the user activating a different window, something only Cocoa is aware of. So I need something like...

NSWindow^Will^BecomeMainNotification

or, even better

NSFrontmostDocumentWillChange
NSFrontmostDocumentDidChange

but I can't find any such things.  Are there any?

Issue #2...

Besides the above problem, there's also the issue that menu items need a dummy "target" to ever be enabled, even if their action is accomplished via bindings. So I wire all their targets to this...

- (IBAction)dummyAction:(id)sender {
}

(Binding 'enabled' to YES is not sufficient is not sufficient to overcome the requirement for a target.)

Again, it works, but is there a less kludgey way to do this?

Jerry Krinock
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Kludges when binding to 'value' of Menu Items
      • From: "I. Savant" <email@hidden>
  • Prev by Date: Re: Binding NSPopupButton crashes
  • Next by Date: Question about laterDate: and earlierDate:
  • Previous by thread: Re: Button enabled.
  • Next by thread: Re: Kludges when binding to 'value' of Menu Items
  • Index(es):
    • Date
    • Thread