Extending Undo Group with delay creates "invalid state" -- Why?
Extending Undo Group with delay creates "invalid state" -- Why?
- Subject: Extending Undo Group with delay creates "invalid state" -- Why?
- From: Jerry Krinock <email@hidden>
- Date: Mon, 3 Aug 2009 12:42:15 -0700
In my Core Data document-based app, I'm trying to group undo
registrations so that the user does not have to hit "Undo" more than
once to undo a single action.
Some of this is caused by the logic in my setters. For example,
changing the 'name' attribute of an object in a collection posts a
coalesced notification which causes the 'timeUnsorted' attribute of my
document's 'configuration' object to be changed to the current time.
(The logic is that changing the name of the object may change its
position in the lexical order of objects sorted by name).
But, apparently because I coalesced this into a notification for
efficiency, the 'timeUnsorted' change gets stacked into a different
undo group. The result is that the user needs to click Undo twice to
undo a name change.
So I replaced the document's undo managed with my own subclass [1]
which overrides -endUndoGrouping such that it performs after a delay
of 0.0. This fixes the double-undo problem, but creates a new problem
-- that upon Undo it complains of an "invalid state"...
When I edit an object's name...
2009-08-03 11:27:10.073 MyApp[3775:10b] 470: Beginning Undo Grouping
2009-08-03 11:27:10.274 MyApp[3775:10b] 1053 Ending Undo Grouping
When I subsequently Undo...
2009-08-03 11:27:15.871 MyApp[3775:10b] 470: Beginning Undo Grouping
2009-08-03 11:27:15.984 MyApp[3775:10b] 1053 Ending Undo Grouping
2009-08-03 11:27:15.986 MyApp[3775:10b] endUndoGrouping:
SSYUndoManager 0x15f24c00 is in invalid state, endUndoGrouping called
with no matching begin
But why? As you can see there ^was^ a "matching begin". 1-1=0.
By the way, I presume that this undo grouping created during undo is
actually a "redo" grouping.
Sincerely,
Jerry Krinock
[1]
@interface SSYUndoManager : NSUndoManager {}
@end
@implementation SSYUndoManager
- (void)beginUndoGrouping
{
NSLog(@"470: Beginning Undo Grouping") ;
[super beginUndoGrouping] ;
[self setActionName:@""] ;
}
- (void)endUndoGrouping
{
[self performSelector:@selector(reallyEndUndoGrouping)
withObject:nil
afterDelay:0.1] ;
}
- (void)reallyEndUndoGrouping
{
NSLog(@"1053 Ending Undo Grouping") ;
[super endUndoGrouping] ;
}
@end
_______________________________________________
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