Adding to the undo chain of an NSTextView for a linked view?
Adding to the undo chain of an NSTextView for a linked view?
- Subject: Adding to the undo chain of an NSTextView for a linked view?
- From: Keith Blount <email@hidden>
- Date: Sun, 9 Jan 2005 13:51:39 -0800 (PST)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
Hello,
I have an NSTextView with an attached (custom) margin
view. Whenever the text is changed in the text view,
the location of the margin notes (each note is a
custom view that is a sub view of the margin) is
updated. I am now faced with the problem of making the
undo mechanism work intuitively.
The view basically works like this: each note "card"
is attached to the text in the text view by keeping
track of a certain character index, which is altered
as necessary in the textDidChange: delegate method. If
all of the text is deleted from the text view, for
instance, all of the cards will now be attached to
character index 0, as you would expect. But if the
user hits Undo at this stage, I need it so that not
only is the text restored, but also the note cards in
the margin are all restored to their former positions
(ie. they are all reset to track their former
character indices). I cannot seem to find a
satisfactory way of doing this.
I tried listening for
NSUndoManagerDidOpenUndoGroupNotification and adding
the following method:
- (void)textViewUndoGroupChanged:(NSNotification
*)notification
{
if ([notification object] == [textView undoManager])
{
NSArray *oldCards = [self cards];
NSUndoManager *undo = [textView undoManager];
[[undo prepareWithInvocationTarget:self]
undoRedoMarginCardsWithCardInfo:oldCards];
}
}
However, because the textview undoManager is the exact
same undo manager as my margin view uses, this method
gets called even when I'm adding cards, so things get
very confused on redo.
I'd be very grateful if anyone has any suggestions as
to how I might successfully implement undo and redo in
this situation.
Many thanks in advance,
Keith
__________________________________
Do you Yahoo!?
Take Yahoo! Mail with you! Get it on your mobile phone.
http://mobile.yahoo.com/maildemo
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden