• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Best Practice for implementing NSUndoManager?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best Practice for implementing NSUndoManager?


  • Subject: Re: Best Practice for implementing NSUndoManager?
  • From: Luke Tupper <email@hidden>
  • Date: Thu, 10 Jun 2004 06:54:36 +1000

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).


I have found one *very* good reason to place these objects in the model. Apples new binding objects (which are basically prebuilt controller objects) don't implement undo. Therefore if you want to implement an undo manager in an app that utilizes bindings you have to put the undo manager code in the model. Unless of course I have overlooked something in the binding stuff to implement undo manager.

Thanks

Luke




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.
_______________________________________________
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.


  • Prev by Date: Re: NSOutlineView Problem
  • Next by Date: Re: How does Pixie get the mouse position?
  • Previous by thread: Re: Best Practice for implementing NSUndoManager?
  • Next by thread: NSButton's setKeyEquivalent and arrow keys
  • Index(es):
    • Date
    • Thread