RE: Adding to the undo chain of an NSTextView for a linked view?
RE: Adding to the undo chain of an NSTextView for a linked view?
- Subject: RE: Adding to the undo chain of an NSTextView for a linked view?
- From: Keith Blount <email@hidden>
- Date: Mon, 10 Jan 2005 15:23:20 -0800 (PST)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
Sorry to reply to my own message, but I've thought
long and hard and this, and still am none the wise -
all the books I have only cover the basics of
NSUndoManager, and I can't find anything in the docs
that covers this sort of situation.
I think this is what I need to do:
Whenever a block of text is edited and a new undo
group is set up for it, I need to save the current
configuration of the note cards. But the trouble is
still that I don't know how to do this *only* when an
undo group is opened for the text view - because
NSUndoManagerDidOpenUndoGroupNotification is sent for
all undo group openings, and the notification object
is the shared undo manager which tells me nothing...
In short, I'm still stumped. If anybody has got any
ideas, I'd be really grateful.
Many thanks again,
Keith
--Original message--
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!?
Yahoo! Mail - Helps protect you from nasty viruses.
http://promotions.yahoo.com/new_mail
_______________________________________________
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