[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Cant disable Item of NSPopUpButton
From: |
Sebastian Reitenbach |
Subject: |
Re: Cant disable Item of NSPopUpButton |
Date: |
Sat, 21 Sep 2024 03:42:53 +0200 |
User-agent: |
SOGoMail 5.11.0 |
On Friday, September 20, 2024 18:57 CEST, "H. Nikolaus Schaller"
<hns@goldelico.com> wrote:
> Hi,
>
> > Am 20.09.2024 um 19:20 schrieb Sebastian Reitenbach
> > <sebastia@l00-bugdead-prods.de>:
> >
> > Hi,
> >
> > I've a NSPopUpButton with some items. Some of them I want just to be
> > disabled.
> > To do so, I thought I can just get away with:
> >
> > [[self.popupButton itemWithTitle: @"Item 2"] setEnabled: NO];
> >
> > but that is not the case.
> >
> > Is that supposted to work that way, if at all? If so, any hint what I'm
> > doing wrong?
>
> I think (based on Cocoa experience) you must implement some validateMenuItem:
> or similar method for the target of the popup button. So that it can return
> YES or NO on demand.
>
> To make it dynamical I think the validateMenuItem: is passed the item in
> discussion and you can make decisions based on e.g. [item action] or [item
> title] (not recommended) or [item representedValue]. This is a little similar
> to the dataSource of an NSTableView. You never set values directly in the
> NSTableView but it asks some other object to provide them but only on demand
> by whatever algorithm fits.
>
> This is called when a users opens the menus and depending on the result the
> setEnabled: is called automatically (and overwrites your changes).
yeah, that worked. For some reason, I had to assign an action to the
NSPopUpButton, and have an empty method in my class to actually trigger it
calling validateMenuItem:
Is this really necessary, esp. the existence of the method in the code?
The "only" oddity is, that in the NSPopUpButton, when the top NSMenuItem is
deactivated,
it IS the selectedItem. Once I select some other active NSMenuItem, I afterward
can't select the top NSMenuItem again, similarly to the other deactivated ones.
I can work around that oddity in code, but wondering, if that's supposed to be,
or kind of a bug?
I can enhance the test up to show off what I mean if someone is interested.
I don't have a Mac where I could easily verify "correct" behaviour.
thanks a lot,
Sebastian
>
> BR,
> Nikolaus
>