Undo architecture advice needed
Undo architecture advice needed
- Subject: Undo architecture advice needed
- From: David Hirsch <email@hidden>
- Date: Fri, 09 Oct 2009 10:53:39 -0700
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