How to receive text color changes from NSFontPanel?

  • Hi,

    The NSFontPanel has a control to change the text color, but how can I
    receive a change of the text color from the NSFontPanel?

    Greetings,

        Daniel
  • > The NSFontPanel has a control to change the text color, but how can I
    > receive a change of the text color from the NSFontPanel?

    I believe the first responder is sent "changeAttributes:", which is documented in the  NSTextView reference. The general gist is that you want to call "convertAttributes:" on the sender, eg:

    - (void) changeAttributes:(id)sender
    {
        NSDictionary* oldAttrs = [self currentAttributes];
        NSDictionary* newAttrs = [sender convertAttributes:oldAttrs]; // adds color attribute
        [self setCurrentAttributes:newAttrs];
    }

    If the NSColorPanel was brought up independently of the text view, then I think you'll receive "changeColor:" instead of "changeAttributes:".

    I hope that helps,
    ~Martin
  • Hi Martin,

    Yes, changeAttribute: is sent to the first responder.

    Maybe a little note in the NSFontPanel documentation would be nice. ;-)

    Thanks!

        Daniel

    Am 13.10.2006 um 20:20 schrieb Martin:

    >> The NSFontPanel has a control to change the text color, but how can I
    >> receive a change of the text color from the NSFontPanel?
    >
    > I believe the first responder is sent "changeAttributes:", which is
    > documented in the  NSTextView reference. The general gist is that
    > you want to call "convertAttributes:" on the sender, eg:
    >
    > - (void) changeAttributes:(id)sender
    > {
    > NSDictionary* oldAttrs = [self currentAttributes];
    > NSDictionary* newAttrs = [sender
    > convertAttributes:oldAttrs]; // adds color attribute
    > [self setCurrentAttributes:newAttrs];
    > }
    >
    > If the NSColorPanel was brought up independently of the text view,
    > then I think you'll receive "changeColor:" instead of
    > "changeAttributes:".
    >
    > I hope that helps,
    > ~Martin
    >
    >
  • On Sat, 14 Oct 2006 16:03:08 +0200, Schwill Daniel <cocoa-dev...>
    said:
    > Hi Martin,
    >
    > Yes, changeAttribute: is sent to the first responder.

    <http://www.cocoabuilder.com/archive/message/cocoa/2004/9/1/116331>

    > Maybe a little note in the NSFontPanel documentation would be nice. ;-)

    If you think so, then file a bug on the docs. m.

    >
    > Am 13.10.2006 um 20:20 schrieb Martin:
    >
    >>> The NSFontPanel has a control to change the text color, but how can I
    >>> receive a change of the text color from the NSFontPanel?
    >>
    >> I believe the first responder is sent "changeAttributes:", which is
    >> documented in the  NSTextView reference. The general gist is that
    >> you want to call "convertAttributes:" on the sender, eg:
    >>
    >> - (void) changeAttributes:(id)sender
    >> {
    >> NSDictionary* oldAttrs = [self currentAttributes];
    >> NSDictionary* newAttrs = [sender
    >> convertAttributes:oldAttrs]; // adds color attribute
    >> [self setCurrentAttributes:newAttrs];
    >> }
    >>
    >> If the NSColorPanel was brought up independently of the text view,
    >> then I think you'll receive "changeColor:" instead of
    >> "changeAttributes:".
    >>
    >> I hope that helps,
    >> ~Martin
    >>
    >>
    >
    >
    >
    >

    --
    matt neuburg, phd = <matt...>, <http://www.tidbits.com/matt/>
    A fool + a tool + an autorelease pool = cool!
    AppleScript: the Definitive Guide - Second Edition!
    <http://www.amazon.com/gp/product/0596102119>
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today