当只调用一次时,NSUndoManager beginUndoGrouping似乎发生了两次?

时间:2015-12-21 20:47:12

标签: objective-c macos cocoa undo nsundomanager

我有一个打开和关闭的弹出窗口。 打开后,我在-beginUndoGrouping上拨打NSUndoManager。 关闭后,我拨打-endUndoGrouping

如果我在事后查看我的撤销堆栈,我会看到:

  

0:endUndoGrouping
  1:endUndoGrouping
  2:beginUndoGrouping
  3:beginUndoGrouping

请注意,在弹出框开始和结束之间没有添加任何操作。我假设分组保持不变,因为有一个嵌套的撤销组?

但是我到处搜索,我100%肯定我不是自己创建嵌套组。这是我的代码:

- (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]);
}

以下是我重现时的输出:

  

2015-12-21 15:37:41.300 Snagit [18714:8416571]嘿嘿   2015-12-21 15:37:41.300 Snagit [18714:8416571]按活动分组?:是的   2015-12-21 15:37:41.300 Snagit [18714:8416571]分组等级:0   2015-12-21 15:37:41.301 Snagit [18714:8416571] BY BY EVENT?:是的   2015-12-21 15:37:41.301 Snagit [18714:8416571]分组等级:2   2015-12-21 15:37:45.000 Snagit [18714:8416571] BY BY EVENT?:是的   2015-12-21 15:37:45.000 Snagit [18714:8416571]分组等级:1   2015-12-21 15:37:45.001 Snagit [18714:8416571] BY BY EVENT?:是的   2015-12-21 15:37:45.001 Snagit [18714:8416571] GROUPING LEVEL:0

基于此,看起来当我呼叫-beginUndoGrouping时,它会立即推送2" beginUndoGrouping"行动到堆栈上。
看来我此时添加的任何操作都将进入内部组

然后直接之前我调用-endUndoGrouping,它神奇地认为只有一个撤消组,所以我只能假设此时添加的任何操作都会进入外部团体
然后之后调用它认为我回到了底层,并且会在群组之外添加行动。

所以我的问题是,当我只调用-beginUndoGrouping一次时,为什么两个组被推入我的撤销堆栈?如果组内没有任何操作,如何从撤消堆栈中删除所有组?我相信这应该会自动发生,但同样,因为外部组内部有一个嵌套的撤销组 - 外部组不会自动解析。

0 个答案:

没有答案