Commit bc465b0b authored by techird's avatar techird

dev

parent ea53ce0d
......@@ -12,6 +12,16 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
return this.parent;
},
getDepth: function () {
var depth = 0,
p = this.parent;
while ( p ) {
p = p.parent;
depth++;
}
return depth;
},
getRoot: function () {
var root = this;
while ( root.parent ) {
......@@ -45,7 +55,7 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
},
getIndex: function () {
return this.parent ? this.parent.indexOf( this ) : -1;
return this.parent ? this.parent.children.indexOf( this ) : -1;
},
insertChild: function ( node, index ) {
......
......@@ -136,6 +136,7 @@ var ConnectModule = KityMinder.registerModule( "ConnectModule", function () {
"events": {
"command": function ( e ) {
var command = e;
var minder = this;
switch ( command.commandName ) {
case "rendernode":
( function () {
......@@ -165,13 +166,24 @@ var ConnectModule = KityMinder.registerModule( "ConnectModule", function () {
break;
case "removenode":
( function () {
var node = command.commandArgs[ 0 ];
node.getData( "connect" ).remove();
var nodes = command.commandArgs[ 0 ];
if ( ( nodes instanceof Array ) === false ) {
nodes = [ nodes ];
}
function removeConnect( node ) {
var connect = node.getData( "connect" );
if ( connect && connect.remove ) {
connect.remove();
}
}
for ( var i = 0; i < nodes.length; i++ ) {
nodes[ i ].traverse( removeConnect );
}
} )();
default:
break;
};
}
}
}
};
} );
\ No newline at end of file
......@@ -46,6 +46,20 @@ KityMinder.registerModule( "KeyboardModule", function () {
} );
}
function findMinDepthNode( nodes ) {
var depth,
minDepth = Number.MAX_VALUE,
minDepthNode = null;
for ( var i = 0; i < nodes.length; i++ ) {
depth = nodes[ i ].getDepth();
if ( depth < minDepth ) {
minDepth = depth;
minDepthNode = nodes[ i ];
}
}
return minDepthNode;
}
var KBCreateAndEditCommand = kity.createClass( {
base: Command,
execute: function ( km, type, referNode ) {
......@@ -73,11 +87,37 @@ KityMinder.registerModule( "KeyboardModule", function () {
}
} );
var KBRemoveCommand = kity.createClass( {
base: Command,
execute: function ( km, nodes ) {
km.clearSelect( nodes );
var select = this.getNextSelection( km, nodes );
km.execCommand( 'removeNode', nodes );
km.select( select );
km.execCommand( 'rendernode', select );
},
getNextSelection: function ( km, removeNodes ) {
var minDepthNode = findMinDepthNode( removeNodes );
var parent = minDepthNode.getParent();
if ( !parent ) {
return km.getRoot();
}
var length = parent.getChildren().length;
if ( length > 1 ) {
var index = minDepthNode.getIndex() + 1;
return parent.getChild( index % length );
} else {
return parent;
}
}
} );
return {
// private usage
"commands": {
'kbCreateAndEdit': KBCreateAndEditCommand,
'kbNavigate': KBNavigateCommand
'kbNavigate': KBNavigateCommand,
'kbRemove': KBRemoveCommand
},
"events": {
contentchange: function () {
......@@ -108,10 +148,11 @@ KityMinder.registerModule( "KeyboardModule", function () {
this.execCommand( 'kbCreateAndEdit', 'child', sNodes[ 0 ] );
}
break;
case 8:
case 46:
// Backspace or Delete
this.execCommand( 'removeNode', sNodes );
this.execCommand( 'kbRemove', sNodes );
break;
case 37:
......
......@@ -57,9 +57,14 @@ KityMinder.registerModule( "LayoutModule", function () {
return {
base: Command,
execute: function ( km, node ) {
var parent = node.getParent();
parent.removeChild( node );
execute: function ( km, nodes ) {
for ( var i = 0; i < nodes.length; i++ ) {
var parent = nodes[ i ].getParent();
if ( parent ) {
parent.removeChild( nodes[ i ] );
}
}
this.setContentChanged( true );
}
};
} )() );
......
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