Commit a87ee4c9 authored by Akikonata's avatar Akikonata

test

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