Commit 5e7f597e authored by Akikonata's avatar Akikonata

remove focus

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