Undo Architecture
【Undo Architecture】
NSUndoManager is a general-purpose recorder of operations for undo and redo. NSUndoManager是一个通常目的操作记录器用于实现undo和redo。
When you perform an action that changes the property values of an object (for example, by invoking a set accessor method), you can also register with an undo manager an operation that can reverse the action. 在设置属性时同时注册undo操作。
An undo manager collects all undo operations that occur within a single cycle of the run loop,so that performing an undo reverts all changes that occurred during the cycle. Also, when performing undo an undo manager saves the operations that were reverted so that you can redo the undos.
Because NSUndoManager also supports redo, these operations should typically be reversible. The method that’s invoked during an undo operation should itself register an undo operation that will then serve as the redo action.
Undo operations are typically collected in undo groups, which represent whole revertible actions, and are stored on a stack. When an undo manager performs undo or redo, it is actually undoing or redoing an entire group of operations.
Redo operations and groups are simply undo operations stored on a separate stack.
NSUndoManager normally creates undo groups automatically during the run loop. The first time it is asked to record an undo operation in the run loop, it creates a new group. Then, at the end of the loop, it closes the group.
Undo groups are stored on a stack, with the oldest groups at the bottom and the newest at the top. The undo stack is unlimited by default, but you can restrict it to a maximum number of groups using the setLevelsOfUndo: method. When the stack exceeds the maximum, the oldest undo groups are dropped from the bottom.
【Undo的注册】
- (void)setMyObjectTitle:(NSString *)newTitle {
NSString *currentTitle = [myObject title];
if (newTitle != currentTitle) {
[undoManager registerUndoWithTarget:self
selector:@selector(setMyObjectTitle:)
object:currentTitle];
[undoManager setActionName:NSLocalizedString(@"Title Change", @"title undo")];
[myObject setTitle:newTitle];
}
}
In an undo operation, setMyObjectTitle: is invoked with the previous value. Notice that this will again invoke the registerUndoWithTarget:selector:object: method—in this case with the “new” value of myObject’s title. Since the undo manager is in the process of undoing, it is recorded as a redo operation.
【Performing Undo and Redo】
The undo method is intended for undoing top-level groups, and should not be used for nested undo groups. If any unclosed, nested undo groups are on the stack when undo is invoked, it raises an exception. To undo nested groups, you must explicitly close the group with an endUndoGrouping message, then use undoNestedGroup to undo it. Note also that if you turn off automatic grouping by event with setGroupsByEvent:, you must explicitly close the current undo group with endUndoGrouping before invoking either undo method.
An NSUndoManager object does not retain the targets of undo operations. The client—the object performing undo operations—typically owns the undo manager, so if the undo manager in turn retained its target this would frequently create a retain cycle.
更多信息参考:《Introduction to Undo Architecture》
Undo Architecture的更多相关文章
- Undo/Redo for Qt Tree Model
Undo/Redo for Qt Tree Model eryar@163.com Abstract. Qt contains a set of item view classes that use ...
- Some current MySQL Architecture writings
Posted on 19/09/2014 by Stewart Smith So, I’ve been looking around for a while (and a few times now) ...
- JavaScript Application Architecture On The Road To 2015
JavaScript Application Architecture On The Road To 2015 I once told someone I was an architect. It’s ...
- The Architecture of Open Source Applications: Berkeley DB
最近研究内存关系数据库的设计与实现,下面一篇为berkeley db原始两位作为的Berkeley DB设计回忆录: Conway's Law states that a design reflect ...
- MySQL 5.6 Reference Manual-14.2 InnoDB Concepts and Architecture
14.2 InnoDB Concepts and Architecture 14.2.1 MySQL and the ACID Model 14.2.2 InnoDB Multi-Versioning ...
- InnoDB Architecture (InnoDB In-Memory Structures 转载)
转载.节选于 https://dev.mysql.com/doc/refman/8.0/en/innodb-in-memory-structures.html InnoDB Architecture ...
- MySQL,MariaDB:Undo | Redo [转]
本文是介绍MySQL数据库InnoDB存储引擎重做日志漫游 00 – Undo LogUndo Log 是为了实现事务的原子性,在MySQL数据库InnoDB存储引擎中,还用Undo Log来实现多版 ...
- iOS: 为画板App增加 Undo/Redo(撤销/重做)操作
这个随笔的内容以上一个随笔为基础,(在iOS中实现一个简单的画板),上一个随笔实现了一个简单的画板: 今天我们要为这个画板增加Undo/Redo操作,当画错了一笔,可以撤销它,或者撤销之后后悔了, ...
- Undefined symbols for architecture arm64解决方案
在iOS开发中经常遇到的一个错误是Undefined symbols for architecture arm64,这个错误表示工程某些地方不支持arm64指令集.那我们应该怎么解决这个问题了?我们不 ...
随机推荐
- 设计模式(Python)-观察者模式
本系列文章是希望将软件项目中最常见的设计模式用通俗易懂的语言来讲解清楚,并通过Python来实现,每个设计模式都是围绕如下三个问题: 为什么?即为什么要使用这个设计模式,在使用这个模式之前存在什么样的 ...
- 在IE7+ 中弹出窗口并关闭本身窗口的脚本(备忘)
window.onload =function(){ window.open("http://www.126.com"); window.opener=null; window.o ...
- 从 FastAdmin 项目上学了什么?
从 FastAdmin 项目上学了什么? 接触到 FastAdmin 我学了好多,自己记录一下 Xmind git 系统学习了 Javascript jQuery 重新开始玩 ThinkPHP 开始记 ...
- 大数据之 ZooKeeper原理及其在Hadoop和HBase中的应用
ZooKeeper是一个开源的分布式协调服务,由雅虎创建,是Google Chubby的开源实现.分布式应用程序可以基于ZooKeeper实现诸如数据发布/订阅.负载均衡.命名服务.分布式协调/通知. ...
- winodws同步时间命令
首先,你应该判断你的两台域控制器,哪一台担任PDC角色(默认的域内权威的时间服务源). 判断方法很简单,单击“开始”,单击“运行”,键入dsa.msc,然后点确定.这时会打开“Active Direc ...
- 手动更新花生壳域名的动态IP
http://帐号:密码@ddns.oray.com/ph/update?hostname=hahaha.vicp.cc&myip=182.xx.200.xx 花生壳的文档地址 例子 1.使用 ...
- VS2017新建windows控制台程序打印中文乱码问题
最近刚换上VS2017,由于手头又要做个MFC的程序,所以写控制台程序做功能测试,然后发现居然乱码了. 于是用VS2017新建windows控制台应用程序,在main函数种加一句printf(&quo ...
- scrollTop、offsetHeight和offsetTop等属性用法详解--转转转
scrollTop.offsetHeight和offsetTop等属性用法详解: 标题中的几个相关相关属性在网页中有这大量的应用,尤其是在运动框架中,但是由于有些属性相互之间的概念比较混杂或者浏览器兼 ...
- 认识Linux操作系统
Linux系统是一个类似UNIX的操作系统 认识Linux的来世与今生 1.Linux系统的历史 Linux系统是一个类似UNIX的操作系统,Linux系统是UNIX在微机上的完整实现,它的标志是一个 ...
- 在Windows命令行窗口中输入并运行PHP代码片段(不需要php文件)的方法
有时候只是简单的为了测试某个php函数的效果,以前总是需要建一个php文件,复制这个文件的路径,再通过web访问或者用php命令执行这个php文件. 一直想要怎么才能不用创建文件,才能直接执行PHP代 ...