Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1372 Rev 1422
1
/*
1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
3
	All Rights Reserved.
4
 
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
9
*/
-
 
10
 
-
 
11
 
10
 
12
 
11
dojo.provide("dojo.undo.Manager");
13
dojo.provide("dojo.undo.Manager");
12
dojo.require("dojo.lang.common");
14
dojo.require("dojo.lang.common");
13
dojo.undo.Manager = function (parent) {
15
dojo.undo.Manager = function (parent) {
14
	this.clear();
16
	this.clear();
15
	this._parent = parent;
17
	this._parent = parent;
16
};
18
};
17
dojo.extend(dojo.undo.Manager, {_parent:null, _undoStack:null, _redoStack:null, _currentManager:null, canUndo:false, canRedo:false, isUndoing:false, isRedoing:false, onUndo:function (manager, item) {
19
dojo.extend(dojo.undo.Manager, {_parent:null, _undoStack:null, _redoStack:null, _currentManager:null, canUndo:false, canRedo:false, isUndoing:false, isRedoing:false, onUndo:function (manager, item) {
18
}, onRedo:function (manager, item) {
20
}, onRedo:function (manager, item) {
19
}, onUndoAny:function (manager, item) {
21
}, onUndoAny:function (manager, item) {
20
}, onRedoAny:function (manager, item) {
22
}, onRedoAny:function (manager, item) {
21
}, _updateStatus:function () {
23
}, _updateStatus:function () {
22
	this.canUndo = this._undoStack.length > 0;
24
	this.canUndo = this._undoStack.length > 0;
23
	this.canRedo = this._redoStack.length > 0;
25
	this.canRedo = this._redoStack.length > 0;
24
}, clear:function () {
26
}, clear:function () {
25
	this._undoStack = [];
27
	this._undoStack = [];
26
	this._redoStack = [];
28
	this._redoStack = [];
27
	this._currentManager = this;
29
	this._currentManager = this;
28
	this.isUndoing = false;
30
	this.isUndoing = false;
29
	this.isRedoing = false;
31
	this.isRedoing = false;
30
	this._updateStatus();
32
	this._updateStatus();
31
}, undo:function () {
33
}, undo:function () {
32
	if (!this.canUndo) {
34
	if (!this.canUndo) {
33
		return false;
35
		return false;
34
	}
36
	}
35
	this.endAllTransactions();
37
	this.endAllTransactions();
36
	this.isUndoing = true;
38
	this.isUndoing = true;
37
	var top = this._undoStack.pop();
39
	var top = this._undoStack.pop();
38
	if (top instanceof dojo.undo.Manager) {
40
	if (top instanceof dojo.undo.Manager) {
39
		top.undoAll();
41
		top.undoAll();
40
	} else {
42
	} else {
41
		top.undo();
43
		top.undo();
42
	}
44
	}
43
	if (top.redo) {
45
	if (top.redo) {
44
		this._redoStack.push(top);
46
		this._redoStack.push(top);
45
	}
47
	}
46
	this.isUndoing = false;
48
	this.isUndoing = false;
47
	this._updateStatus();
49
	this._updateStatus();
48
	this.onUndo(this, top);
50
	this.onUndo(this, top);
49
	if (!(top instanceof dojo.undo.Manager)) {
51
	if (!(top instanceof dojo.undo.Manager)) {
50
		this.getTop().onUndoAny(this, top);
52
		this.getTop().onUndoAny(this, top);
51
	}
53
	}
52
	return true;
54
	return true;
53
}, redo:function () {
55
}, redo:function () {
54
	if (!this.canRedo) {
56
	if (!this.canRedo) {
55
		return false;
57
		return false;
56
	}
58
	}
57
	this.isRedoing = true;
59
	this.isRedoing = true;
58
	var top = this._redoStack.pop();
60
	var top = this._redoStack.pop();
59
	if (top instanceof dojo.undo.Manager) {
61
	if (top instanceof dojo.undo.Manager) {
60
		top.redoAll();
62
		top.redoAll();
61
	} else {
63
	} else {
62
		top.redo();
64
		top.redo();
63
	}
65
	}
64
	this._undoStack.push(top);
66
	this._undoStack.push(top);
65
	this.isRedoing = false;
67
	this.isRedoing = false;
66
	this._updateStatus();
68
	this._updateStatus();
67
	this.onRedo(this, top);
69
	this.onRedo(this, top);
68
	if (!(top instanceof dojo.undo.Manager)) {
70
	if (!(top instanceof dojo.undo.Manager)) {
69
		this.getTop().onRedoAny(this, top);
71
		this.getTop().onRedoAny(this, top);
70
	}
72
	}
71
	return true;
73
	return true;
72
}, undoAll:function () {
74
}, undoAll:function () {
73
	while (this._undoStack.length > 0) {
75
	while (this._undoStack.length > 0) {
74
		this.undo();
76
		this.undo();
75
	}
77
	}
76
}, redoAll:function () {
78
}, redoAll:function () {
77
	while (this._redoStack.length > 0) {
79
	while (this._redoStack.length > 0) {
78
		this.redo();
80
		this.redo();
79
	}
81
	}
80
}, push:function (undo, redo, description) {
82
}, push:function (undo, redo, description) {
81
	if (!undo) {
83
	if (!undo) {
82
		return;
84
		return;
83
	}
85
	}
84
	if (this._currentManager == this) {
86
	if (this._currentManager == this) {
85
		this._undoStack.push({undo:undo, redo:redo, description:description});
87
		this._undoStack.push({undo:undo, redo:redo, description:description});
86
	} else {
88
	} else {
87
		this._currentManager.push.apply(this._currentManager, arguments);
89
		this._currentManager.push.apply(this._currentManager, arguments);
88
	}
90
	}
89
	this._redoStack = [];
91
	this._redoStack = [];
90
	this._updateStatus();
92
	this._updateStatus();
91
}, concat:function (manager) {
93
}, concat:function (manager) {
92
	if (!manager) {
94
	if (!manager) {
93
		return;
95
		return;
94
	}
96
	}
95
	if (this._currentManager == this) {
97
	if (this._currentManager == this) {
96
		for (var x = 0; x < manager._undoStack.length; x++) {
98
		for (var x = 0; x < manager._undoStack.length; x++) {
97
			this._undoStack.push(manager._undoStack[x]);
99
			this._undoStack.push(manager._undoStack[x]);
98
		}
100
		}
99
		if (manager._undoStack.length > 0) {
101
		if (manager._undoStack.length > 0) {
100
			this._redoStack = [];
102
			this._redoStack = [];
101
		}
103
		}
102
		this._updateStatus();
104
		this._updateStatus();
103
	} else {
105
	} else {
104
		this._currentManager.concat.apply(this._currentManager, arguments);
106
		this._currentManager.concat.apply(this._currentManager, arguments);
105
	}
107
	}
106
}, beginTransaction:function (description) {
108
}, beginTransaction:function (description) {
107
	if (this._currentManager == this) {
109
	if (this._currentManager == this) {
108
		var mgr = new dojo.undo.Manager(this);
110
		var mgr = new dojo.undo.Manager(this);
109
		mgr.description = description ? description : "";
111
		mgr.description = description ? description : "";
110
		this._undoStack.push(mgr);
112
		this._undoStack.push(mgr);
111
		this._currentManager = mgr;
113
		this._currentManager = mgr;
112
		return mgr;
114
		return mgr;
113
	} else {
115
	} else {
114
		this._currentManager = this._currentManager.beginTransaction.apply(this._currentManager, arguments);
116
		this._currentManager = this._currentManager.beginTransaction.apply(this._currentManager, arguments);
115
	}
117
	}
116
}, endTransaction:function (flatten) {
118
}, endTransaction:function (flatten) {
117
	if (this._currentManager == this) {
119
	if (this._currentManager == this) {
118
		if (this._parent) {
120
		if (this._parent) {
119
			this._parent._currentManager = this._parent;
121
			this._parent._currentManager = this._parent;
120
			if (this._undoStack.length == 0 || flatten) {
122
			if (this._undoStack.length == 0 || flatten) {
121
				var idx = dojo.lang.find(this._parent._undoStack, this);
123
				var idx = dojo.lang.find(this._parent._undoStack, this);
122
				if (idx >= 0) {
124
				if (idx >= 0) {
123
					this._parent._undoStack.splice(idx, 1);
125
					this._parent._undoStack.splice(idx, 1);
124
					if (flatten) {
126
					if (flatten) {
125
						for (var x = 0; x < this._undoStack.length; x++) {
127
						for (var x = 0; x < this._undoStack.length; x++) {
126
							this._parent._undoStack.splice(idx++, 0, this._undoStack[x]);
128
							this._parent._undoStack.splice(idx++, 0, this._undoStack[x]);
127
						}
129
						}
128
						this._updateStatus();
130
						this._updateStatus();
129
					}
131
					}
130
				}
132
				}
131
			}
133
			}
132
			return this._parent;
134
			return this._parent;
133
		}
135
		}
134
	} else {
136
	} else {
135
		this._currentManager = this._currentManager.endTransaction.apply(this._currentManager, arguments);
137
		this._currentManager = this._currentManager.endTransaction.apply(this._currentManager, arguments);
136
	}
138
	}
137
}, endAllTransactions:function () {
139
}, endAllTransactions:function () {
138
	while (this._currentManager != this) {
140
	while (this._currentManager != this) {
139
		this.endTransaction();
141
		this.endTransaction();
140
	}
142
	}
141
}, getTop:function () {
143
}, getTop:function () {
142
	if (this._parent) {
144
	if (this._parent) {
143
		return this._parent.getTop();
145
		return this._parent.getTop();
144
	} else {
146
	} else {
145
		return this;
147
		return this;
146
	}
148
	}
147
}});
149
}});
148
 
150