Updating menu items in a status bar item
Updating menu items in a status bar item
- Subject: Updating menu items in a status bar item
- From: Jeffrey Mattox <email@hidden>
- Date: Wed, 5 Feb 2003 02:58:31 -0600
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.