Commit 7c7ac886 authored by Akikonata's avatar Akikonata

added node delete

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