Preventing NSTextView sending -setColor: to NSColorPanel?
Preventing NSTextView sending -setColor: to NSColorPanel?
- Subject: Preventing NSTextView sending -setColor: to NSColorPanel?
- From: Keith Blount <email@hidden>
- Date: Tue, 5 Feb 2008 15:23:00 -0800 (PST)
Hi,
I have an NSTextView subclass that can use the shared NSColorPanel to set the color for either NSForegroundColorAttributeName or NSBackgroundColorAttributeName.
Obviously, NSTextView's -changeColor: method (the delegate method of NSColorPanel) changes NSForegroundColorAttributeName by default, so I just call super when I need to do that. If the text view is set to affect the background colour, though, instead of calling [super changeColor:sender], it uses [sender color] to affect the NSBackgroundColorAttributeName of the range for user change or typing attributes. (I have an NSTextView category with methods for ordering front or hiding the colour panel for either foreground or background colour changes, setting a flag accordingly.)
All of this works fine, except... If the text has a colour set for NSForeroundColorAttributeName and then I set a background colour using the NSColorPanel, things work fine for the first character typed. However, it seems that when there is a foreground colour set, every time the selection changes in the text view - and thus every time a character is typed - NSTextView sends a -setColor: message to the shared colour panel to ensure that the colour in the panel reflects the foreground colour of the text. This is fine for the default NSTextView implementation where the colour panel only affects the foreground colour and wants to stay in sync with it, but it messes things up when it can affect the background colour too. This basically means that if I have some coloured text and then set the background coloured text (thus setting a flag telling the text view to affect NSBackgroundColorAttributeName in -changeColor:), as soon as the user types, the
NSColorPanel receives a -setColor: message, setting it to the text's foreground colour, which in turn sends my text view another -changeColor: message, which my text view interprets as a user change to the background colour. This results in the background colour being set to the same as the foreground colour after the user has typed a character.
At the moment, I've set it up so that if the text view is set to affect background colour when it receives a -changeColor: message, -changeColor: does nothing if the colour panel is not visible. However, this does not solve the problem if the colour panel *is* visible.
Is there any way to prevent the colour panel automatically updating with the foreground colour of the text in the NSTextView when the selection changes?
Thanks in advance and all the best,
Keith
____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden