清除 NSUndoManager 的重做堆栈
在我的应用程序中,我想以编程方式撤消一些操作,而不向用户提供单击“重做”的选项。有没有办法清除NSUndoManager
的Redo堆栈?如果没有,并且我要子类化 NSUndoManager,是否有任何方法可以访问重做堆栈以清除它?我没有从文档中看到任何方法。
或者,是否有一种方法可以恢复当前嵌套撤消组的更改而不填充重做堆栈?我已经在构建一个嵌套撤消组。
In my application, there are some actions I want to undo programmatically, without giving the user the option of clicking "Redo". Is there any way to clear the Redo stack of NSUndoManager
? If not, and I were to subclass NSUndoManager
, is there any way to get access to the redo stack in order to clear it? I didn't see any way to from the documentation.
Alternately, is there a way to revert the changes from the current nested undo group without it populating the Redo stack? I'm already building a nested undo group.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最终采取了两步方法。第一步是创建一个虚拟撤消项,它会清除重做堆栈。然后,我只需删除该撤消项目,两个堆栈都是干净的。
我能够使用 self 作为虚拟撤消目标,因为我没有任何与包含代码的类关联的实际撤消操作。
self
可以替换为任何不参与撤消堆栈的对象。诀窍是延迟调用
removeAllActionsWithTarget
,否则它不会产生任何效果。I ended up taking a 2-step approach. The first step was to create a dummy undo item, which clears the Redo stack. Then, I just had to remove that undo item, and both stacks are clean.
I was able to use
self
as the dummy undo target, since I don't have any actual undo actions associated with the class containing the code.self
could be replaced with any object that doesn't contribute to the Undo stack.The trick was calling
removeAllActionsWithTarget
with a delay, otherwise it doesn't have an effect.