Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / sketch / UndoStack.js @ 13

History | View | Annotate | Download (1.69 KB)

1 9 andrej.cim
/*
2
        Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3
        Available via Academic Free License >= 2.1 OR the modified BSD license.
4
        see: http://dojotoolkit.org/license for details
5
*/
6
7
8
if(!dojo._hasResource["dojox.sketch.UndoStack"]){
9
dojo._hasResource["dojox.sketch.UndoStack"]=true;
10
dojo.provide("dojox.sketch.UndoStack");
11
dojo.require("dojox.xml.DomParser");
12
(function(){
13
var ta=dojox.sketch;
14
ta.CommandTypes={Create:"Create",Move:"Move",Modify:"Modify",Delete:"Delete",Convert:"Convert"};
15
dojo.declare("dojox.sketch.UndoStack",null,{constructor:function(_1){
16
this.figure=_1;
17
this._steps=[];
18
this._undoedSteps=[];
19
},apply:function(_2,_3,to){
20
if(!_3&&!to&&_2.fullText){
21
this.figure.setValue(_2.fullText);
22
return;
23
}
24
var _4=_3.shapeText;
25
var _5=to.shapeText;
26
if(_4.length==0&&_5.length==0){
27
return;
28
}
29
if(_4.length==0){
30
var o=dojox.xml.DomParser.parse(_5).documentElement;
31
var a=this.figure._loadAnnotation(o);
32
if(a){
33
this.figure._add(a);
34
}
35
return;
36
}
37
if(_5.length==0){
38
var _6=this.figure.getAnnotator(_3.shapeId);
39
this.figure._delete([_6],true);
40
return;
41
}
42
var _7=this.figure.getAnnotator(to.shapeId);
43
var no=dojox.xml.DomParser.parse(_5).documentElement;
44
_7.draw(no);
45
this.figure.select(_7);
46
return;
47
},add:function(_8,_9,_a){
48
var id=_9?_9.id:"";
49
var _b=_9?_9.serialize():"";
50
if(_8==ta.CommandTypes.Delete){
51
_b="";
52
}
53
var _c={cmdname:_8,before:{shapeId:id,shapeText:_a||""},after:{shapeId:id,shapeText:_b}};
54
this._steps.push(_c);
55
this._undoedSteps=[];
56
},destroy:function(){
57
},undo:function(){
58
var _d=this._steps.pop();
59
if(_d){
60
this._undoedSteps.push(_d);
61
this.apply(_d,_d.after,_d.before);
62
}
63
},redo:function(){
64
var _e=this._undoedSteps.pop();
65
if(_e){
66
this._steps.push(_e);
67
this.apply(_e,_e.before,_e.after);
68
}
69
}});
70
})();
71
}