On Aug 15, 2014, at 8:58 AM, Jonathan Taylor <jonathan.tay...@glasgow.ac.uk> 
wrote:

>>> 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.

This thread gives a couple of approaches, depending on how you need the menu 
constructed: 
http://www.cocoabuilder.com/archive/cocoa/275031-nspopupbutton-bindings-separator-items.html

> 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?

As long as you can hook your delegate in on time, sure. I think that 
NSPopupButton keeps the same NSMenu instance throughout it's lifetime, but if 
not, the delegate approach won't work.

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to