Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Cocoa : toggled menu item

Cocoa : toggled menu item
Thread Tools
Fresh-Faced Recruit
Join Date: Feb 2001
Location: Paris - France
Status: Offline
Reply With Quote
Aug 11, 2002, 04:13 PM
 
Hi everyone

I hope that question was not asked before, so it's bar basic.
I'm looking to make a toggled menu item on my app but i don't find the appriopriate documentation, neither a sample code to look.
I would like to make a menu item with two step Show / Hide "Window", like the toggle menu item when you show/hide a toollbar...

It's covered by the Aqua Human Interfaces guidelines pdf, but no indication found for "How To" this... (page 48)

For the moment I have two menu items :

-> Show The Window

- (IBAction)showWindowid)sender
{
/* display our window */
[self showTheWindow:itsWindow];
}

-> Hide The Window

- (IBAction)hideWindowid)sender
{
/* close our window */
[itsWindow close];
}

Of course, I made an IBOutlet for itsWindow


If anyone have an idea, I know it's a basic question, but it'll be much apprieciated

Thx,
Az'
Mac OS X : The power of UNIX with the simplicity and elegance of the
Macintosh. Simplicity is the Ultimate Sophistication...
     
Senior User
Join Date: Jan 2000
Status: Offline
Reply With Quote
Aug 11, 2002, 04:47 PM
 
Make an outlet for an NSMenuItem in your custom class, and hook it up to the menu item you want to control the window. Make the default title "Show window".

In your header file:

...
IBOutlet NSMenuItem *wMenuItem;
...

In your .m file:

Code:
- ( IBAction )showWindow: ( id )sender { [ wMenuItem setTitle: @"Hide Window" ]; [ self showTheWindow: itsWindow ]; } - ( IBAction )hideWindow: ( id )sender { [ wMenuItem setTitle: @"Show Window" ]; [ itsWindow close ]; }
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Aug 11, 2002, 07:04 PM
 
A more efficient way is to use the menu item validation protocol. Implement -(void)validateMenuItemid <NSMenuItem>)anItem on the class which implements your menu item action methods, find out which MenuItem you're being asked about by using [anItem action], and change the title using [anItem setTitle:]. This way you don't have to keep hooking up outlets for menu items, so it's easier to localize.
Rick Roe
icons.cx | weblog
     
Fresh-Faced Recruit
Join Date: Feb 2001
Location: Paris - France
Status: Offline
Reply With Quote
Aug 11, 2002, 08:19 PM
 
Thanks you Fitter and Rickster for your precious help.


In my code, the window is load when the application start.
So I need to implement a Hide menu by default.
I followed in the first time the fitter method, but in that case when the window is hide using the menu item ; and the menu turn to Show, the menu doesn't respond to the action "showWindow" to follow the come back of that window...
So I will implement the Void method : it's more appropriate.

thanks again.

Az'
Mac OS X : The power of UNIX with the simplicity and elegance of the
Macintosh. Simplicity is the Ultimate Sophistication...
     
Mac Enthusiast
Join Date: Jan 2001
Status: Offline
Reply With Quote
Aug 14, 2002, 07:50 PM
 
this is a shot in the dark, but shouldn't you try:

[window orderOut];

instead of:

[window close];

i thought 'close:' deallocated the window... by using 'orderOut:', you simply hide it...

just a thought

ps. I have no clue about what I'm talking about
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:09 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2