Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
hi... i have a large ColorWell in my window that when clicked, the select color window appears automatically... that's great... apple makes this possible without having to write code for the select color window to appear... however, i would like to include a menu item "Select Color" that essentially does the same thing as clicking on the window, but i don't know what code to write for the controller since it's all automated... it's not for a font so adding the built-in font menu items doesn't work.

anyone know what i should do?
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,630
Western US
I guess I'd start with calling [[NSColorPanel sharedColorPanel] makeKeyAndOrderFront]; in the action method called by your menu item.
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
I guess I'd start with calling [[NSColorPanel sharedColorPanel] makeKeyAndOrderFront]; in the action method called by your menu item.

i'm not sure i'm doing this properly... actually scratch that, i'm certain i'm not doing this properly... any help would be appreciated...

1) i made an object called "SelectColorFromMenu" and instantiated it
2) i made one action called "openColorSelectWindow"
3) wired the "Select Color" menu item to the controller and connected the action, and made the .h and .m files
4) my .m file was coded and now looks like this:

Code:
#import "SelectColorFromMenu.h"

@implementation SelectColorFromMenu

- (IBAction)openColorSelectWindow:(id)sender
{
[[NSColorPanel sharedColorPanel] makeKeyAndOrderFront];
}

@end

5) tested it: selecting the Select Color from the menu bar doesn't do anything, and it gives me this warning:

Code:
-[NSColorPanel makeKeyAndOrderFront]: selector not recognized [self = 0x388620]

*hangs head in embarrassment*
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,630
Western US
Sorry about that, you have to send nil as an argument:

[[NSColorPanel sharedColorPanel] makeKeyAndOrderFront:nil];

Anyway, I wrote up a sample which I'm attaching. When you choose Select Color from the Test menu, it calls selectColor: from the controller. That sets the target (in this case, my custom view which simply fills with that color) and action to send when a color is changed in the panel, and then brings up the color panel. I *think* that's what you're looking for? It shouldn't be too hard to make it set the color of a well instead of a custom view. There might even be better ways to do it, such as through bindings or notifications.

View attachment ColorPanelTest.zip

EDIT: Actually, it's really easy to change the color in a well, just make a reference to the color well in your controller and connect it in IB, then call [myColorWell activate:YES] in your setColor: method. That has the effect of clicking on the well and it'll bring up the color panel with the color already linked to the well.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.