Re: Programatically adding/removing menu items
Re: Programatically adding/removing menu items
- Subject: Re: Programatically adding/removing menu items
- From: Nicholas Riley <email@hidden>
- Date: Tue, 2 Jul 2002 05:45:54 -0500
- Mail-followup-to: Joe Morris <email@hidden>, CocoaDev <email@hidden>
On Tue, Jul 02, 2002 at 06:27:57AM -0400, Joe Morris wrote:
>
As an additional question, is this a good way to have a toggle for this
>
action? I really want to have a keyboard shortcut for it, so it needs
>
to be a menu item, but at least one other option would be to have both
>
Show and Hide always in the menu, and use the setState functions to put
>
a check next to the one that is in effect. Does anyone think one way is
>
better than the other for whatever reason?
I think you're working too hard :-) Here's how I do it, in a
NSWindowController subclass for a status window:
- (IBAction)showWindow:(id)sender;
{
[DockCamPrefs setBool: YES forPref: DCShowStatus];
[showHideStatusItem setAction: @selector(hideWindow:)];
[showHideStatusItem setTitle: @"Hide Status"];
[[self window] orderFront: self];
}
- (IBAction)hideWindow:(id)sender;
{
[[self window] orderOut: sender];
[DockCamPrefs setBool: NO forPref: DCShowStatus];
[showHideStatusItem setAction: @selector(showWindow:)];
[showHideStatusItem setTitle: @"Show Status"];
}
If you want the item titles to be localized, you'll have to work a
little harder, but that should be all.
--
=Nicholas Riley <email@hidden> | <
http://www.uiuc.edu/ph/www/njriley>
Pablo Research Group, Department of Computer Science and
Medical Scholars Program, University of Illinois at Urbana-Champaign
_______________________________________________
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.