Re: Handling Undo in a Non-Document app with "generational" objects
Re: Handling Undo in a Non-Document app with "generational" objects
- Subject: Re: Handling Undo in a Non-Document app with "generational" objects
- From: "Raphael Sebbe" <email@hidden>
- Date: Tue, 7 Aug 2007 21:02:54 +0200
Hi,
In such configurations, I generally propagate an "undo manager
provider" object through my model objects. This is set up when the
model objects are created, as an instance variable + accessors (weak).
This provider can actually be the controller itself, but this is
encapsulated through a protocol.
I believe that it is actually the responsability of the model to
implement most part of undo/redo, as it knows how to revert the state
from each of its operation (which is not the case of the controller).
What may be the controller responsability is the undo action name, as
it may be composed of several more basic model operations.
HTH,
Raphael
On 8/7/07, Paul Bruneau <email@hidden> wrote:
> Hi,
>
> I have a class called OrderStep whose objects represent the steps of
> an order.
>
> Each of these objects has an NSMutableArray as an instance variable
> (nextSteps) whose purpose is to optionally hold more OrderStep
> objects, which can then optionally hold their own child objects, and
> so on.
>
> orderStepA ---> orderStepB ---> orderStepE
> orderStepC
> orderStepD ---> orderStepF
> orderStepG
>
> You get the idea.
>
> So I have a -deleteStep method which recursively calls itself for any
> objects in its nextSteps array before removing itself from the array
> of its parent object. This is working very well as far as memory
> management and overall operation.
>
> But I want to implement Undo for it. My question is, how best to get
> my NSUndoManager to these objects so they can call
> prepareWithInvocationTarget? I feel like I am violating MVC because
> it seems like my model objects are going to have to know about the
> controller where the NSUndoManager object is stored. That doesn't
> seem right to me because the -deleteStep method could be called from
> really anywhere in the app.
>
> For similar reasons, I don't think that using the -
> windowWillReturnUndoManager delegate will help me because my
> orderSteps aren't going to know what window they are in, right?
>
> I think I know that in a design where there weren't these recursive
> children, I could just handle it all from the controller, but this
> thinking doesn't seem to fit given my situation. I don't think I can
> delete all the generations of children from the controller, and it is
> certainly easy to do it from each successive parent model object.
>
> I am sure I am just thinking about something altogether wrong and I
> hope someone can give me a shove in the right direction.
>
> Thank you
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> 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:
>
> This email sent to email@hidden
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden