• 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: Undo architecture advice needed
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Undo architecture advice needed


  • Subject: Re: Undo architecture advice needed
  • From: David Hirsch <email@hidden>
  • Date: Fri, 09 Oct 2009 11:54:41 -0700

Thanks. For the second time on this list, I have forgotten that bindings work through setters/getters, rather than directly on the object's variables.
-Dave


On Oct 9, 2009, at 11:07 AM, Kai Brüning wrote:

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



============================
Dave Hirsch
Associate Professor
Department of Geology
Western Washington University
persistent email: email@hidden
http://www.davehirsch.com
voice: (360) 389-3583
aim: email@hidden
vCard: http://almandine.geol.wwu.edu/~dave/personal/DaveHirsch.vcf
============================



_______________________________________________

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


References: 
 >Undo architecture advice needed (From: David Hirsch <email@hidden>)
 >Re: Undo architecture advice needed (From: Kai Brüning <email@hidden>)

  • Prev by Date: Re: Undo architecture advice needed
  • Next by Date: Detecting if application is running as Finder
  • Previous by thread: Re: Undo architecture advice needed
  • Next by thread: Detecting if application is running as Finder
  • Index(es):
    • Date
    • Thread