Re: Undo manager and field editors: a tale of woe
Re: Undo manager and field editors: a tale of woe
- Subject: Re: Undo manager and field editors: a tale of woe
- From: Bill Cheeseman <email@hidden>
- Date: Thu, 15 May 2003 21:04:29 -0400
on 03-05-15 8:39 PM, Pete Yandell at email@hidden wrote:
>
What I'd like to do is inspect the
>
undo stack, see if the last posted event was also a change in this
>
field editor and, if so, pull it off and replace it with a new event
>
combining the changes. (I believe this is exactly what an NSTextView
>
does.) Unfortunately NSUndoManager doesn't have any methods that let me
>
inspect and modify the undo stack in this way. How do I go about it?
I've struggled with similar problems at length, and the solutions I've come
up with are hard and somewhat hackish. Basically, it seems to me that the
undo manager is designed to work with straightforward, by-the-book Cocoa
applications, and as soon as you try to do something unusual you run into
the wall of assumptions made by the undo manager. Using the notifications
that it posts can be helpful, but it's hard to deal with all the
interdependencies. The documentation isn't detailed or exhaustive enough to
be really helpful.
One interesting way to play with the undo manager is to write category
methods that allow you to examine and manipulate the undo and redo stacks
level by level. The stacks are available as private variables declared in
the headers, and it's quite easy to access them. Of course, they are private
variables and undocumented, and Apple makes no guarantees whatsoever that
the next system version won't destroy your application if you rely on them.
But you can learn a lot about how the undo manager works by doing this.
I don't mean to suggest that this is the best way to attack your problem. In
fact, in my experiments I never ran into the problem you've experienced of
getting an undo action for every character. So I suspect you need a
fundamental rethink of your approach.
If you're interested, my efforts are chronicled in the chapter of my book,
Vermont Recipes, that shows how to implement "live" undo and redo of editing
within a text field before it is "committed" by pressing Enter. Another
chapter shows one way to handle undo and redo of addition and deletion of
rows in a table. I've only read your message quickly, but it sounds like
you're dealing with very similar problems.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.