• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Continuous controls and undo
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Continuous controls and undo
      • From: Dan Bernstein <email@hidden>
  • Prev by Date: Re: Continuous controls and undo
  • Next by Date: Re: Continuous controls and undo
  • Previous by thread: Re: Continuous controls and undo
  • Next by thread: Re: Continuous controls and undo
  • Index(es):
    • Date
    • Thread