Question

I have a list of applications and I'd like to make an NSPopupButton that shows a menu of application names with their icon to the left of each item.

I've been able to bind the NSPopupButton to my array of items, but there isn't a binding entry for an image. I thought I could put a cell in there and bind the cell as an image and as text, but I can't find an appropriate cell in IB.

Is there a clean and simple way to do this using bindings? Do I have to write a custom cell?

Was it helpful?

Solution

There is no way to bind the images as well as the titles of the menu items using a stock NSPopUpButton. You will have to subclass it and write an IBPlugin to expose the subclass. And, of course, you should handle the cell as well.

I've found mixing Bindings with NSPopUpButton to be a bag of hurt for a variety of reasons, including the impossibility of separators and of out-of-model menu items such as “Default” or “All”. Consider using a different control, such as a source list, or populating and re-populating the pop-up menu manually.

OTHER TIPS

NSMenuItem has Image binding (in "Parameters" section waaaaaayyyyy down). So I think that you should bind that value to a path in your array of running applications. You can get an icon for your app using shared NSWorkspace object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top