Multiple controls undo (NSTextView + NSTextField)
Multiple controls undo (NSTextView + NSTextField)
- Subject: Multiple controls undo (NSTextView + NSTextField)
- From: Simon Jacquier <email@hidden>
- Date: Tue, 05 Mar 2002 11:38:31 +0100
Hi Cocoa-dev folks,
I'm new to Cocoa programming (less than two weeks) and I ran into a problem
while porting my first app from REALbasic to Obj-C.
My application is document based and my document window holds (among others)
a NSTextView and a NSTextField called "textLink". I have an action called
-myClear: to empty the content of both the textView and the textField and
I'd like to be able to undo it. I've RTFM but I can't figure out how to do
it correctly. Here is how my code looks like:
- (IBAction)myClear:(id)sender
{
[[[textView window] undoManager] beginUndoGrouping];
[[[[textView window] undoManager] prepareWithInvocationTarget:self]
setTextViewValue:[[textView textStorage] string]];
[[[[textView window] undoManager] prepareWithInvocationTarget:self]
setTextLinkValue:[textLink stringValue]];
[self setTextLinkValue:@""];
[self setTextViewValue:@""];
[[[textView window] undoManager] endUndoGrouping];
}
- (void)setTextViewValue:(NSString *)viewValue
{
[textView replaceCharactersInRange:NSMakeRange(0, [[textView
textStorage] length]) withString:viewValue];
}
- (void)setTextLinkValue:(NSString *)linkValue
{
[textLink setStringValue:linkValue];
}
At first, I tried with a single method (-setTextViewValue:(NSString
*)viewValue textLinkValue:(NSString *)linkValue), and then with and without
begin/endUndoGrouping, but no success. The textField is reverting correctly
to its old value but the textField is staying desperately empty.
I guess the problem is my textView has its own, Cocoa-driven undoManager.
I tried to -disableUndoRegistration for my textView's undoManager and then
reenable it but it didn't worked. Perhaps I did it at the wrong place... I
still need this automated undoManager for undoing other actions, so I can't
disable it entirely.
Any tip is welcome.
Thanks,
Simon
_______________________________________________
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.