Re: Best Practice for implementing NSUndoManager?
Re: Best Practice for implementing NSUndoManager?
- Subject: Re: Best Practice for implementing NSUndoManager?
- From: Raphael Sebbe <email@hidden>
- Date: Wed, 9 Jun 2004 10:03:23 +0200
On 08 Jun 2004, at 15:38, Sean Todd wrote:
Luke,
The link to your sample app didn't work for me so I will just give you
my thoughts on the 2 questions that you posed (in so far as I
understand what you wrote):
1) Should the model or the controller add objects to the undo
manager?
Considering 'reuse' issues, I would say that the model should not have
any knowledge of an undo manager and would opt for the controller.
On the contrary, I would say that the model should handle undo
operations. For a simple reason, the model defines "primitive" low
level methods that are undoable, and higher level methods which are
based on low-level ones. The controller invokes methods either high or
low level (and does not know and doesn't have to know actually). The
model is responsible for maintaining a coherent state.
The controller should define the action names though, as it knows the
user intent (that is not known for individual primitive model methods).
Considering reusability, undo code is totally reusable too... And
should be reused in the case a class is used in different applications.
More, undo manager is easily disabled if not needed (use nil, or
explicitly disable).
2) If I am on the right track with question 1, then question 2 is:
How should you propagate the NSUndoManager within the app? At present
I am passing the NSUndoManager to objects during the initialization
of the object, is there an easier or more elegant way to do this?
For this, you could try something like:
[[[NSDocumentController sharedDocumentController] currentDocument]
undoManager];
This is not robust to me. I would propagate it down the document (keep
weak references to parent objects).
Something like implementing -undoManager in your classes that return
- undoManager
{
return [_parent undoManager];
}
A while back, I did write an essay on undo managers, you can find it
there:
http://www.ex-cinder.com/downloads/undo-article.rtf
Raphael
_______________________________________________
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.