Re: undo oddness
Re: undo oddness
- Subject: Re: undo oddness
- From: Jeremy Dronfield <email@hidden>
- Date: Wed, 12 May 2004 21:32:17 +0100
On 12 May 2004, at 6:29 pm, Robert Goldsmith wrote:
Hi :)
Ok, I'm stumped. I have a text view in a scroll view in a split view in
a window. I have set the text view to use undo in IB and it's delegate
responds to undoManagerForTextView:. This all -seems- to work, in that
I know the delegate method is called etc. However, the undo and redo
menu items are never available. They are connected to the first
responder so should work just like cut, copy, paste etc (which all DO
work).
My only thought is that I do odd stuff with the text storage for the
text view (I swap in and out multiple text storages), and I set the
text view to editable and non-editable (and, for good measure, at the
same time, setAllowUndo: yes/no). But my experience of responder chains
and auto-enabling menu items is that they check every time so all the
storage switching should have no effect on them.
So has anyone any idea why my undo and redo menu items are never
enabled?
My experience of -undoManagerForTextView: is that it's just not worth
the bother. Unfortunately, I only realised this *after* I'd bothered.
Don't use it unless you really have to. (I really have to.) I finally
made it work using an implementation based on undo in TextEdit. My text
view delegate registers as a notification observer for undo
notifications (NSUndoManagerDidRedoChangeNotification,
NSUndoManagerWillCloseUndoGroupNotification,
NSUndoManagerDidUndoChangeNotification) and I implement these delegate
methods:
- (void)undoManagerChangeDone:(NSNotification *)notification {
if (changeCount == 0) [self setDocumentEdited:YES];
changeCount++;
}
- (void)undoManagerChangeUndone:(NSNotification *)notification {
changeCount--;
if (changeCount == 0) [self setDocumentEdited:NO];
}
-isDocumentEdited: is implemented like so:
- (void)setDocumentEdited:(BOOL)flag {
if (flag != isDocumentEdited) {
isDocumentEdited = flag;
[[myTextView window] setDocumentEdited:isDocumentEdited];
}
if (!isDocumentEdited) changeCount = 0;
}
- (BOOL)isDocumentEdited {
return isDocumentEdited;
}
It's a lot of work to achieve something you normally get for free, but
it works.
Regards,
-Jeremy
_______________________________________________
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.
References: | |
| >undo oddness (From: Robert Goldsmith <email@hidden>) |