KVC validation and overriding "Discard Changes" button
KVC validation and overriding "Discard Changes" button
- Subject: KVC validation and overriding "Discard Changes" button
- From: Matt Neuburg <email@hidden>
- Date: Sun, 09 Jul 2006 08:59:49 -0700
- Thread-topic: KVC validation and overriding "Discard Changes" button
In my NSObjectController, to do KVC validation, I implement
validateValue:forKeyPath:error:, setting the error with a custom NSError and
returning NO if I deem the value invalid. The dialog that actually appears,
however, ignores part of my custom NSError! It correctly shows my
NSLocalizedRecoverySuggestionErrorKey and NSLocalizedDescriptionKey values,
but it ignores my values for NSLocalizedRecoveryOptionsErrorKey and
NSRecoveryAttempterErrorKey.
Thus, when the dialog appears, the buttons say "Discard Changes" and "OK"
instead of the button titles submitted in my
NSLocalizedRecoveryOptionsErrorKey.
Is this a bug? I see how to solve the problem - namely, by intercepting the
error higher up the responder chain with willPresentError: and customizing
it again - but it seems to me that I should not have to do so. My
NSObjectController is the object that knows how this error dialog should
look; I shouldn't have to assign some other object up the responder chain
that knowledge.
Incidentally, I can see that something has deliberately changed my error,
because I can log the NSError further up the responder chain:
NSError "Sorry!" Domain=MyDomain Code=-1 UserInfo={
NSLocalizedDescription = "Sorry!";
NSLocalizedRecoveryOptions = (OK, "Discard Changes");
NSLocalizedRecoverySuggestion = "Invalid number. A positive integer is
required.";
NSRecoveryAttempter = <_NSBinderAlertRecoveryAttempter: 0x564a5d0>;
NSUnderlyingError = NSError "Sorry!" Domain=MyDomain Code=-1 UserInfo={
NSLocalizedDescription = "Sorry!";
NSLocalizedRecoveryOptions = (Revert, Cancel);
NSLocalizedRecoverySuggestion = "Invalid number. A positive integer is
required.";
NSRecoveryAttempter = <MyRelativeQuantityObjectController:
0x5649b10>[object class: NSMutableDictionary];
};
The NSUnderlyingError is what I submitted. So someone has changed this,
replacing my NSRecoverySuggestion and my NSRecoveryAttempter with another.
So, this is not a hard problem to solve; it's a one-liner for me, up the
responder chain, to replace this NSError with the underlying error. But
still I wonder whether this is expected or reasonable behavior.
m.
--
matt neuburg, phd = email@hidden, <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>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden