views:

296

answers:

3

I'm trying to make a color chooser using an NSPopupButton, and at the bottom i'd like a separator and a "Custom…" option. Is it possible to load the colors from array, then tack the separator and "custom" item on bottom? if so, how?

Thanks!

A: 

Not using Bindings, no. You could do the “Custom…” one easily enough, but not the separator.

Why not use an NSColorWell, anyway?

Peter Hosey
I've thought about using a colorwell, but the menu item really makes the interface more concise. They'd both have the same effect of getting the sharedColorPanel open.It seems my best solution, then, is to manually rebuild the menu every time my array changes from my view class.
Joshua Breeden
A: 

You should really use a NSColorWell instead of hand-crafting your own. One of the reasons why Apple has superior GUIs than other platforms (especially Linux) is because developers use the standard components for doing this kind of thing. Arguments like 'because I think it makes the interface more concise' are the reasons why GIMP is such a prime example of how not to design a GUI.

That said, basically what you're trying to do is define a dynamic menu, rather than a fixed-size list (as one might do in InterfaceBuilder). You can do this via the NSMenu and NSMenuItem classes.

MenuList documentation guide

What you'd need to do, is rather than display the menu on-demand, is fill it when the application starts up with the default array. Then, when the array changes (via your model objects) trigger the re-creation of the menu. Alternatively, trap the menu with the menuNeedsUpdate: message.

AlBlue
thanks for the response. everyone seems dedicated to the NSColorWell, when, in reality, there are plenty of instances where it isn't appropriate. case in point: iCal. "get info" on a calendar in the source list, and click on the color menu on the right. that is almost exactly what i'm trying to do.you can fill up an interface with apple's standard components, that doesn't make it a good GUI. the inverse is also true.thanks for pointing me in the right direction, though!
Joshua Breeden
A: 

I have created a similar PopUpButton, but am not yet binding the default colors to a fixed array (though I am working on that now). there are two appraoches here - both may be considered hacks by purists, but they do get the job done.

  1. Subclass the NSPopUpButtonCell and override attachPopUpWithFrame to add your own menu items. I have not tried this alongside bound items.

  2. Hard-code the 'Custom ..' object in your array, and have the action of the displayed color panel, add a new item to the array.

Meehsa