Re: NSPopupButton, bindings, and item state
Re: NSPopupButton, bindings, and item state
- Subject: Re: NSPopupButton, bindings, and item state
- From: Jonathan Taylor <email@hidden>
- Date: Fri, 15 Aug 2014 15:58:39 +0100
>> After being impressed with bindings for an NSTableView, I’m looking at what I can do for a standalone NSPopupButton, in the hope of reducing the amount of glue code I have. The button isn’t just a simple one though, I need to:
>> - Include separator items
>> - Disable (grey out) some items
>> - Select multiple items (it’s configured as a pull-down menu)
>>
>> It’s not obvious to me that there’s a way of doing any of those things with bindings (though the multiple-selected-items might work somehow through the array controller). Can anyone advise on whether there is any hope for this approach, or do I have to accept that this is more than the bindings are intended to help with?
>
> Short answer, yes. With some hackery you could get separator items, but the multiple checked state will likely require as much work as your glue code. So I wold say the best approaches are a 50/50 between bindings and glue. That is, you could use bindings for content, but manually handle state, or use bindings for state, and manually handle content. Doing both is probably an exercise in futility.
Thanks for confirming! Out of interest, could you describe the hackery you have in mind for separators? It might still be helpful to bind the menu item titles to an array.
As for manually handing state (if I were to use bindings for content), would the NSMenuDelegate method menu:updateItem:atIndex:shouldCancel: be the appropriate place to determine which items are checked, enabled, etc? In my all-manual version, I keep track of when the user checks/unchecks individual items through an action on the NSMenuItem. I'm going to have to do something else if the item list is bound to an array - any suggestions about the most appropriate place to identify when the selection changes?
_______________________________________________
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