Prevent NSMenuItem selection

  • 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
  • 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
  • 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
  • Am 19.10.2007 um 05:34 schrieb Greg Hoover:
    > 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.

      Danger! Apple Human Interface Police (tm) is everywhere!

      There's a reason why unselectable things are generally disabled. We
    have section header menu items these days, so I'd use that and let
    Apple sort out how to display them. That way, users will *know* the
    item isn't supposed to be selectable, and doesn't have to try out to
    find out it won't do anything.

      (If you're not aware why this may be a Bad Thing(tm), Steve Krug
    wrote a nice book, "Don't make me think", that explains why you want
    to make your UI this obvious to the user and stay out of their way.
    In short, it lets users concentrate on the task at hand, like writing
    their novel, instead of on the tool, i.e. the word processor you wrote)

    Cheers,
    -- M. Uli Kusterer
    http://www.zathras.de
  • I'm trying to...what "section header menu items" are you referring to?

    Greg
    On Oct 19, 2007, at 12:20 AM, Uli Kusterer wrote:

    > Am 19.10.2007 um 05:34 schrieb Greg Hoover:
    >> 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.
    >
    > Danger! Apple Human Interface Police (tm) is everywhere!
    >
    > There's a reason why unselectable things are generally disabled.
    > We have section header menu items these days, so I'd use that and
    > let Apple sort out how to display them. That way, users will *know*
    > the item isn't supposed to be selectable, and doesn't have to try
    > out to find out it won't do anything.
    >
    > (If you're not aware why this may be a Bad Thing(tm), Steve Krug
    > wrote a nice book, "Don't make me think", that explains why you
    > want to make your UI this obvious to the user and stay out of their
    > way. In short, it lets users concentrate on the task at hand, like
    > writing their novel, instead of on the tool, i.e. the word
    > processor you wrote)
    >
    > Cheers,
    > -- M. Uli Kusterer
    > http://www.zathras.de
    >
    >
  • 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
  • Am 19.10.2007 um 17:02 schrieb Greg Hoover:
    > I'm trying to...what "section header menu items" are you referring to?

    Weird... looks like only Carbon has those. You can see them, for
    example, in the Apple menu's "Recent Items" submenu. They essentially
    look and behave like disabled menu items, but in Carbon you can set a
    flag on any menu item to get this look, and it's a different flag
    than the enable state.

    Anyway, I'd suggest you just use disabled menu items for now, and
    then use different indentation levels for your menu items to achieve
    the proper look. There's already an established look for such items
    in the OS, and it isn't selectable grey items or disabled black items.

    Cheers,
    -- M. Uli Kusterer
    http://www.zathras.de
  • 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
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today