Re: Correct implementation of undoManagerForTextView
Re: Correct implementation of undoManagerForTextView
- Subject: Re: Correct implementation of undoManagerForTextView
- From: Jeremy Dronfield <email@hidden>
- Date: Wed, 3 Mar 2004 22:20:24 +0000
On 3 Mar 2004, at 9:08 pm, Dustin Voss wrote:
On 3 Mar, 2004, at 10:32 AM, Jeremy Dronfield wrote:
My app has two separate text views (one in the main window, another
in a drawer). Each has its own separate delegate, and I want each to
have its own undo manager. (So that they can separately trigger an
Unsaved Changes warning.) The trouble is, I can't figure out the
correct implementation of the NSTextView delegate method:
- (NSUndoManager *)undoManagerForTextView:(NSTextView *)aTextView
{
return (what?);
}
There's no illumination in the FM, and I'm further confused by a
reference by Bill Cheeseman (Omni archives) to this as an NSWindow
delegate method, which it clearly isn't.
Firstly, the undo manager is not in charge of unsaved changes
warnings. Your model should keep track of this itself.
That's what I meant. The undo manager isn't in charge - it's consulted.
NSDocument keeps track by observing the NSUndoManager it maintains,
and other parts of the framework check with NSDocument to see if there
are unsaved changes.
I'm not using NSDocument. Each text view has a delegate (an NSObject
subclass).
Secondly, there is an NSWindow delegate method that supplies an undo
manager. If a text view needs an undo manager, it follows the
responder chain, and will get one of these (in order):
* One returned by the NSTextView delegate's -undoManagerForTextView:
That's the one I want. The documentation tells me that "If you want a
text view to have its own NSUndoManager (and not the windows), have
the text views delegate implement undoManagerForTextView:, to return
the NSUndoManager." What it doesn't tell me is how to implement this
method. What do I return?
Thirdly, depending on how your app is laid out, are you sure you want
two undo managers? Remember that the undo manager controls the undo
stack. Let's say the user makes a change A in the first text view,
change B in the second, and change C in the first. With two undo
managers, he will be be able to undo C then A when he is in the first
text view, but if he switches to the second, he will only be able to
undo B.
That's the behaviour I want. The main window is always present, whereas
the drawer opens and closes, so tracking changes and saving is handled
separately for each text view. Furthermore, if the user is editing text
view A and hits undo, it would be disastrous if the result was to undo
something typed a few minutes before in text view B.
-Jeremy
========================================
email@hidden
theLocustFarm.net:
- fractious fiction at
http://freespace.virgin.net/jeremy.dronfield
========================================
_______________________________________________
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.