Commit a87ee4c9 authored by Akikonata's avatar Akikonata

test

parent fefd5329
......@@ -23,8 +23,6 @@
minder.execCommand("appendsiblingnode",new MinderNode("test4"));
minder.execCommand("appendchildnode",new MinderNode("test5"));
minder.execCommand("appendsiblingnode",new MinderNode("test6"));
minder.execCommand("appendchildnode",new MinderNode("test7"));
minder.execCommand("appendsiblingnode",new MinderNode("test8"));
//minder.execCommand("switchlayout","green");
</script>
</html>
\ No newline at end of file
KityMinder.registerModule( "HistoryModule", function () {
var Scene = kity.createClass('Scene',{
constructor:function(root){
var Scene = kity.createClass( 'Scene', {
constructor: function ( root ) {
this.data = root.clone();
},
getData:function(){
getData: function () {
return this.data;
},
cloneData:function(){
cloneData: function () {
return this.getData().clone();
},
equals:function(scene){
return this.getData().equals(scene.getData())
equals: function ( scene ) {
return this.getData().equals( scene.getData() )
}
});
var HistoryManager = kity.createClass('HistoryManager',{
constructor : function(km){
} );
var HistoryManager = kity.createClass( 'HistoryManager', {
constructor: function ( km ) {
this.list = [];
this.index = 0;
this.hasUndo = false;
this.hasRedo = false;
this.km = km;
},
undo:function(){
if (this.hasUndo) {
if (!this.list[this.index - 1] && this.list.length == 1) {
undo: function () {
if ( this.hasUndo ) {
if ( !this.list[ this.index - 1 ] && this.list.length == 1 ) {
this.reset();
return;
}
while (this.list[this.index].equals(this.list[this.index - 1])) {
while ( this.list[ this.index ].equals( this.list[ this.index - 1 ] ) ) {
this.index--;
if (this.index == 0) {
return this.restore(0);
if ( this.index == 0 ) {
return this.restore( 0 );
}
}
this.restore(--this.index);
this.restore( --this.index );
}
},
redo:function(){
if (this.hasRedo) {
while (this.list[this.index].equals(this.list[this.index + 1])) {
redo: function () {
if ( this.hasRedo ) {
while ( this.list[ this.index ].equals( this.list[ this.index + 1 ] ) ) {
this.index++;
if (this.index == this.list.length - 1) {
return this.restore(this.index);
if ( this.index == this.list.length - 1 ) {
return this.restore( this.index );
}
}
this.restore(++this.index);
this.restore( ++this.index );
}
},
restore:function(){
var scene = this.list[this.index];
this.km.setRoot(scene.cloneData());
restore: function () {
var scene = this.list[ this.index ];
this.km.setRoot( scene.cloneData() );
this.km.initStyle();
this.update();
},
getScene:function(){
return new Scene(this.km.getRoot())
getScene: function () {
return new Scene( this.km.getRoot() )
},
saveScene:function(){
saveScene: function () {
var currentScene = this.getScene();
var lastScene = this.list[this.index];
if(lastScene && lastScene.equals(currentScene)){
var lastScene = this.list[ this.index ];
if ( lastScene && lastScene.equals( currentScene ) ) {
return
}
this.list = this.list.slice(0, this.index + 1);
this.list.push(currentScene);
this.list = this.list.slice( 0, this.index + 1 );
this.list.push( currentScene );
//如果大于最大数量了,就把最前的剔除
if (this.list.length > this.km.getOptions('maxUndoCount')) {
if ( this.list.length > this.km.getOptions( 'maxUndoCount' ) ) {
this.list.shift();
}
this.index = this.list.length - 1;
//跟新undo/redo状态
this.update();
},
update : function () {
this.hasRedo = !!this.list[this.index + 1];
this.hasUndo = !!this.list[this.index - 1];
update: function () {
this.hasRedo = !! this.list[ this.index + 1 ];
this.hasUndo = !! this.list[ this.index - 1 ];
},
reset:function(){
reset: function () {
this.list = [];
this.index = 0;
this.hasUndo = false;
this.hasRedo = false;
}
});
} );
//为km实例添加history管理
this.historyManager = new HistoryManager(this);
this.historyManager = new HistoryManager( this );
return {
defaultOptions:{
maxUndoCount : 20
defaultOptions: {
maxUndoCount: 20
},
"commands": {
"undo": kity.createClass( "UndoCommand", {
......@@ -103,7 +103,7 @@ KityMinder.registerModule( "HistoryModule", function () {
queryState: function ( km ) {
km.historyManager.hasUndo ? 0 : -1;
},
isNeedUndo : true
isNeedUndo: true
} ),
"redo": kity.createClass( "RedoCommand", {
base: Command,
......@@ -115,7 +115,7 @@ KityMinder.registerModule( "HistoryModule", function () {
queryState: function ( km ) {
return km.historyManager.hasRedo ? 0 : -1;
},
isNeedUndo : true
isNeedUndo: true
} )
},
......
......@@ -369,8 +369,12 @@ KityMinder.registerModule( "LayoutDefault", function () {
drawNode( node );
},
initStyle: function () {
var _root = this.getRoot();
//清空节点上附加的数据;
var minder = this;
var _root = minder.getRoot();
_root.preTraverse( function ( node ) {
node.clearLayout();
} );
var Layout = _root.getData( "layout" );
Layout.style = {
radius: 10,
......@@ -396,14 +400,14 @@ KityMinder.registerModule( "LayoutDefault", function () {
translateNode( _root );
//如果是从其他style切过来的,需要重新布局
var _buffer = _root.getChildren();
while ( _buffer.length !== 0 ) {
_buffer = _buffer.concat( _buffer[ 0 ].getChildren() );
var prt = _buffer[ 0 ].getParent();
_buffer[ 0 ].children = [];
this.appendChildNode( prt, _buffer[ 0 ] );
_buffer.shift();
}
// var _buffer = _root.getChildren();
// while ( _buffer.length !== 0 ) {
// _buffer = _buffer.concat( _buffer[ 0 ].getChildren() );
// var prt = _buffer[ 0 ].getParent();
// _buffer[ 0 ].children = [];
// this.appendChildNode( prt, _buffer[ 0 ] );
// _buffer.shift();
// }
},
appendChildNode: function ( parent, node, index ) {
if ( !node.getData( "layout" ) ) node.setData( "layout", {} );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment