Commit 5e7f597e authored by Akikonata's avatar Akikonata

remove focus

parent e10988fa
KityMinder.registerModule( "KeyboardModule", function () {
KityMinder.registerModule("KeyboardModule", function () {
var min = Math.min,
max = Math.max,
abs = Math.abs,
sqrt = Math.sqrt,
exp = Math.exp;
function buildPositionNetwork( root ) {
function buildPositionNetwork(root) {
var pointIndexes = [],
p;
root.traverse( function ( node ) {
p = node.getRenderContainer().getRenderBox( 'top' );
root.traverse(function (node) {
p = node.getRenderContainer().getRenderBox('top');
// bugfix: 不应导航到收起的节点(判断其尺寸是否存在)
if ( p.width && p.height ) {
pointIndexes.push( {
if (p.width && p.height) {
pointIndexes.push({
left: p.x,
top: p.y,
right: p.x + p.width,
......@@ -22,30 +22,30 @@ KityMinder.registerModule( "KeyboardModule", function () {
height: p.height,
node: node,
text: node.getText()
} );
});
}
} );
for ( var i = 0; i < pointIndexes.length; i++ ) {
findClosestPointsFor( pointIndexes, i );
});
for (var i = 0; i < pointIndexes.length; i++) {
findClosestPointsFor(pointIndexes, i);
}
}
// 这是金泉的点子,赞!
// 求两个不相交矩形的最近距离
function getCoefedDistance( box1, box2 ) {
function getCoefedDistance(box1, box2) {
var xMin, xMax, yMin, yMax, xDist, yDist, dist, cx, cy;
xMin = min( box1.left, box2.left );
xMax = max( box1.right, box2.right );
yMin = min( box1.top, box2.top );
yMax = max( box1.bottom, box2.bottom );
xMin = min(box1.left, box2.left);
xMax = max(box1.right, box2.right);
yMin = min(box1.top, box2.top);
yMax = max(box1.bottom, box2.bottom);
xDist = xMax - xMin - box1.width - box2.width;
yDist = yMax - yMin - box1.height - box2.height;
if ( xDist < 0 ) dist = yDist;
else if ( yDist < 0 ) dist = xDist;
else dist = sqrt( xDist * xDist + yDist * yDist );
if (xDist < 0) dist = yDist;
else if (yDist < 0) dist = xDist;
else dist = sqrt(xDist * xDist + yDist * yDist);
return {
cx: dist,
......@@ -53,21 +53,22 @@ KityMinder.registerModule( "KeyboardModule", function () {
};
}
function findClosestPointsFor( pointIndexes, iFind ) {
var find = pointIndexes[ iFind ];
var most = {}, quad;
function findClosestPointsFor(pointIndexes, iFind) {
var find = pointIndexes[iFind];
var most = {},
quad;
var current, dist;
for ( var i = 0; i < pointIndexes.length; i++ ) {
for (var i = 0; i < pointIndexes.length; i++) {
if ( i == iFind ) continue;
current = pointIndexes[ i ];
if (i == iFind) continue;
current = pointIndexes[i];
dist = getCoefedDistance( current, find );
dist = getCoefedDistance(current, find);
// left check
if ( current.right < find.left ) {
if ( !most.left || dist.cx < most.left.dist ) {
if (current.right < find.left) {
if (!most.left || dist.cx < most.left.dist) {
most.left = {
dist: dist.cx,
node: current.node
......@@ -76,8 +77,8 @@ KityMinder.registerModule( "KeyboardModule", function () {
}
// right check
if ( current.left > find.right ) {
if ( !most.right || dist.cx < most.right.dist ) {
if (current.left > find.right) {
if (!most.right || dist.cx < most.right.dist) {
most.right = {
dist: dist.cx,
node: current.node
......@@ -86,8 +87,8 @@ KityMinder.registerModule( "KeyboardModule", function () {
}
// top check
if ( current.bottom < find.top ) {
if ( !most.top || dist.cy < most.top.dist ) {
if (current.bottom < find.top) {
if (!most.top || dist.cy < most.top.dist) {
most.top = {
dist: dist.cy,
node: current.node
......@@ -96,8 +97,8 @@ KityMinder.registerModule( "KeyboardModule", function () {
}
// bottom check
if ( current.top > find.bottom ) {
if ( !most.down || dist.cy < most.down.dist ) {
if (current.top > find.bottom) {
if (!most.down || dist.cy < most.down.dist) {
most.down = {
dist: dist.cy,
node: current.node
......@@ -114,63 +115,63 @@ KityMinder.registerModule( "KeyboardModule", function () {
}
function navigateTo( km, direction ) {
function navigateTo(km, direction) {
var referNode = km.getSelectedNode();
if ( !referNode ) {
km.select( km.getRoot() );
buildPositionNetwork( km.getRoot() );
if (!referNode) {
km.select(km.getRoot());
buildPositionNetwork(km.getRoot());
return;
}
var nextNode = referNode._nearestNodes[ direction ];
if ( nextNode ) {
km.select( nextNode, true );
var nextNode = referNode._nearestNodes[direction];
if (nextNode) {
km.select(nextNode, true);
}
}
return {
"events": {
contentchange: function () {
buildPositionNetwork( this.getRoot() );
buildPositionNetwork(this.getRoot());
},
"normal.keydown": function ( e ) {
"normal.keydown": function (e) {
var keys = KityMinder.keymap;
var node = e.getTargetNode();
this.receiver.keydownNode = node;
switch ( e.originEvent.keyCode ) {
switch (e.originEvent.keyCode) {
case keys.Enter:
this.execCommand( 'appendSiblingNode', new MinderNode( this.getLang().topic ), true );
this.execCommand('appendSiblingNode', new MinderNode(this.getLang().topic));
e.preventDefault();
break;
case keys.Tab:
this.execCommand( 'appendChildNode', new MinderNode( this.getLang().topic ), true );
this.execCommand('appendChildNode', new MinderNode(this.getLang().topic));
e.preventDefault();
break;
case keys.Backspace:
case keys.Del:
e.preventDefault();
this.execCommand( 'removenode' );
this.execCommand('removenode');
break;
case keys.F2:
e.preventDefault();
this.execCommand( 'editnode' );
this.execCommand('editnode');
break;
case keys.Left:
navigateTo( this, 'left' );
navigateTo(this, 'left');
e.preventDefault();
break;
case keys.Up:
navigateTo( this, 'top' );
navigateTo(this, 'top');
e.preventDefault();
break;
case keys.Right:
navigateTo( this, 'right' );
navigateTo(this, 'right');
e.preventDefault();
break;
case keys.Down:
navigateTo( this, 'down' );
navigateTo(this, 'down');
e.preventDefault();
break;
}
......@@ -178,4 +179,4 @@ KityMinder.registerModule( "KeyboardModule", function () {
}
}
};
} );
\ No newline at end of file
});
\ No newline at end of file
......@@ -428,10 +428,12 @@ KityMinder.registerModule("LayoutBottom", function () {
node: _root
}, false));
updateShapeByCont(_root);
// updateLayoutAll(_root);
updateLayoutAll(_root);
translateNode(_root);
// var _buffer = [_root];
// var _cleanbuffer = [];
var _buffer = [_root];
var _cleanbuffer = [];
//打散结构
// while (_buffer.length !== 0) {
// var children = _buffer[0].getChildren();
......@@ -448,15 +450,18 @@ KityMinder.registerModule("LayoutBottom", function () {
// this.appendChildNode(_cleanbuffer[j].getLayout().parent, _cleanbuffer[j]);
// }
},
appendChildNode: function (parent, node, focus, sibling) {
appendChildNode: function (parent, node, sibling) {
minder.handelNodeInsert(node);
node.clearLayout();
var parentLayout = parent.getLayout();
var expand = parent.getData("expand");
node.getContRc().clear();
var Layout = node.getLayout();
Layout = node.getLayout();
Layout.added = true;
initLayout(node);
//设置分支类型
if (parent.getType() === "root") {
node.setType("main");
node.setData("expand", true);
minder.handelNodeInsert(node);
} else {
node.setType("sub");
//将节点加入到main分支的subgroup中
......@@ -469,9 +474,6 @@ KityMinder.registerModule("LayoutBottom", function () {
parent.appendChild(node);
}
//计算位置等流程
updateBg(node);
initLayout(node);
node.getRenderContainer().clear();
this._firePharse(new MinderEvent("RenderNodeLeft", {
node: node
}, false));
......@@ -487,19 +489,23 @@ KityMinder.registerModule("LayoutBottom", function () {
this._firePharse(new MinderEvent("RenderNodeTop", {
node: node
}, false));
this._firePharse(new MinderEvent("RenderNode", {
node: node
}, false));
updateBg(node);
updateShapeByCont(node);
var set = updateLayoutAll(node, parent, "append");
for (var i = 0; i < set.length; i++) {
translateNode(set [i]);
updateConnectAndshIcon(set [i]);
}
if (node.getType() === "sub") {
var set1 = updateLayoutMain();
for (var j = 0; j < set1.length; j++) {
translateNode(set1[j]);
updateConnectAndshIcon(set1[j]);
}
}
// var set = updateLayoutAll(node, parent, "append");
// for (var i = 0; i < set.length; i++) {
// translateNode(set [i]);
// updateConnectAndshIcon(set [i]);
// }
// if (node.getType() === "sub") {
// var set1 = updateLayoutMain();
// for (var j = 0; j < set1.length; j++) {
// translateNode(set1[j]);
// updateConnectAndshIcon(set1[j]);
// }
// }
},
appendSiblingNode: function (sibling, node) {
var parent = sibling.getParent();
......
......@@ -591,11 +591,11 @@ KityMinder.registerModule("LayoutDefault", function () {
}
}
},
appendChildNode: function (parent, node, focus, sibling) {
appendChildNode: function (parent, node, sibling) {
minder.handelNodeInsert(node);
var Layout = node.getLayout();
node.clearLayout();
node.getContRc().clear();
var Layout = node.getLayout();
Layout = node.getLayout();
Layout.added = true;
var parentLayout = parent.getLayout();
......@@ -694,16 +694,13 @@ KityMinder.registerModule("LayoutDefault", function () {
updateConnectAndshIcon(set [i]);
}
// if ( focus ) {
// showNodeInView( node );
// }
parent.expand();
var shicon = parent.getLayout().shicon;
if (shicon) shicon.switchState(true);
},
appendSiblingNode: function (sibling, node, focus) {
appendSiblingNode: function (sibling, node) {
var parent = sibling.getParent();
this.appendChildNode(parent, node, focus, sibling);
this.appendChildNode(parent, node, sibling);
},
removeNode: function (nodes) {
nodes = utils.isArray(nodes) ? nodes : [nodes];
......
......@@ -55,13 +55,13 @@ KityMinder.registerModule("LayoutModule", function () {
this.getLayoutStyle(curStyle).initStyle.call(this);
this.fire('afterinitstyle');
},
appendChildNode: function (parent, node, focus, index) {
appendChildNode: function (parent, node, index) {
var curStyle = this.getCurrentStyle();
this.getLayoutStyle(curStyle).appendChildNode.call(this, parent, node, focus, index);
this.getLayoutStyle(curStyle).appendChildNode.call(this, parent, node, index);
},
appendSiblingNode: function (sibling, node, focus) {
appendSiblingNode: function (sibling, node) {
var curStyle = this.getCurrentStyle();
this.getLayoutStyle(curStyle).appendSiblingNode.call(this, sibling, node, focus);
this.getLayoutStyle(curStyle).appendSiblingNode.call(this, sibling, node);
},
removeNode: function (nodes) {
var curStyle = this.getCurrentStyle();
......@@ -119,7 +119,7 @@ KityMinder.registerModule("LayoutModule", function () {
var AppendChildNodeCommand = kity.createClass("AppendChildNodeCommand", (function () {
return {
base: Command,
execute: function (km, node, focus, silbling) {
execute: function (km, node, silbling) {
var parent = km.getSelectedNode();
if (!parent) {
......@@ -129,7 +129,7 @@ KityMinder.registerModule("LayoutModule", function () {
km.expandNode(parent);
}
parent.expand();
km.appendChildNode(parent, node, focus, silbling);
km.appendChildNode(parent, node, silbling);
km.select(node, true);
return node;
},
......@@ -146,7 +146,7 @@ KityMinder.registerModule("LayoutModule", function () {
var AppendSiblingNodeCommand = kity.createClass("AppendSiblingNodeCommand", (function () {
return {
base: Command,
execute: function (km, node, focus) {
execute: function (km, node) {
var selectedNode = km.getSelectedNode();
if (!selectedNode) {
return null;
......@@ -154,9 +154,9 @@ KityMinder.registerModule("LayoutModule", function () {
if (selectedNode.isRoot()) {
node.setType("main");
km.appendChildNode(selectedNode, node, focus);
km.appendChildNode(selectedNode, node);
} else {
km.appendSiblingNode(selectedNode, node, focus);
km.appendSiblingNode(selectedNode, node);
}
km.select(node, true);
return node;
......
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