I have a popover that opens and closes.
When it opens, I call -beginUndoGrouping
on my NSUndoManager
.
When it closes, I call -endUndoGrouping
.
If I view my undo stack after the fact, I see this:
0: endUndoGrouping
1: endUndoGrouping
2: beginUndoGrouping
3: beginUndoGrouping
Note that there are no actions added inbetween the popover opening and closing. I assume the grouping stays around because there is a nested undo group?
But I searched everywhere, and I am 100% positive I am not creating the nested group myself. Here is my code:
- (void)colorWellWillShow:(NSNotification*)notification
{
NSLog(@"HEYHEY");
NSLog(@"GROUP BY EVENT?: %@", [[[[self imageController] document] undoManager] groupsByEvent] ? @"YES": @"NO");
NSLog(@"GROUPING LEVEL: %ld", (long)[[[[self imageController] document] undoManager] groupingLevel]);
[[[[self imageController] document] undoManager] beginUndoGrouping];
NSLog(@"GROUP BY EVENT?: %@", [[[[self imageController] document] undoManager] groupsByEvent] ? @"YES": @"NO");
NSLog(@"GROUPING LEVEL: %ld", (long)[[[[self imageController] document] undoManager] groupingLevel]);
}
- (void)colorWellDidClose:(NSNotification*)notification
{
NSLog(@"GROUP BY EVENT?: %@", [[[[self imageController] document] undoManager] groupsByEvent] ? @"YES": @"NO");
NSLog(@"GROUPING LEVEL: %ld", (long)[[[[self imageController] document] undoManager] groupingLevel]);
[[[[self imageController] document] undoManager] endUndoGrouping];
NSLog(@"GROUP BY EVENT?: %@", [[[[self imageController] document] undoManager] groupsByEvent] ? @"YES": @"NO");
NSLog(@"GROUPING LEVEL: %ld", (long)[[[[self imageController] document] undoManager] groupingLevel]);
}
Here is the output when I reproduce:
2015-12-21 15:37:41.300 Snagit[18714:8416571] HEYHEY 2015-12-21 15:37:41.300 Snagit[18714:8416571] GROUP BY EVENT?: YES 2015-12-21 15:37:41.300 Snagit[18714:8416571] GROUPING LEVEL: 0 2015-12-21 15:37:41.301 Snagit[18714:8416571] GROUP BY EVENT?: YES 2015-12-21 15:37:41.301 Snagit[18714:8416571] GROUPING LEVEL: 2 2015-12-21 15:37:45.000 Snagit[18714:8416571] GROUP BY EVENT?: YES 2015-12-21 15:37:45.000 Snagit[18714:8416571] GROUPING LEVEL: 1 2015-12-21 15:37:45.001 Snagit[18714:8416571] GROUP BY EVENT?: YES 2015-12-21 15:37:45.001 Snagit[18714:8416571] GROUPING LEVEL: 0
Based on this, it looks like when I call -beginUndoGrouping
, it immediately pushes 2 "beginUndoGrouping" actions onto the stack.
It would appear that any action I add at this point will go into the inner group.
Then directly before I call -endUndoGrouping
, it magically thinks that there is only one undo group, so I can only assume any actions added at this point would go into the outer group.
And then after the call it thinks that I am back at the bottom level, and will add actions outside of the group.
So my question is, why are two groups being pushed onto my undo stack when I am only calling -beginUndoGrouping
once? And how can I remove all of the groups from my undo stack if there are no actions inside of the group? I believe this should happen automatically, but again, because there is a nested undo group inside of the outer group-- the outer group does not automatically resolve.