Re: The Problems with NSController (Undo)
Re: The Problems with NSController (Undo)
- Subject: Re: The Problems with NSController (Undo)
- From: Jonathan Wight <email@hidden>
- Date: Sun, 26 Oct 2003 14:45:39 -0600
>
From: Mike Nowak <email@hidden>
>
Date: Sun, 26 Oct 2003 15:12:25 -0500
>
To: Cocoa-Dev Mail <email@hidden>
>
Subject: Re: The Problems with NSController (Undo)
>
>
I got this useful information from Shaun Wexler to make the first demo
>
in the NSController tutorial to work. See below. The lack of Undo
>
support is a little scary. Is there a way to easily add it? I suppose
>
you could do the registration with the Undo Manager in the setters,
>
like we used to, as in:
>
>
[[[self undoManager] prepareWithInvocationTarget:self]
>
setDollarsToConvert:value];
I'm doing undo handling in my "observeValueForKeyPath" delegate method. In
my document creation I'm registering for NSKeyValueObservation:
[self addObserver:self forKeyPath:@"waypoints"
options:NSKeyValueObservingOptionOld context:NULL];
And then I have my delegate method (snippet):
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqual:@"waypoints"])
{
[[self undoManager] registerUndoWithTarget:self
selector:@selector(setWaypoints:) object:[change
objectForKey:NSKeyValueChangeOldKey]];
}
}
I've only just started with this method so it might not be the best way. But
this method is really simple. So while NSController doesn't provide
automatic undo support it is still pretty simple.
Jon.
_______________________________________________
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.