• 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: How to make Redo work with a custom group
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to make Redo work with a custom group


  • Subject: Re: How to make Redo work with a custom group
  • From: David Spooner <email@hidden>
  • Date: Mon, 29 Oct 2007 13:25:06 -0600


On 29-Oct-07, at 10:42 AM, Paul Bruneau wrote:

Coincidentally, I did in fact use the undo manager as a parameter in a different part of my application. I was considering removing that because this app is non-document based and I want just a single undo manager throughout the whole thing anyway. I'll think more about that.

When you say "use the undo manager at the lowest level" you don't really mean the LOWEST level do you? By that I mean, you didn't implement undo into your ivar setter methods did you?

The operations for which you want to provide an inverse should take an undo manager. If these operations are written as a sequence of more primitive operations then it may be convenient to provide the undo manager as an argument to those primitive methods also. For example, in a method which splits an edge of a triangle mesh you need to replace the selected edge and its two adjacent triangles with a new vertex attached to four new edges and four new triangles. By adding the undo manager as parameter to the primitive methods for vertex/edge/face addition and removal (where the inverse operation is easy) there was no need to write an explicit inverse method.



What I did which seems to work well is to make the following method in my view's controller:

- (void)moveOrderStep:(OrderStep *)orderStep
		  toStartTime:(NSDate *)newStartTime;
{
	//add the inverse of this operation to the undo stack
	[[[appController myUndo] prepareWithInvocationTarget:self]
		moveOrderStep:orderStep
		  toStartTime:[orderStep startTime]];

	if (![[appController myUndo] isUndoing])
	{
		[[appController myUndo] setActionName:@"move order step"];
	}
}

This gives me a sort of an undo "middle man" that can be called by the higher level methods which in turn calls the setter of the order step's ivar.

I'm not sure I understand. You say the caller of this method also actually effects the start time, or did you leave out the call to - setStartTime:?



I found the following method useful for the many situations in which I wanted undo for setting object attributes...


@implementation NSObject(...)
- (void) setValue:(id)value forKeyPath:(NSString *)path undo: (NSUndoManager *)undo
{
if (undo != nil)
[[undo prepareWithInvocationTarget:self] setValue:[self valueForKeyPath:path] forKeyPath:path undo:undo];
[self setValue:value forKeyPath:path];
}
@end



Thanks again,

PB

Cheers, dave

_______________________________________________

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: How to make Redo work with a custom group
      • From: Paul Bruneau <email@hidden>
References: 
 >How to make Redo work with a custom group (From: Paul Bruneau <email@hidden>)
 >Re: How to make Redo work with a custom group (From: David Spooner <email@hidden>)
 >Re: How to make Redo work with a custom group (From: Paul Bruneau <email@hidden>)

  • Prev by Date: Re: [Leopard] Debugging GC
  • Next by Date: Re: How to make Redo work with a custom group
  • Previous by thread: Re: How to make Redo work with a custom group
  • Next by thread: Re: How to make Redo work with a custom group
  • Index(es):
    • Date
    • Thread