On 03/09/2012, at 8:10 AM, Erik Stainsby <erik.stain...@roaringsky.ca> wrote:

> Advice from those who know would be much appreciated.


I wouldn't say 'I know' at all, but I find that it is necessary to put the 
calls to the undo manager into the model.

NSUndoManager's basic functionality acts on the model, but it also supports 
aspects of the view because it maintains the "action string" that is displayed 
in the Undo menu. As such you could say that it sits in the controller layer 
but unless the model tells it what to undo it can't do anything, so it relies 
on cooperation from the model. KVO is a good way to handle that (via some 
adapter class) because it's generic and so the model is not required to know 
about the undo manager itself - but a lot of model code predates KVO and talks 
to the undo manager directly (and there are some aspects of KVO that can make 
using it for undo awkward, like handling one-to-many relationship undos).

If you're not using NSDocument, then you could make your undo manager a 
singleton, but bear in mind that standard Cocoa classes (e.g. NSTextView) will 
expect it to be returned by the window/window's delegate via 
-windowWillReturnUndoManager:, so you'd have to override that method to pass 
back your singleton.

--Graham


_______________________________________________

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

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

Reply via email to