• 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: newb question on documents, nibs & the menu bar
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: newb question on documents, nibs & the menu bar


  • Subject: Re: newb question on documents, nibs & the menu bar
  • From: PGM <email@hidden>
  • Date: Sat, 28 Jan 2006 20:55:37 -0500

Yeah, I indeed have a windowDidBecomeMain notification upon which the menu is ticked. Another way to do it would be to put the code in - (BOOL)validateMenuItem:(NSMenuItem*)anItem, so that it is invoked when the user actually clicks the menu. However, as people more often click in menus than that they change documents and validateMenuItem is invoked for every item in the menu, the latter method would give substantially more overhead.

Maybe there's a way to do it using bindings, but I never really got into those (I somehow started out with my app thinking that I wanted it to be able to run on Jaguar).

Patrick


On 28 Jan, 2006, at 16:09, Mike Abdullah wrote:

OK, I can see how that code would work. But the thing is, say I switch to a different document within the app which has a different setting, then surely this wouldn't work? As far as I can see, I would have to detect the document switch somehow and set the menu bar manually from this.

It just seems to me that this is not a very Cocoa way of doing things, that's all.

Mike.

On 28 Jan 2006, at 20:30, PGM wrote:

I use something like the following. I modified the code a bit in Mail, so there is no guarantee that simply copy pasting will work, but you may get the idea.

//connect this action to the popUpButton
//or include the code into your own popUpButton action
- (IBAction)clickedPopUpButton:(id)sender
{
    int choice = [sender indexOfSelectedItem];

//get the menu to which the submenu belongs ("Action") and then the submenu ("Choice")
NSMenu *choiceMenu = [[[[[NSApp mainMenu] itemWithTitle:@"Action"] submenu] itemWithTitle:@"Choice"] submenu];


int i;
//loop through the available choices (three in your case) and tick the correct one
for(i = 0; i < [choiceMenu numberOfItems]; i++){
if(i == choice){
[[choiceMenu itemWithTag:i] setState:NSOnState];
}
else{
[[choiceMenu itemWithTag:i] setState:NSOffState];
}
}
}


Best, Patrick

On 28 Jan, 2006, at 14:48, Mike Abdullah wrote:

I need some advice on getting the right behaviour in my app with regard to the menu bar.

I have a doc-based app. In the document window there is a popup button which offers the user 3 different choices. In my menu bar there is a submenu that offers the equivalent of this, with a sperate menu item for each item in the popup button.

I have used the First Responder in MainMenu.nib to send the events of the user clicking on the menu bar item to the window's controller and this works fine. However, how do I send stuff back? I need to place a tick by whichever of the menu bar choices the user has made.

Thanks,
Mike.


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden


This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: newb question on documents, nibs & the menu bar
      • From: Mike Abdullah <email@hidden>
References: 
 >newb question on documents, nibs & the menu bar (From: Mike Abdullah <email@hidden>)
 >Re: newb question on documents, nibs & the menu bar (From: PGM <email@hidden>)
 >Re: newb question on documents, nibs & the menu bar (From: Mike Abdullah <email@hidden>)

  • Prev by Date: CoreData + NSTreeController + NSOutlineView help with basics
  • Next by Date: Forcing a table row to redraw
  • Previous by thread: Re: newb question on documents, nibs & the menu bar
  • Next by thread: Re: newb question on documents, nibs & the menu bar
  • Index(es):
    • Date
    • Thread