• 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
Re: Updating menu items in a status bar item
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Updating menu items in a status bar item


  • Subject: Re: Updating menu items in a status bar item
  • From: Daniel Jalkut <email@hidden>
  • Date: Wed, 5 Feb 2003 09:22:41 -0800

Hi Jeffrey - I have also been plagued by this "shortcoming" of the way menus are displayed. As far as I can tell (including setting breakpoints on postNotification and examining all notes that take place while clicking menus), there is no suitable notification for when a menu is about to display.

The general advise from Apple engineers seems to be that you should achieve your goal of a dynamic menu by implementing the "validateMenuItem:" method in whatever object is the target for your menu items. Unfortunately, this suggestion doesn't seem to do the trick so well when you want to be able to wholesale destroy and rebuild a menu before it is displayed. We really want something like a "validateMenu:" method instead.

So  I think your approach is probably a good one, to simply bypass the usual path to displaying a menu. As far as I know the only "legitimate" way to display a menu in an arbitrary place at an arbitrary time is by using the +popUpContextMenu class method of NSMenu to display the menu. You will probably have to make up a bogus Event object for the method so that you can cause the menu to display exactly where you want it to (regardless of where in your status item the click occurred).

Hope this helps. Yes, it's tedious and obnoxious. In general, the "menu customization" situation seems to be an ugly spot on Cocoa's otherwise easy-to-modify class structure. This is probably due to the replacement of some of Cocoa's menu handling classes (where you could otherwise add custom functionality) with direct call-through to Carbon menu manager implementations.

Cheers,
Daniel

On Wednesday, February 5, 2003, at 12:58 AM, Jeffrey Mattox wrote:

I have a NSStatusItem on the systemStatusBar that contains a NSMenu and several NSMenuItems. When I click on the status bar item, I see the menu items drop down from the status bar. So, I've proved to myself that I can create a drop down menu and I can select the items within it.

My problem is that my menu item titles are dynamic, and I won't know what they should be until the moment the status bar item is clicked. So, to get control when the status bar item is clicked, I don't do this (see why, below):

[theStatusBarItem setMenu:theMenu]

instead I do this:

[theStatusBarItem setAction:@selector(menuClicked:)];
[theStatusBarItem sendActionOn:NSLeftMouseDownMask];

and, sure enough, menuClicked runs when I click on the status bar item. In this case, however, the menu items do not appear (there aren't any because I skipped the setMenu:, as I must do according to the documentation for the NSStatusBar's setAction: method).

So, in menuClicked, I construct a menu and set the menu item titles, and then I need to cause them to be displayed. But, I can't figure out how to do that. If I do setMenu: there, they don't appear unless I release the mouse and click again.

What I need is a notification that the status bar is about to display the menu. Then I could still use setMenu early on, and simply set my menu item titles just before they are displayed. However, no such notification exists for the status bar.

So, I'm stuck. When I click on the status bar item, either I see my menu items, but the titles are stale, or I get control in order to set the titles, but the menu items don't appear.

Any ideas?

Jeff
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Updating menu items in a status bar item
      • From: Jeffrey Mattox <email@hidden>
References: 
 >Updating menu items in a status bar item (From: Jeffrey Mattox <email@hidden>)

  • Prev by Date: Re: Sorting an NSOutlineView
  • Next by Date: Re: Kernal/Quartz extension to "snap" mouse to nearest control
  • Previous by thread: Updating menu items in a status bar item
  • Next by thread: Re: Updating menu items in a status bar item
  • Index(es):
    • Date
    • Thread