Commit 7c7ac886 authored by Akikonata's avatar Akikonata

added node delete

parent fb4cc971
...@@ -17,11 +17,12 @@ ...@@ -17,11 +17,12 @@
<script> <script>
minder = KM.createMinder(kityminder); minder = KM.createMinder(kityminder);
// minder.execCommand("appendchildnode",new MinderNode('dsf')); minder.execCommand("appendchildnode",new MinderNode('dsf'));
// minder.execCommand("appendsiblingnode",new MinderNode('sdf')); minder.execCommand("appendsiblingnode",new MinderNode('sdf'));
// minder.execCommand("appendchildnode",new MinderNode('sdf')); minder.execCommand("appendchildnode",new MinderNode('sdf'));
// minder.execCommand("appendsiblingnode",new MinderNode('df')); minder.execCommand("appendsiblingnode",new MinderNode('df'));
// minder.execCommand("appendsiblingnode",new MinderNode('sdfsdf')); var del = new MinderNode('sdfsdf');
minder.execCommand("appendsiblingnode",del);
minder.execCommand("removenode",del);
</script> </script>
</html> </html>
\ No newline at end of file
...@@ -378,24 +378,12 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -378,24 +378,12 @@ KityMinder.registerModule( "LayoutDefault", function () {
updateArrangement( _root ); updateArrangement( _root );
//如果是从其他style切过来的,需要重新布局 //如果是从其他style切过来的,需要重新布局
if ( children.length !== 0 ) { var _buffer = _root.getChildren();
_root.setData( "leftList", [] ); while ( _buffer.length !== 0 ) {
_root.setData( "rightList", [] ); _buffer = _buffer.concat( _buffer[ 0 ].getChildren() );
var leftList = _root.getData( "leftList" ); var parent = _buffer[ 0 ].getParent();
var rightList = _root.getData( "rightList" ); this.appendChildNode( parent, _buffer[ 0 ] );
for ( var i = 0; i < children.length; i++ ) { _buffer.shift();
if ( i % 2 === 0 ) {
rightList.push( children[ i ] );
children[ i ].setData( "appendside", "right" );
} else {
leftList.push( children[ i ] );
children[ i ].setData( "appendside", "left" );
}
children[ i ].getRenderContainer().clear();
children.setData( "shape", null );
drawNode( children[ i ] );
updateArrangement( children[ i ] );
}
} }
}, },
appendChildNode: function ( parent, node, index ) { appendChildNode: function ( parent, node, index ) {
...@@ -436,13 +424,15 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -436,13 +424,15 @@ KityMinder.registerModule( "LayoutDefault", function () {
}, },
removeNode: function ( nodes ) { removeNode: function ( nodes ) {
var root = this.getRoot(); var root = this.getRoot();
var minder = this;
for ( var i = 0; i < nodes.length; i++ ) { for ( var i = 0; i < nodes.length; i++ ) {
var parent = nodes[ i ].getParent(); var parent = nodes[ i ].getParent();
if ( parent ) { if ( parent ) {
nodes[ i ].getRenderContainer().remove();
updateConnect( minder, nodes[ i ], "remove" );
parent.removeChild( nodes[ i ] ); parent.removeChild( nodes[ i ] );
} }
} }
this.setContentChanged( true );
} }
}; };
this.addLayoutStyle( "default", _style ); this.addLayoutStyle( "default", _style );
......
...@@ -349,6 +349,7 @@ KityMinder.registerModule( "LayoutGreen", function () { ...@@ -349,6 +349,7 @@ KityMinder.registerModule( "LayoutGreen", function () {
}, },
initStyle: function () { initStyle: function () {
var _root = this.getRoot(); var _root = this.getRoot();
console.log( _root );
var minder = this; var minder = this;
_root.setData( "style", { _root.setData( "style", {
radius: 10, radius: 10,
...@@ -366,7 +367,6 @@ KityMinder.registerModule( "LayoutGreen", function () { ...@@ -366,7 +367,6 @@ KityMinder.registerModule( "LayoutGreen", function () {
_root.setData( "text", "I am the root" ); _root.setData( "text", "I am the root" );
_root.setData( "appendside", "right" ); _root.setData( "appendside", "right" );
var children = _root.getChildren();
_root.setData( "leftList", [] ); _root.setData( "leftList", [] );
_root.setData( "rightList", [] ); _root.setData( "rightList", [] );
...@@ -378,25 +378,16 @@ KityMinder.registerModule( "LayoutGreen", function () { ...@@ -378,25 +378,16 @@ KityMinder.registerModule( "LayoutGreen", function () {
updateArrangement( _root ); updateArrangement( _root );
//如果是从其他style切过来的,需要重新布局 //如果是从其他style切过来的,需要重新布局
if ( children.length !== 0 ) { var _buffer = _root.getChildren();
_root.setData( "leftList", [] ); while ( _buffer.length !== 0 ) {
_root.setData( "rightList", [] ); _buffer = _buffer.concat( _buffer[ 0 ].getChildren() );
var leftList = _root.getData( "leftList" ); var parent = _buffer[ 0 ].getParent();
var rightList = _root.getData( "rightList" ); this.appendChildNode( parent, _buffer[ 0 ] );
for ( var i = 0; i < children.length; i++ ) { _buffer.shift();
if ( i % 2 === 0 ) {
rightList.push( children[ i ] );
children[ i ].setData( "appendside", "right" );
} else {
leftList.push( children[ i ] );
children[ i ].setData( "appendside", "left" );
}
drawNode( children[ i ] );
updateArrangement( children[ i ] );
}
} }
}, },
appendChildNode: function ( parent, node, index ) { appendChildNode: function ( parent, node, index ) {
var minder = this;
var appendside = parent.getData( "appendside" ); var appendside = parent.getData( "appendside" );
if ( parent === root ) { if ( parent === root ) {
var leftList = parent.getData( "leftList" ); var leftList = parent.getData( "leftList" );
...@@ -417,7 +408,10 @@ KityMinder.registerModule( "LayoutGreen", function () { ...@@ -417,7 +408,10 @@ KityMinder.registerModule( "LayoutGreen", function () {
} else { } else {
node.setData( "align", "left" ); node.setData( "align", "left" );
} }
if ( parent.getChildren().indexOf( node ) === -1 ) parent.appendChild( node, index ); if ( parent.getChildren().indexOf( node ) === -1 ) {
parent.appendChild( node, index );
minder.handelNodeInsert( node );
}
drawNode( node ); drawNode( node );
updateArrangement( node, "append" ); updateArrangement( node, "append" );
}, },
......
...@@ -40,11 +40,11 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -40,11 +40,11 @@ KityMinder.registerModule( "LayoutModule", function () {
execute: function ( km, node ) { execute: function ( km, node ) {
//km.select( node ); //km.select( node );
var selectedNode = km.getSelectedNode(); var selectedNode = km.getSelectedNode();
if(selectedNode.isRoot()){ if ( selectedNode.isRoot() ) {
km.appendChildNode( selectedNode, node ); km.appendChildNode( selectedNode, node );
}else{ } else {
km.appendSiblingNode( selectedNode, node ); km.appendSiblingNode( selectedNode, node );
} }
km.select( node ); km.select( node );
return node; return node;
} }
...@@ -53,8 +53,9 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -53,8 +53,9 @@ KityMinder.registerModule( "LayoutModule", function () {
var RemoveNodeCommand = kity.createClass( "RemoveNodeCommand", ( function () { var RemoveNodeCommand = kity.createClass( "RemoveNodeCommand", ( function () {
return { return {
base: Command, base: Command,
execute: function ( km, nodes ) { execute: function ( km ) {
km.removeNode( nodes ); var selectedNodes = km.getSelectedNodes();
km.removeNode( selectedNodes );
} }
}; };
} )() ); } )() );
......
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