Re: Continuous controls and undo
Re: Continuous controls and undo
- Subject: Re: Continuous controls and undo
- From: "Erik M. Buck" <email@hidden>
- Date: Sat, 8 Jan 2005 13:10:46 -0500
In the past, I have implemented undo for values changed by continuous
controls by taking advantage of the fact that most continuous Cocoa controls
including NSSlider co-opt the normal event loop and process their own modal
event loop until mouseUp.
Composed in email:
- (void)takeValueFromContinuousControl:(id)sender
{
// Register undo message NOW with initial value that will be restored by
undo
// subsequent calls before continuous control stops will not register
[[undoManager prepareWithInvocationTarget:self] setFoo:[self foo]];
// If undo recording is not already disabled, disable undo recording NOW
if(undoIsEnabled)
{
[undoManager disableUndoRegistration];
undoIsEnabled = NO;
// Schedule a message to be sent after continuous control stops stealing
events
// -concludeTakeValueFromContinuousControl: will not be called until
AFTER sender stops stealing events
// (usually after mouseUp) and the run loop resumes
[self performSelector:@selector(concludeTakeValueFromContinuousControl:)
withObject:nil afterDelay:0];
}
// Change whatever objects should be changed by changes to sender [undo is
disabled]
[self setFoo:[sender fooValue]];
}
- (void)concludeTakeValueFromContinuousControl:(id)unused
{
// Reenable undo recording
if(!undoIsEnabled )
{
[undoManager enableUndoRegistration];
undoIsEnabled = YES;
}
}
undoIsEnabled needs to be an instance variable or static somewhere. It
would be nice if NSUndoManager had an -isUndoEnabled method.
_______________________________________________
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