I need to come back to this as something's not right and I can't find out what.
I am now initialising a new instance of NSUndoManager when I create my model object. When I type I can see undoManagerForTextView being called and a valid undo manager returned to the text view. My problem is, when I switch model objects by clicking on a table row I get lose the ability to undo text that was previously typed and I get a strange behaviour: Lets suppose I have two models. I open the first one and type something in. Undo works. I then open the second model, type something in and return to the first model. Undo stopped working, I only get a loud beep. Going through the Undo Architecture documentation I found this snippet of code: *The default undo and redo behavior applies to text fields and text in cells as long as the field or cell is the first responder (that is, the focus of keyboard actions). Once the insertion point leaves the field or cell, prior operations cannot be undone.* * * Does this mean that by clicking the table row and therefore removing focus from the text field I lost the ability to undo? On 19 March 2010 16:35, Rui Pacheco <[email protected]> wrote: > You are right, I forgot to check the delegate methods. > > > On 17 March 2010 14:41, Keith Blount <[email protected]> wrote: > >> I might be missing something, but can you not just use the NSTextView >> delegate message, -undoManagerForTextView:? This is what I do in my app. I >> have a single text view that can have various text storage objects swapped >> into it, and I have each of those text storages associated with a different >> NSUndoManager. I use -undoManagerForTextView: to return whichever undo >> manager corresponds to the current text object, so that the user's undoes >> affect the currently loaded text and the user can load up a text he or she >> worked on earlier and hitting undo will undo whatever they last did in that >> particular text. >> >> Hope that helps. >> All the best, >> Keith >> >> --- original message --- >> >> Is there a way to bind the text view's undo manager to an instance of >> NSUndoManager on my model object? >> >> I can get to the text view undo manager but I don't seem to be able to set >> it. >> >> On 17 March 2010 13:34, Keary Suska <em...@hidden> wrote: >> >> > On Mar 16, 2010, at 6:09 PM, Rui Pacheco wrote: >> > >> > > I've a window with a fairly complex layout - one NSTextView and >> several >> > > tables, all displaying different types of data. To keep things in >> order, >> > > I've created a model object that holds the data for all these >> interface >> > > elements. The window may also hold several instances of the model >> object >> > and >> > > I list them in a table. >> > > >> > > My problem is how to keep the undo manager for the text view >> synchronised >> > > with a particular instance of a model object. As the user switches >> > between >> > > model objects, I want him to be able to do cmd + z transparently with >> the >> > > window knowing what changed in that particular instance. >> > > >> > > Some research seems to indicate that using core data would give me >> this >> > for >> > > free - make my model objects extend NSManagedObject and I would have >> undo >> > > for free. Is this correct? >> > >> > More or less. You may want to keep in mind that "out of the box" that >> undos >> > will be tracked in the order they are registered across all objects. >> I.e., >> > user changes textfield value, tabs to textview and makes a change, then >> hits >> > undo twice, the textfield change will get undone. >> > >> > HTH, >> > >> > Keary Suska >> > Esoteritech, Inc. >> > "Demystifying technology for your home or business" >> > >> > >> >> >> >> >> > > > -- > Best regards, > Rui Pacheco > -- Best regards, Rui Pacheco _______________________________________________ Cocoa-dev mailing list ([email protected]) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
