Re: NSTextView undo/redo question
Re: NSTextView undo/redo question
- Subject: Re: NSTextView undo/redo question
- From: Bill Cheeseman <email@hidden>
- Date: Sun, 19 Aug 2001 19:56:18 -0400
on 8/19/01 2:43 PM, Brian Webster at email@hidden wrote:
>
You might instead try implementing the undoManagerForTextView:
>
method in your text view's delegate so you can keep a separate
>
undo manager for the text view.
I thought of that, but it seemed too hard to do in my application.
I'm trying to implement undo/redo in standard NSTextFields in a window.
Basically, I want on-the-fly text undo/redo in a text field, but without
dirtying the document until the user hits Return to commit the data. When
the user does hit return, I need to discard the text field actions in the
undo stack (which are replaced by a single action to undo the committed
value of the text field), while not discarding older actions in the undo
stack left over from other text fields that were committed earlier.
The only text view in a window full of text fields is the window's shared
field editor. The field editor chooses its own delegate, namely, the text
field that currently has focus, which changes from time to time. So
(thinking out loud, here), I would have to subclass each textfield to
implement undoManagerForTextView: to provide a separate undo manager. Then,
as the user commits one text field and moves on to the next, I would use
removeAllActions to clear that special undo manager, which could be reused
by the next text field, while leaving the contents of the main undo stack
intact. That might work, assuming the special undo manager and the standard
undo manager remain synchronized -- I'll have to explore that issue. (I'll
also have to figure out to handle the text field subclasses in Interface
Builder.)
I have everything working without a separate undo manager in about 10 lines
of code in my window controller, except for the fact that removeAllActions
throws out the older pending actions along with the current text field's
actions. It would be a lot easier if I could make removeAllActionsForTarget:
work.
You've given me some food for thought. Thanks.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
The AppleScript Sourcebook - www.AppleScriptSourcebook.com
Vermont Recipes - www.stepwise.com/Articles/VermontRecipes