Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Does NSToolbarShowColorsItemIdentifier send a method?

Does NSToolbarShowColorsItemIdentifier send a method?
Thread Tools
Forum Regular
Join Date: Aug 2005
Status: Offline
Reply With Quote
Mar 17, 2006, 07:33 PM
 
I know that NSToolbarPrintItemIdentifier sends printDocument: to firstResponder, but I can't find information on how to use NSToolbarShowColorsItemIdentifier. I guess I might not be able to do what I want with it, which is to have the result the color panel sends back change the color of the text in a non-editable NSTextField.
YummySoup! - Recipe management and sharing at its best!
     
Forum Regular
Join Date: Aug 2005
Status: Offline
Reply With Quote
Mar 17, 2006, 11:24 PM
 
OK, I have created a method to change the text of the NSTextField, that method being:
Code:
- (void)changeTextColor:(NSColor *)sender
I have setup a collorWell and set its action to changeTextColor: and it works perfectly. Now what I would like to do is remove that colorWell and have my NSToolbarShowColorsItemIdentifier take the colorWells place. I have in place this code, which doesn't work:
Code:
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)willBeInserted { NSToolbarItem *item = [[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier]; if ([itemIdentifier isEqual: NSToolbarShowColorsItemIdentifier]) { NSLog(@"NSToolbarShowColorsItemIdentifier phrased"); [item setTarget:self]; [item setAction:@selector(changeTextColor:)]; } return [item autorelease]; }
I was hoping that someone could help me figure out how to get the toolbar item to plug into the method for changing the text color I created. Thanks!
(Last edited by HungrySeacow; Mar 17, 2006 at 11:59 PM. )
YummySoup! - Recipe management and sharing at its best!
     
Senior User
Join Date: Nov 2001
Location: State of Denial
Status: Offline
Reply With Quote
Mar 21, 2006, 09:28 PM
 
I think what NSToolbarShowColorsItemIdentifier does (or rather, what the NSToolbarItem with that as its identifier does) is show the shared color panel. If that's the case (though I admit I haven't tested it), you can probably implement -(void)changeColor:(id)sender on an object in the responder chain or set the color panel's action and target.
[Wevah setPostCount:[Wevah postCount] + 1];
     
Forum Regular
Join Date: Aug 2005
Status: Offline
Reply With Quote
Mar 22, 2006, 03:06 PM
 
Well I figured it out. I had to modify NSToolbarShowColorsItemIdentifier with the method, - (void) toolbarWillAddItemNSNotification *)notification. Here is my code if anyone is interested:
Code:
- (void) toolbarWillAddItem:(NSNotification *)notification { NSToolbarItem *addedItem = [[notification userInfo] objectForKey: @"item"]; if([[addedItem itemIdentifier] isEqual: NSToolbarShowColorsItemIdentifier]) { [addedItem setToolTip:@"Change Text Color"]; [addedItem setTarget:self]; [addedItem setAction:@selector(showColorPicker)]; } } - (void)showColorPicker { NSColorPanel *colorPanel = [NSColorPanel sharedColorPanel]; [colorPanel setTarget:self]; [colorPanel setAction:@selector(changeTextColor:)]; [NSApp orderFrontColorPanel:self]; } - (void)changeTextColor:(id)sender { NSColor *colorFromWell = [sender color]; [textField1 setTextColor:colorFromWell]; [textField2 setTextColor:colorFromWell]; }
YummySoup! - Recipe management and sharing at its best!
     
Senior User
Join Date: Nov 2001
Location: State of Denial
Status: Offline
Reply With Quote
Mar 23, 2006, 09:12 AM
 
Well, I'm glad you got it sorted!
[Wevah setPostCount:[Wevah postCount] + 1];
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:33 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2