On Jul 2, 2009, at 8:38 PM, Quincey Morris wrote:

It remains totally mysterious what's going to cause individual validatable interface items to trigger their own validation. Perhaps there's no automatic general mechanism at all, and each interface item class has to solve the problem for itself

I would summarize it like this:

In the case of menu items and toolbar items, you have to implement - validateMenuItem: or -validateToolbarItem:, or their fallback - validateUserInterfaceItem:, yourself. In your implementation, you decide which items require validation by testing which action the current item sends (or, rarely, what tag it has). If you implement one of these -validate... methods, it is called automatically by the - update or -validateVisibleItems mechanisms you described.

In the case of buttons, you likewise have to implement - validateUserInterfaceItem: yourself. But that isn't enough, because Cocoa does not call it automatically just because you implemented it. A generic solution is to implement the -windowDidUpdate: delegate method in your window controller, and in it loop through all the subviews in your window's contentView. In each iteration of the loop, call your -validateUserInterfaceItem: method, testing first to make sure the item implements -action and -tag and -setEnabled: (or just test whether it's a button, since all buttons do). If efficiency becomes a problem, take steps to reduce the frequency with which - validatedUserInterfaceItem: is called (every time the window updates -- that is, once every time through the run loop -- may be overkill for many validation scenarios).

--

Bill Cheeseman
b...@cheeseman.name

_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to