• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Changing color in NSColorPanel without message
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Changing color in NSColorPanel without message


  • Subject: Re: Changing color in NSColorPanel without message
  • From: Andy Lee <email@hidden>
  • Date: Thu, 17 Jan 2013 03:30:01 -0500

On Jan 17, 2013, at 2:23 AM, "email@hidden" <email@hidden> wrote:

> The refactor could be fairly simple.
> A category method on NSColorPanel could be used to insert a filter into the responder chain as and when required before displaying the panel.
> The filter could then divert the change request locally as required.

Would this work? I ruled it out because I figured that the "real" FR would have to resignFirstResponder, which could cause problems if for example it was a text field whose contents failed validation.

I tried a quick-and-dirty hack of the responder chain using a subclass of NSApplication, plus a category method on NSColorPanel called mySetColor: which you'd call instead of setColor:.

The idea was to have NSApp return nil for keyWindow and mainWindow if the program was in the middle of executing mySetColor:. I assumed the color panel was calling these methods to look for the first responder, so it would think there *was* no first responder and the changeColor: message wouldn't get sent (well, it might get sent to some non-visual object in the responder chain).

It didn't work. The "real" first responder (an NSColorWell) still changed color. One thing I didn't test was whether this was due to changeColor: being sent or due to the color well responding to the notification, which would be surprising but I can't say I ruled it out.

Another possibility is that changeColor: isn't sent during setColor:, but rather with maybe a delayed perform. Didn't bother to test.

Or maybe I guessed wrong about how it's determined what the FR is.

Here's a snippet that gives the idea of the kludge I was trying:

- (void)mySetColor:(NSColor *)color
{
    NSLog(@"ENTER mySetColor:");
    BOOL wasSettingColor = [(MyApplication *)NSApp colorPanelIsSettingColor];
    [(MyApplication *)NSApp setColorPanelIsSettingColor:YES];

    [self setColor:color];

    [(MyApplication *)NSApp setColorPanelIsSettingColor:wasSettingColor];
    NSLog(@"EXIT mySetColor:");
}

I was tempted to try to get this to work by getting a little messier. But I didn't.

--Andy

_______________________________________________

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

  • Follow-Ups:
    • Re: Changing color in NSColorPanel without message
      • From: Andy Lee <email@hidden>
References: 
 >Re: Changing color in NSColorPanel without message (From: Melvin Walker <email@hidden>)
 >Re: Changing color in NSColorPanel without message (From: Andy Lee <email@hidden>)
 >Re: Changing color in NSColorPanel without message (From: Melvin Walker <email@hidden>)
 >Re: Changing color in NSColorPanel without message (From: "email@hidden" <email@hidden>)

  • Prev by Date: Re: Changing color in NSColorPanel without message
  • Next by Date: Comparator blocks in NSSortDescriptor not supported in Core Data?
  • Previous by thread: Re: Changing color in NSColorPanel without message
  • Next by thread: Re: Changing color in NSColorPanel without message
  • Index(es):
    • Date
    • Thread