• 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: Need advice on a custom run-loop mode
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need advice on a custom run-loop mode


  • Subject: Re: Need advice on a custom run-loop mode
  • From: Graham Cox <email@hidden>
  • Date: Sat, 21 May 2016 14:27:35 +1000

Maybe spoke too soon, as so far I’ve been unsuccessful in getting this to work as I wish. My code does perform the series of undos, but I can’t see the results until the end - the window isn’t refreshed on each pass of the runloop as I expected.

Here’s my code:

- (BOOL)		performUndoUntilGroup:(GCUndoGroup*) desiredTopOfStack
{
	// check if there's anything to do:

	if( self.undoManager.canUndo && self.undoManager.peekUndo != desiredTopOfStack )
	{
		// set up timer to repeatedly invoke Undo

		NSTimer* timer = [NSTimer timerWithTimeInterval:kMDABUndoHistoryUndoInvocationRate target:self.undoManager selector:@selector(undo) userInfo:NULL repeats:YES];
		[[NSRunLoop mainRunLoop] addTimer:timer forMode:MDABUndoHistoryRunLoopMode];

		// run loop in special custom mode until finished or times out (allow twice the scheduled time to finish)

		NSDate* maxEndDate = [NSDate distantPast];//[NSDate dateWithTimeIntervalSinceNow:self.undoManager.numberOfUndoActions * kMDABUndoHistoryUndoInvocationRate * 2];

		while( self.undoManager.canUndo && self.undoManager.peekUndo != desiredTopOfStack )
		{
			[[NSRunLoop mainRunLoop] runMode:MDABUndoHistoryRunLoopMode beforeDate:maxEndDate];
			[self.view.window displayIfNeeded];
		}

		// get rid of timer

		[timer invalidate];

		return YES;
	}
	return NO;
}



The ‘self.undoManager’ is not NSUndoManager but GCUndoManager, which has some methods that differ from NSUndoManager that make this possible - that all works, and is not important here.

As you can see I’ve experimented with the end date, but seems that -distantPast works well enough. I’ve also tried forcing a window redisplay on each pass (as here) but it doesn’t appear to do anything; my understanding was that the runloop should take care of this anyway.

What am I missing?


—Graham






> On 21 May 2016, at 12:14 PM, Graham Cox <email@hidden> wrote:
>
> Great, thanks! Perfect answer,actually...
>
>
> —Graham
>
>
>> On 21 May 2016, at 1:00 AM, Jens Alfke <email@hidden> wrote:
>>
>>
>>> On May 20, 2016, at 12:58 AM, Graham Cox <email@hidden> wrote:
>>>
>>> First question: does that even sound like a proper use for a custom run-loop mode?
>>
>> Yes.
>>
>>> If the answer is yes, how do I cause the run loop to run in that mode? Do I have to run the loop mysef until the operation is done?
>>
>> Yes, use a `while` loop that calls -runMode:beforeDate: repeatedly until all of the actions are done.
>>
>> —Jens
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Need advice on a custom run-loop mode
      • From: Roland King <email@hidden>
References: 
 >Need advice on a custom run-loop mode (From: Graham Cox <email@hidden>)
 >Re: Need advice on a custom run-loop mode (From: Jens Alfke <email@hidden>)
 >Re: Need advice on a custom run-loop mode (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Need advice on a custom run-loop mode
  • Next by Date: Re: Need advice on a custom run-loop mode
  • Previous by thread: Re: Need advice on a custom run-loop mode
  • Next by thread: Re: Need advice on a custom run-loop mode
  • Index(es):
    • Date
    • Thread