Re: How to validate the Undo menu item?
Re: How to validate the Undo menu item?
- Subject: Re: How to validate the Undo menu item?
- From: Brian Webster <email@hidden>
- Date: Wed, 24 Apr 2002 09:35:52 -0500
On Tuesday, April 23, 2002, at 10:02 PM, cocoa-dev-
email@hidden wrote:
Yes: It doesn't work, either. Also, one of the conditions for
disabling the
Undo menu item has to do with the state of the table view
(namely, is one of
its rows currently being edited), and I hate to access view
objects from
within my document.
Hmm, this is an interesting question, whether handling undo
operations belongs in the controller or the view that displays
the data. The view is the first responder, after all, and in
this case your validation depends on the state of the view.
Sketch also implements validation in the SKTGraphicView class,
although it doesn't do any customization of undo behavior.
I guess my thinking on the subject is that the object that
handles the undo: action (and thus validates the menu item)
should be the object that "owns" the undo manager. In the case
of Sketch, most of the behavior is really located in that
SKTGraphicView class, since it's the only view in which the data
is modified.
However, there can be cases where you have a window with
multiple views that all modify the same data, or where you have
a document with multiple windows that modify the same data. If
the views were modifying different data, then they should each
have and control their own undo manager as well.
But if they're modifying the same data, it doesn't really make
sense to have to rewrite the undo code and validation for each
view that could be the first responder. There may be some
differences in the validation depending on which view is first
responder, but the window controller or document would be
perfectly capable of managing this distinction.
So, I'm not really sure what the "right" answer is. I've always
implemented my undo validation in my document just because it
seemed the natural place to do it, since the document is the
object that creates and holds the undo manager, and it's right
there in the responder chain all the time, ready to validate.
When I say it doesn't work, I mean that, although the validateMenuItem;
method gets called in my document for other menu items, it
never gets called
for the Undo menu item. For that, I would have to implement undo: in my
document, and then I still would have the problem of not
knowing what to do
in undo:.
That's simple:
-(void)undo:(id)sender
{
[[self undoManager] undo];
}
Also, checking whether the undo manager canUndo or canRedo is a
good thing to put into validation for these items, since they
shouldn't be enabled if the undo/redo stack is empty. I think
NSResponder's auto-handling of undo: and its validation does
this, but if you want custom validation, you'll have to add it
yourself to whatever other code you write.
--
Brian Webster
email@hidden
http://homepage.mac.com/bwebster
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.