summaryrefslogtreecommitdiff
path: root/js/dojo-1.6/dojox/drawing/manager/Undo.js
blob: f09b93d52f2cd2a36bc3ee108d4f9fc09b815dc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
	Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/


if(!dojo._hasResource["dojox.drawing.manager.Undo"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.drawing.manager.Undo"] = true;
dojo.provide("dojox.drawing.manager.Undo");

dojox.drawing.manager.Undo = dojox.drawing.util.oo.declare(
	// summary
	//	Handles the Undo in drawing.
	//	NOTE: Only partially implemented!!! There is very
	//		little actual undo functionality!
	//
	function(options){
		this.keys = options.keys;
		this.undostack = [];
		this.redostack = [];
		dojo.connect(this.keys, "onKeyDown", this, "onKeyDown");
	},
	{
		onKeyDown: function(evt){
			if(!evt.cmmd){ return; }
			
			if(evt.keyCode==90 && !evt.shift){
				this.undo();
			}else if((evt.keyCode == 90 && evt.shift) || evt.keyCode==89){
				this.redo();
			}
			
		},
		add: function(stack){
			//console.log("undo add", stack)
			stack.args = dojo.mixin({}, stack.args);
			this.undostack.push(stack);
		},
		apply: function(scope, method, args){
			dojo.hitch(scope, method)(args);
		},
		undo: function(){
			
			var o = this.undostack.pop();
			console.log("undo!", o);
			if(!o){ return; }
			
			o.before();
			
			this.redostack.push(o);
		},
		redo: function(){
			console.log("redo!");
			var o = this.redostack.pop();
			if(!o){ return; }
			if(o.after){
				o.after();
			}else{
				o.before(); ///??????
			}
			
			this.undostack.push(o);
		}
	}
);

}