• 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: Prevent NSMenuItem selection
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Prevent NSMenuItem selection


  • Subject: Re: Prevent NSMenuItem selection
  • From: Ron Fleckner <email@hidden>
  • Date: Sat, 20 Oct 2007 08:10:38 +1000

Hey cool! After sending that post, I tried to implement it and failed. Thanks for the list of steps.
Ron


On 20/10/2007, at 1:44 AM, Greg Hoover wrote:

Thanks Ron,

That worked like a charm.  Here were the steps:
- setAutoenabledItems to NO for the menu
- setEnabled to NO for the header items
- setAttributedTitle using [NSColor blackColor] for the header items

It's unfortunate that there isn't a simpler way to do this (like a single call to an NSMenuItem). I tried subclassing NSMenuItem and making the custom class return YES for the isSeparatorItem but that also makes the cell only a few pixels high and doesn't draw the title string.

Thanks again.

Greg
On Oct 18, 2007, at 11:08 PM, Ron Fleckner wrote:

How about -setAttributedTitle:

From the docs:
	Specifies a custom string for a menu item.

	- (void)setAttributedTitle:(NSAttributedString *)string

	Parameters

	string
	An attributed string to use as the receiver's title.

	Discussion

You can use this method to add styled text and embedded images to menu item strings. If you do not set a text color for the attributed string, it is black when not selected, white when selected, and gray when disabled. ***Colored text remains unchanged when selected.***

Note the marked text at the end. I've not tried it but it looks promising.



Ron	




On 19/10/2007, at 2:03 PM, Greg Hoover wrote:

Not exactly. I don't want it greyed out -- just want it not to be selectable. I suppose I could subclass to get the same effect...but am hoping not to have to go that route.

BTW-- It's only greyed out if implement the validateUserInterfaceItem function.

Greg
On Oct 18, 2007, at 8:57 PM, Ron Fleckner wrote:


On 19/10/2007, at 1:34 PM, Greg Hoover wrote:

I have a menu in an nspopupbutton with several sections (there are heading items) at various locations. I want to prevent these items from being selectable, similarly to separator items. Can somebody point me to a solution? The only alternative I see is to create a custom subclass.

Thanks,
Greg

This works for me:

NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:@"Whatever" action:NULL keyEquivalent:@""];

You get a greyed-out menu item that doesn't do anything. Is that what you were after?

Ron
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Prevent NSMenuItem selection (From: Greg Hoover <email@hidden>)
 >Re: Prevent NSMenuItem selection (From: Greg Hoover <email@hidden>)
 >Re: Prevent NSMenuItem selection (From: Ron Fleckner <email@hidden>)
 >Re: Prevent NSMenuItem selection (From: Greg Hoover <email@hidden>)

  • Prev by Date: Re: Getting list of classes inside NSBundle
  • Next by Date: Re: Question Mark Cursor
  • Previous by thread: Re: Prevent NSMenuItem selection
  • Next by thread: Re: Prevent NSMenuItem selection
  • Index(es):
    • Date
    • Thread