On Jan 17, 2013, at 2:23 AM, "jonat...@mugginsoft.com" <jonat...@mugginsoft.com> 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 (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com