Re: Undo architecture advice needed
Re: Undo architecture advice needed
- Subject: Re: Undo architecture advice needed
- From: Kai Brüning <email@hidden>
- Date: Fri, 9 Oct 2009 20:07:08 +0200
Hello Dave,
undo/redo is a model operation and should be handled inside the model.
That is, I wouldn’t pick your suggestions 1) or 2), because they both
do not observe (in a general case, not KVO) the model to generate undo
information.
If I understand you correctly, the phase objects are your model. If
this is correct, the changes do go through your code: when they arrive
at the phase object (typically in a setter). And this is the place to
record the information needed for undoing the change.
Hope this makes any sense
Kai
On 9.10.2009, at 19:53, David Hirsch wrote:
Hello list-
I have a document-based application. Each document has a NSArray
of phases. Phases is an NSArrayController created in IB and bound
to FIle's Owner.phases. When a given phase is selected in the
NSTableView (bound to phase controller), then its properties show up
in a set of text fields, check boxes, color wells, popup menus,
etc., through bindings similar to "Phases.selection.size".
Here is my question: what is the best way to implement undo/redo
here? I'd like to enable undo of changes to the settings (like
size) that the user makes in the text fields, but they don't go
through my code - they are just bound directly to the array. (Note
that I do understand that the field editor has its own undo that
operates during text editing; that is not what I'm talking about.)
Here are some potential avenues I'm considering:
1) Make the document the delegate for all these fields. Then I can
get a controlTextDidChange: notification, figure out the current
phase, get the object and the value, and post an undo. However,
this requires me to implement a whole bunch of setters in my
NSDocument subclass that duplicate setters in my phases class, which
seems inelegant, to say the least. Also, I don't see an obvious way
to do something similar for, say checkboxes.
2) Try to set up KVO (from my document subclass, I guess?) on the
NSArrayController to watch for changes, and then register undo
operations in the observing method. I would have to be careful not
to get into a loop when re-doing the undo operations, though, since
I would observe any changes I made during undo.
3) I'm sure there are other ways, but I'm not smart enough to think
of them.
Thanks in advance,
Dave
_______________________________________________
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