Re: User interface validation doesn't work, right?
Re: User interface validation doesn't work, right?
- Subject: Re: User interface validation doesn't work, right?
- From: Bill Cheeseman <email@hidden>
- Date: Thu, 2 Jul 2009 03:48:24 -0400
On Jul 1, 2009, at 9:15 PM, Keary Suska wrote:
So I think you are claiming this works because the documentation
says so. I'm saying the documentation is wrong because it doesn't
work. I would love to see a project proving me wrong. Can you show
me one?
No, I am saying that it works as advertised for objects that it
works for. NSButton is not one of them, and never has been. You seem
to assume that all user interface items should, but they don't, and
never have, and the documentation has never said that they did. The
documentation is explicit:
"The protocols NSUserInterfaceValidations and
NSValidatedUserInterfaceItem provide a standard way to validate user
interface items—that is, to set their state as appropriate for the
current application context"
Validation is not a function of user interface items, it is a
function of the protocol(s) listed. Neither NSButton, nor any of its
parents conforms to the protocol, so none of them support validation
of this kind. Look at NSMenuItem, and you will see that it does, and
that your validation method will always be called.
I'm not "assuming" that it works with all user controls. The document
I quoted from says it does, explicitly and in detail, without
qualification. All I asked in my original post is whether I'm correct
in concluding that in fact buttons don't work that way. I understand
that you've all confirmed that I'm correct in my conclusion. Thanks.
I must say, though, that I enjoyed your defense of the document. You
said, in so many words, that it is true only for those user interface
items for which it is true. That captures my complaint perfectly. When
a general statement has substantial qualifications, the document
should express those qualifications. Otherwise, as in this case, it
fails to serve its purpose of educating people who aren't already in
the know.
The document not only fails to disclose the qualifications; it
affirmatively misleads by giving a detailed narrative description of
how to do it in the general case. I followed the explanation in my own
code precisely, and it simply doesn't work. In the "The Target Object"
section, the document describes how to implement user interface
validation in the case of a "controller" that implements an "action
method." It says that the controller should also implement -
validateUserInterfaceItem: in order to enable or disable a user
interface item. It says, for example, that if the method returns NO,
"the user interface item is disabled." Nothing in the document
suggests that this is limited to menu items or toolbar items; instead,
it refers repeatedly to "user interface items." It goes on to give a
code example for a subclass of NSDocument. The code sample works only
because NSDocument is written to make it work (as some other document
explains; I've forgotten which), but this document doesn't explain
that rather important qualification. NSWindowController is not written
that way, and it doesn't work, contrary to the "The Target Object"
section's assertion that it does work for "controllers" and "user
interface items" in general.
It doesn't help to refer me to the NSUserInterfaceValidations and
NSValidatedUserInterface protocol documents, because that's where I
started. They are ambiguous, and they're very short on explanation. In
fact, I turned to the User Interface Validation document precisely
because I was seeking clarification of the protocol documents. Telling
me to go back and look at the protocol documents doesn't help.
The protocol documents say, as you noted, that they "work together" to
implement user interface validation. They go on to state that "The
NSMenuItem and NSToolbar Item classes take advantage of these
protocols." Grammatically, that sentence is written as if these are
simply two examples of classes that do so; it does not state that they
are the ONLY classes that do so. And the User Interface Validation
document says that NSMenuItem is "one example."
In trying to pin down whether buttons also do so, I looked at the
NSButton Class Reference document and found that it expressly conforms
to the NSUserInterfaceValidations protocol. I don't understand why you
say it doesn't.
I did find it confusing when I read the NSMenuItem and NSToolbarItem
Class Reference documents, which say that they conform to the other
protocol, the NSValidatedUserInterface protocol. But this tends to
suggest that NSButton will work, too, since NSControl, from which
NSButton inherits, also conforms to the NSValidatedUserInterface
protocol. It doesn't say so, but Apple's documentation has a long
history of neglecting to mention all the protocols that a class
conforms to. I was able to confirm from the NSControl Class Reference
document, and you can too, that NSControl does implement the -action
and -tag methods required by the NSValidatedUserInterface protocol.
So, again, I don't understand why you say it doesn't.
Putting the protocol documents and the class reference documents
together with the User Interface Validations document leads one
directly to the conclusion that buttons work just like menu items and
toolbar items in this regard. (And they should, by the way, perhaps
with an on/off switch like NSToolbarItem's -setAutovalidates: method.)
But they don't, so the document is wrong, which was my original point.
I have understood for many years that they don't, but I hadn't
previously made a thorough effort to track down whether that was only
because I wasn't doing it right. Over the last couple of days I
finally made that effort, because the documents so clearly say it does
work. I concluded that it wasn't my fault; buttons really don't work
that way. Instead, the document is simply wrong. My original post to
the list was to seek confirmation that it doesn't work with buttons.
You've given me that confirmation, for which I thank you.
What I don't understand is why everybody is working so hard to defend
an indefensible document. I'll file a bug against the document. And
against the two protocol documents, as well. And against NSControl for
failing to state that it conforms to the NSValidatedUserInterface
protocol, as it does. And a feature request to make this work with all
user controls -- then mmalc wouldn't have to rewrite the document!
--
Bill Cheeseman
email@hidden
_______________________________________________
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