Commit f18e3c89 authored by campaign's avatar campaign

by zhanyi

parent d6b5f112
...@@ -827,6 +827,9 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", { ...@@ -827,6 +827,9 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
this._shortcutkeys = {}; this._shortcutkeys = {};
this._bindshortcutKeys(); this._bindshortcutKeys();
}, },
isTextEditStatus:function(){
return false;
},
addShortcutKeys: function ( cmd, keys ) { addShortcutKeys: function ( cmd, keys ) {
var obj = {},km = this; var obj = {},km = this;
if ( keys ) { if ( keys ) {
...@@ -845,25 +848,50 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", { ...@@ -845,25 +848,50 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
_bindshortcutKeys: function () { _bindshortcutKeys: function () {
var me = this, var me = this,
shortcutkeys = this._shortcutkeys; shortcutkeys = this._shortcutkeys;
me.on( 'keydown', function ( e ) { function checkkey(key,keyCode,e){
switch(key){
case 'ctrl':
case 'cmd':
if(e.ctrlKey || e.metaKey){
return true;
}
break;
case 'alt':
if(e.altKey){
return true
}
break;
case 'shift':
if(e.shiftKey){
return true;
}
}
if(keyCode == keymap[key]){
return true;
}
return false
}
me.on( 'keydown', function ( e ) {
var originEvent = e.originEvent; var originEvent = e.originEvent;
var keyCode = originEvent.keyCode || originEvent.which; var keyCode = originEvent.keyCode || originEvent.which;
for ( var i in shortcutkeys ) { for ( var i in shortcutkeys ) {
var tmp = shortcutkeys[ i ].split( ',' ); var keys = shortcutkeys[ i ].toLowerCase().split('+');
for ( var t = 0, ti; ti = tmp[ t++ ]; ) { var current = 0;
ti = ti.split( ':' ); utils.each(keys,function(i,k){
var key = ti[ 0 ], if(checkkey(k,keyCode,originEvent)){
param = ti[ 1 ]; current++;
if ( /^(ctrl)(\+shift)?\+(\d+)$/.test( key.toLowerCase() ) || /^(\d+)$/.test( key ) ) {
if ( ( ( RegExp.$1 == 'ctrl' ? ( originEvent.ctrlKey || originEvent.metaKey ) : 0 ) && ( RegExp.$2 != "" ? originEvent[ RegExp.$2.slice( 1 ) + "Key" ] : 1 ) && keyCode == RegExp.$3 ) ||
keyCode == RegExp.$1
) {
if ( me.queryCommandState( i, param ) != -1 )
me.execCommand( i, param );
e.preventDefault();
}
} }
});
//todo 暂时通过receiver判断
if(me.isTextEditStatus()){
return;
}
if(current == keys.length){
if ( me.queryCommandState( i ) != -1 )
me.execCommand( i );
originEvent.preventDefault();
break;
} }
} }
...@@ -1322,7 +1350,16 @@ var keymap = KityMinder.keymap = { ...@@ -1322,7 +1350,16 @@ var keymap = KityMinder.keymap = {
'NumLock':144, 'NumLock':144,
'Cmd':91 'Cmd':91,
'=':187,
'-':189,
"b":66,
'i':73,
'z':90,
'y':89
}; };
//添加多语言模块 //添加多语言模块
...@@ -1600,8 +1637,8 @@ KityMinder.registerModule( "HistoryModule", function () { ...@@ -1600,8 +1637,8 @@ KityMinder.registerModule( "HistoryModule", function () {
} ) } )
}, },
addShortcutKeys: { addShortcutKeys: {
"Undo": "ctrl+90", //undo "Undo": "ctrl+z", //undo
"Redo": "ctrl+89" //redo "Redo": "ctrl+y" //redo
}, },
"events": { "events": {
"saveScene": function ( e ) { "saveScene": function ( e ) {
...@@ -1769,7 +1806,11 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -1769,7 +1806,11 @@ KityMinder.registerModule( "LayoutModule", function () {
return this._layoutStyles[ name ]; return this._layoutStyles[ name ];
}, },
getLayoutStyleItems: function () { getLayoutStyleItems: function () {
return this._layoutStyles; var items = [];
for ( var key in this._layoutStyles ) {
items.push( key );
}
return items;
}, },
getCurrentStyle: function () { getCurrentStyle: function () {
var _root = this.getRoot(); var _root = this.getRoot();
...@@ -1859,12 +1900,17 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -1859,12 +1900,17 @@ KityMinder.registerModule( "LayoutModule", function () {
base: Command, base: Command,
execute: function ( km, node ) { execute: function ( km, node ) {
var parent = km.getSelectedNode(); var parent = km.getSelectedNode();
if ( !parent ) {
return false;
}
km.appendChildNode( parent, node ); km.appendChildNode( parent, node );
km.select( node, true ); km.select( node, true );
return node; return node;
},
queryState: function ( km ) {
var selectedNode = km.getSelectedNode();
if ( !selectedNode ) {
return -1;
} else {
return 0;
}
} }
}; };
} )() ); } )() );
...@@ -1873,9 +1919,6 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -1873,9 +1919,6 @@ KityMinder.registerModule( "LayoutModule", function () {
base: Command, base: Command,
execute: function ( km, node ) { execute: function ( km, node ) {
var selectedNode = km.getSelectedNode(); var selectedNode = km.getSelectedNode();
if ( !selectedNode ) {
return false;
}
if ( selectedNode.isRoot() ) { if ( selectedNode.isRoot() ) {
node.setType( "main" ); node.setType( "main" );
km.appendChildNode( selectedNode, node ); km.appendChildNode( selectedNode, node );
...@@ -1885,6 +1928,15 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -1885,6 +1928,15 @@ KityMinder.registerModule( "LayoutModule", function () {
} }
km.select( node, true ); km.select( node, true );
return node; return node;
},
queryState: function ( km ) {
var selectedNodes = km.getSelectedNodes();
//没选中节点和单选root的时候返回不可执行
if ( selectedNodes.length === 0 || ( selectedNodes.length === 1 && selectedNodes[ 0 ] === km.getRoot() ) ) {
return -1;
} else {
return 0;
}
} }
}; };
} )() ); } )() );
...@@ -1894,10 +1946,6 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -1894,10 +1946,6 @@ KityMinder.registerModule( "LayoutModule", function () {
execute: function ( km ) { execute: function ( km ) {
var selectedNodes = km.getSelectedNodes(); var selectedNodes = km.getSelectedNodes();
var _root = km.getRoot(); var _root = km.getRoot();
if ( selectedNodes.length === 0 || ( selectedNodes.length === 1 && !selectedNodes[ 0 ].getParent() ) ) {
km.select( _root );
return false;
}
var _buffer = []; var _buffer = [];
for ( var i = 0; i < selectedNodes.length; i++ ) { for ( var i = 0; i < selectedNodes.length; i++ ) {
_buffer.push( selectedNodes[ i ] ); _buffer.push( selectedNodes[ i ] );
...@@ -1909,6 +1957,14 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -1909,6 +1957,14 @@ KityMinder.registerModule( "LayoutModule", function () {
} while ( _buffer.length > 1 ); } while ( _buffer.length > 1 );
km.removeNode( selectedNodes ); km.removeNode( selectedNodes );
km.select( _buffer[ 0 ] ); km.select( _buffer[ 0 ] );
},
queryState: function ( km ) {
var selectedNodes = km.getSelectedNodes();
if ( selectedNodes.length === 0 || ( selectedNodes.length === 1 && selectedNodes[ 0 ] === km.getRoot() ) ) {
return -1;
} else {
return 0;
}
} }
}; };
} )() ); } )() );
...@@ -1942,7 +1998,12 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -1942,7 +1998,12 @@ KityMinder.registerModule( "LayoutModule", function () {
} }
}, },
"defaultOptions": { "defaultOptions": {
"defaultlayoutstyle": "default" "defaultlayoutstyle": "default",
"node": {
'appendsiblingnode': 'appendsiblingnode',
'appendchildnode': 'appendchildnode',
'removenode': 'removenode'
}
} }
}; };
} ); } );
...@@ -2554,7 +2615,6 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -2554,7 +2615,6 @@ KityMinder.registerModule( "LayoutDefault", function () {
var parent = _buffer[ 0 ].getParent(); var parent = _buffer[ 0 ].getParent();
Layout.parent = parent; Layout.parent = parent;
_cleanbuffer.push( _buffer[ 0 ] ); _cleanbuffer.push( _buffer[ 0 ] );
//minder.appendChildNode( parent, _buffer[ 0 ] );
Layout.connect = null; Layout.connect = null;
Layout.shicon = null; Layout.shicon = null;
} else { } else {
...@@ -2603,21 +2663,24 @@ KityMinder.registerModule( "LayoutBottom", function () { ...@@ -2603,21 +2663,24 @@ KityMinder.registerModule( "LayoutBottom", function () {
var iconShape = this.shape = new kity.Group(); var iconShape = this.shape = new kity.Group();
iconShape.class = "shicon"; iconShape.class = "shicon";
iconShape.icon = this; iconShape.icon = this;
var circle = this._circle = new kity.Circle().fill( "white" ).stroke( "gray" ).setRadius( 5 ); var rect = this._rect = new kity.Rect().fill( "white" ).stroke( "gray" ).setRadius( 2 ).setWidth( 10 ).setHeight( 10 );
var plus = this._plus = new kity.Path(); var plus = this._plus = new kity.Path();
plus.getDrawer() plus.getDrawer()
.moveTo( -3, 0 ) .moveTo( 2, 5 )
.lineTo( 3, 0 ) .lineTo( 8, 5 )
.moveTo( 0, -3 ) .moveTo( 5, 2 )
.lineTo( 0, 3 ); .lineTo( 5, 8 );
plus.stroke( "gray" ); plus.stroke( "gray" );
var dec = this._dec = new kity.Path(); var dec = this._dec = new kity.Path();
dec.getDrawer() dec.getDrawer()
.moveTo( -3, 0 ) .moveTo( 2, 5 )
.lineTo( 3, 0 ); .lineTo( 8, 5 );
dec.stroke( "gray" ); dec.stroke( "gray" );
minder.getRenderContainer().addShape( iconShape ); if ( node.getType() === "main" ) minder.getRenderContainer().addShape( iconShape );
iconShape.addShapes( [ circle, plus, dec ] ); else {
node.getLayout().subgroup.addShape( iconShape );
}
iconShape.addShapes( [ rect, plus, dec ] );
this.update(); this.update();
this.switchState(); this.switchState();
}, },
...@@ -2637,12 +2700,9 @@ KityMinder.registerModule( "LayoutBottom", function () { ...@@ -2637,12 +2700,9 @@ KityMinder.registerModule( "LayoutBottom", function () {
var node = this._node; var node = this._node;
var Layout = node.getLayout(); var Layout = node.getLayout();
var nodeShape = node.getRenderContainer(); var nodeShape = node.getRenderContainer();
var nodeX, nodeY = ( node.getType() === "main" ? Layout.y : ( Layout.y + nodeShape.getHeight() / 2 - 5 ) ); var nodeType = node.getType();
if ( Layout.appendside === "left" ) { var nodeX = nodeShape.getRenderBox().closurePoints[ 1 ].x + 5;
nodeX = nodeShape.getRenderBox().closurePoints[ 1 ].x - 6; var nodeY = nodeShape.getRenderBox().closurePoints[ 0 ].y;
} else {
nodeX = nodeShape.getRenderBox().closurePoints[ 0 ].x + 6;
}
this.shape.setTransform( new kity.Matrix().translate( nodeX, nodeY ) ); this.shape.setTransform( new kity.Matrix().translate( nodeX, nodeY ) );
}, },
remove: function () { remove: function () {
...@@ -2650,16 +2710,6 @@ KityMinder.registerModule( "LayoutBottom", function () { ...@@ -2650,16 +2710,6 @@ KityMinder.registerModule( "LayoutBottom", function () {
} }
}; };
} )() ); } )() );
//求并集
var uSet = function ( a, b ) {
for ( var i = 0; i < a.length; i++ ) {
var idx = b.indexOf( a[ i ] );
if ( idx !== -1 ) {
b.splice( idx, 1 );
}
}
return a.concat( b );
};
//样式的配置(包括颜色、字号等) //样式的配置(包括颜色、字号等)
var nodeStyles = { var nodeStyles = {
"root": { "root": {
...@@ -2667,8 +2717,8 @@ KityMinder.registerModule( "LayoutBottom", function () { ...@@ -2667,8 +2717,8 @@ KityMinder.registerModule( "LayoutBottom", function () {
fill: '#e9df98', fill: '#e9df98',
fontSize: 24, fontSize: 24,
padding: [ 15.5, 25.5, 15.5, 25.5 ], padding: [ 15.5, 25.5, 15.5, 25.5 ],
margin: [ 0, 0, 0, 0 ], margin: [ 0, 0, 20, 0 ],
radius: 30, radius: 0,
highlight: 'rgb(254, 219, 0)' highlight: 'rgb(254, 219, 0)'
}, },
"main": { "main": {
...@@ -2677,17 +2727,18 @@ KityMinder.registerModule( "LayoutBottom", function () { ...@@ -2677,17 +2727,18 @@ KityMinder.registerModule( "LayoutBottom", function () {
color: "#333", color: "#333",
padding: [ 6.5, 20, 6.5, 20 ], padding: [ 6.5, 20, 6.5, 20 ],
fontSize: 16, fontSize: 16,
margin: [ 0, 10, 30, 50 ], margin: [ 20, 20, 10, 10 ],
radius: 10, radius: 0,
highlight: 'rgb(254, 219, 0)' highlight: 'rgb(254, 219, 0)'
}, },
"sub": { "sub": {
stroke: new kity.Pen( "white", 2 ).setLineCap( "round" ).setLineJoin( "round" ), stroke: new kity.Pen( "white", 2 ).setLineCap( "round" ).setLineJoin( "round" ),
color: "white", color: "#333",
fontSize: 12, fontSize: 12,
margin: [ 0, 10, 20, 6 ], margin: [ 10, 10, 10, 30 ],
padding: [ 5, 10, 5.5, 10 ], padding: [ 5, 10, 5.5, 10 ],
highlight: 'rgb(254, 219, 0)' highlight: 'rgb(254, 219, 0)',
fill: 'rgb(231, 243, 255)'
} }
}; };
//更新背景 //更新背景
...@@ -2705,9 +2756,9 @@ KityMinder.registerModule( "LayoutBottom", function () { ...@@ -2705,9 +2756,9 @@ KityMinder.registerModule( "LayoutBottom", function () {
Layout.bgShadow.fill( 'black' ).setOpacity( 0.2 ).setRadius( nodeStyle.radius ).translate( 3, 5 ); Layout.bgShadow.fill( 'black' ).setOpacity( 0.2 ).setRadius( nodeStyle.radius ).translate( 3, 5 );
break; break;
case "sub": case "sub":
var underline = Layout.underline = new kity.Path(); var bgRc = node.getBgRc().clear();
var highlightshape = Layout.highlightshape = new kity.Rect().setRadius( 4 ); bgRc.addShape( Layout.bgRect = new kity.Rect() );
node.getBgRc().clear().addShapes( [ Layout.bgRect = new kity.Rect().setRadius( 4 ), highlightshape, underline ] ); Layout.bgRect.fill( nodeStyle.fill );
break; break;
default: default:
break; break;
...@@ -2720,6 +2771,10 @@ KityMinder.registerModule( "LayoutBottom", function () { ...@@ -2720,6 +2771,10 @@ KityMinder.registerModule( "LayoutBottom", function () {
var nodeStyle = nodeStyles[ nodeType ]; var nodeStyle = nodeStyles[ nodeType ];
var txtShape = node.getTextShape(); var txtShape = node.getTextShape();
txtShape.fill( nodeStyle.color ).setSize( nodeStyle.fontSize ).setY( -3 ); txtShape.fill( nodeStyle.color ).setSize( nodeStyle.fontSize ).setY( -3 );
if ( nodeType === "main" ) {
var subgroup = Layout.subgroup = new kity.Group();
minder.getRenderContainer().addShape( subgroup );
}
}; };
//根据内容调整节点尺寸 //根据内容调整节点尺寸
var updateShapeByCont = function ( node ) { var updateShapeByCont = function ( node ) {
...@@ -2738,18 +2793,8 @@ KityMinder.registerModule( "LayoutBottom", function () { ...@@ -2738,18 +2793,8 @@ KityMinder.registerModule( "LayoutBottom", function () {
Layout.bgShadow.setWidth( width ).setHeight( height ); Layout.bgShadow.setWidth( width ).setHeight( height );
break; break;
case "sub": case "sub":
var _contWidth = contRc.getWidth(); width = _contRCWidth + nodeStyle.padding[ 1 ] + nodeStyle.padding[ 3 ];
var _contHeight = contRc.getHeight(); height = _contRCHeight + nodeStyle.padding[ 0 ] + nodeStyle.padding[ 2 ];
width = _contWidth + nodeStyle.padding[ 1 ] + nodeStyle.padding[ 3 ];
height = _contHeight + nodeStyle.padding[ 0 ] + nodeStyle.padding[ 2 ];
Layout.underline.getDrawer()
.clear()
.moveTo( 0, _contHeight + nodeStyle.padding[ 2 ] + nodeStyle.padding[ 0 ] )
.lineTo( _contWidth + nodeStyle.padding[ 1 ] + nodeStyle.padding[ 3 ], _contHeight + nodeStyle.padding[ 2 ] + nodeStyle.padding[ 0 ] );
Layout.underline.stroke( nodeStyle.stroke );
Layout.highlightshape
.setWidth( _contWidth + nodeStyle.padding[ 1 ] + nodeStyle.padding[ 3 ] )
.setHeight( _contHeight + nodeStyle.padding[ 0 ] + nodeStyle.padding[ 2 ] );
Layout.bgRect.setWidth( width ).setHeight( height ); Layout.bgRect.setWidth( width ).setHeight( height );
break; break;
default: default:
...@@ -2757,87 +2802,95 @@ KityMinder.registerModule( "LayoutBottom", function () { ...@@ -2757,87 +2802,95 @@ KityMinder.registerModule( "LayoutBottom", function () {
} }
contRc.setTransform( new kity.Matrix().translate( nodeStyle.padding[ 3 ], nodeStyle.padding[ 0 ] + node.getTextShape().getHeight() ) ); contRc.setTransform( new kity.Matrix().translate( nodeStyle.padding[ 3 ], nodeStyle.padding[ 0 ] + node.getTextShape().getHeight() ) );
}; };
//计算节点在垂直方向的位置 var updateLayoutMain = function () {
var updateLayoutVertical = function ( node ) { var _root = minder.getRoot();
var nodeType = node.getType(); var mainnodes = _root.getChildren();
var parent = node.getParent(); var countMainWidth = function ( node ) {
var effectSet = [ node ]; var nLayout = node.getLayout();
var Layout = node.getLayout(); var selfwidth = node.getRenderContainer().getWidth() + nodeStyles.main.margin[ 1 ] + nodeStyles.main.margin[ 3 ];
var _buffer = [ node ]; var childwidth = nLayout.subgroup.getWidth() + nodeStyles.main.margin[ 1 ] + nodeStyles.sub.margin[ 3 ];
while ( _buffer.length !== 0 ) { var branchwidth = nLayout.branchwidth = ( selfwidth > childwidth ? selfwidth : childwidth );
var prt = _buffer[ 0 ].getParent(); return branchwidth;
_buffer = _buffer.concat( _buffer[ 0 ].getChildren() ); };
if ( !prt ) { var rootLayout = _root.getLayout();
Layout.y = 100; var rootbranchwidth = 0;
_buffer.shift(); for ( var j = 0; j < mainnodes.length; j++ ) {
continue; rootbranchwidth += countMainWidth( mainnodes[ j ] );
}
var parentLayout = prt.getLayout();
var parentHeight = prt.getRenderContainer().getHeight();
var parentStyle = nodeStyles[ prt.getType() ];
var childLayout = _buffer[ 0 ].getLayout();
var childStyle = nodeStyles[ _buffer[ 0 ].getType() ];
childLayout.y = parentLayout.y + parentHeight + parentStyle.margin[ 2 ] + childStyle.margin[ 2 ];
effectSet.push( _buffer[ 0 ] );
_buffer.shift();
} }
return effectSet; var sX = rootLayout.x - rootbranchwidth / 2;
}; for ( var k = 0; k < mainnodes.length; k++ ) {
//计算节点在水平方向的位置 var mLayout = mainnodes[ k ].getLayout();
var updateLayoutHorizon = function ( node, parent, action ) { mLayout.x = sX;
var root = minder.getRoot(); sX += mLayout.branchwidth;
var effectSet = [ node ];
if ( action === "remove" ) {
effectSet = [];
} }
var Layout = node.getLayout(); return mainnodes;
var nodeShape = node.getRenderContainer(); };
var updateLayoutAll = function ( node, parent, action ) {
var effectSet = [];
var nodeType = node.getType(); var nodeType = node.getType();
var nodeStyle = nodeStyles[ nodeType ]; var Layout = node.getLayout();
var countBranchWidth = function ( node ) { var _root = minder.getRoot();
var nodeStyle = nodeStyles[ node.getType() ]; var rootLayout = _root.getLayout();
var selfWidth = node.getRenderContainer().getWidth() + nodeStyle.margin[ 1 ] + nodeStyle.margin[ 3 ];
var childWidth = ( function () {
var sum = 0;
var children = node.getChildren();
for ( var i = 0; i < children.length; i++ ) {
var childLayout = children[ i ].getLayout();
if ( children[ i ].getRenderContainer().getWidth() !== 0 )
sum += childLayout.branchwidth;
}
return sum;
} )();
return ( selfWidth > childWidth ? selfWidth : childWidth );
};
if ( nodeType === "root" ) { if ( nodeType === "root" ) {
Layout.x = getMinderSize().width / 2 - node.getRenderContainer().getWidth() / 2; Layout.x = getMinderSize().width / 2;
Layout.y = 100;
Layout.align = "center";
effectSet.push( node ); effectSet.push( node );
} else { var children = node.getChildren();
for ( var i = 0; i < children.length; i++ ) {
var childLayout = children[ i ].getLayout();
childLayout.y = Layout.y + node.getRenderContainer().getHeight() + nodeStyles.root.margin[ 2 ] + nodeStyles.main.margin[ 0 ];
}
effectSet = effectSet.concat( children );
} else if ( nodeType === "main" ) {
Layout.align = "left";
if ( action === "append" || action === "contract" ) { if ( action === "append" || action === "contract" ) {
Layout.branchwidth = node.getRenderContainer().getWidth() + nodeStyle.margin[ 1 ] + nodeStyle.margin[ 3 ]; Layout.y = rootLayout.y + _root.getRenderContainer().getHeight() + nodeStyles.root.margin[ 2 ] + nodeStyles.main.margin[ 0 ];
} else if ( action === "change" ) {
Layout.branchheight = countBranchWidth( node );
} }
effectSet = updateLayoutMain();
} else {
Layout.align = "left";
var parentLayout = parent.getLayout(); var parentLayout = parent.getLayout();
var parentShape = parent.getRenderContainer(); if ( action === "append" ) {
var prt = node.getParent() || parent; if ( parent.getType() === "main" ) {
//自底向上更新祖先元素的branchwidth值 Layout.x = nodeStyles.sub.margin[ 3 ];
while ( prt ) { } else {
Layout.x = parentLayout.x + nodeStyles.sub.margin[ 3 ];
}
}
if ( action === "append" || action === "contract" ) {
Layout.branchheight = node.getRenderContainer().getHeight() + nodeStyles.sub.margin[ 0 ] + nodeStyles.sub.margin[ 2 ];
}
var prt = parent;
if ( action === "change" ) {
prt = node;
}
//自底向上更新branchheight
while ( prt.getType() !== "main" ) {
var c = prt.getChildren();
var prtLayout = prt.getLayout(); var prtLayout = prt.getLayout();
prtLayout.branchheight = countBranchWidth( prt ); var branchHeight = prt.getRenderContainer().getHeight() + nodeStyles.sub.margin[ 0 ] + nodeStyles.sub.margin[ 2 ];
for ( var i1 = 0; i1 < c.length; i1++ ) {
branchHeight += c[ i1 ].getLayout().branchheight;
}
prtLayout.branchheight = branchHeight;
prt = prt.getParent(); prt = prt.getParent();
} }
//自顶向下更新受影响一侧的y值 //自顶向下更新y
var _buffer = [ root ]; var _buffer = [ prt ];
while ( _buffer.length > 0 ) { while ( _buffer.length !== 0 ) {
var childrenC = _buffer[ 0 ].getChildren();
_buffer = _buffer.concat( childrenC );
var _buffer0Layout = _buffer[ 0 ].getLayout(); var _buffer0Layout = _buffer[ 0 ].getLayout();
var children = _buffer[ 0 ].getChildren(); var _buffer0Style = nodeStyles[ _buffer[ 0 ].getType() ];
_buffer = _buffer.concat( children ); var sY;
var sX = _buffer0Layout.x - _buffer0Layout.branchwidth / 2; if ( _buffer[ 0 ].getType() === "main" ) sY = 0;
for ( var i = 0; i < children.length; i++ ) { else sY = _buffer0Layout.y + _buffer[ 0 ].getRenderContainer().getHeight() + _buffer0Style.margin[ 2 ];
var childLayout = children[ i ].getLayout(); for ( var s = 0; s < childrenC.length; s++ ) {
childLayout.x = sX; var childLayoutC = childrenC[ s ].getLayout();
sX += childLayout.branchwidth; var childStyleC = nodeStyles[ childrenC[ s ].getType() ];
childLayoutC.y = sY + childStyleC.margin[ 0 ];
sY += childLayoutC.branchheight;
} }
effectSet.push( _buffer[ 0 ] ); effectSet.push( _buffer[ 0 ] );
_buffer.shift(); _buffer.shift();
...@@ -2851,7 +2904,20 @@ KityMinder.registerModule( "LayoutBottom", function () { ...@@ -2851,7 +2904,20 @@ KityMinder.registerModule( "LayoutBottom", function () {
var align = Layout.align; var align = Layout.align;
var _rectHeight = nodeShape.getHeight(); var _rectHeight = nodeShape.getHeight();
var _rectWidth = nodeShape.getWidth(); var _rectWidth = nodeShape.getWidth();
nodeShape.setTransform( new kity.Matrix().translate( Layout.x, Layout.y ) ); switch ( align ) {
case "right":
nodeShape.setTransform( new kity.Matrix().translate( Layout.x - _rectWidth, Layout.y ) );
break;
case "center":
nodeShape.setTransform( new kity.Matrix().translate( Layout.x - _rectWidth / 2, Layout.y ) );
break;
default:
nodeShape.setTransform( new kity.Matrix().translate( Layout.x, Layout.y ) );
break;
}
if ( node.getType() === "main" ) {
Layout.subgroup.setTransform( new kity.Matrix().translate( Layout.x, Layout.y + node.getRenderContainer().getHeight() ) );
}
node.setPoint( Layout.x, Layout.y ); node.setPoint( Layout.x, Layout.y );
}; };
var updateConnectAndshIcon = function ( node ) { var updateConnectAndshIcon = function ( node ) {
...@@ -2859,73 +2925,50 @@ KityMinder.registerModule( "LayoutBottom", function () { ...@@ -2859,73 +2925,50 @@ KityMinder.registerModule( "LayoutBottom", function () {
var Layout = node.getLayout(); var Layout = node.getLayout();
var nodeStyle = nodeStyles[ node.getType() ]; var nodeStyle = nodeStyles[ node.getType() ];
var connect; var connect;
var _root = minder.getRoot();
var _rootLayout = _root.getLayout();
//更新连线 //更新连线
if ( nodeType === "main" ) { if ( nodeType === "main" ) {
if ( !Layout.connect ) { if ( !Layout.connect ) {
connect = Layout.connect = new kity.Group(); connect = Layout.connect = new kity.Path();
var bezier = Layout.connect.bezier = new kity.Bezier();
var circle = Layout.connect.circle = new kity.Circle();
connect.addShapes( [ bezier, circle ] );
minder.getRenderContainer().addShape( connect ); minder.getRenderContainer().addShape( connect );
minder.getRoot().getRenderContainer().bringTop();
} }
var parent = minder.getRoot();
var rootX = parent.getLayout().x;
var rootY = parent.getLayout().y;
connect = Layout.connect; connect = Layout.connect;
var nodeShape = node.getRenderContainer(); var sX = _rootLayout.x;
var nodeClosurePoints = nodeShape.getRenderBox().closurePoints; var sY = _rootLayout.y + _root.getRenderContainer().getHeight();
var sPos; var transX = Layout.x + node.getRenderContainer().getWidth() / 2;
var endPos; var transY = sY + nodeStyles.root.margin[ 2 ];
if ( Layout.appendside === "left" ) { connect.getDrawer().clear()
sPos = new kity.BezierPoint( rootX - 30, nodeClosurePoints[ 2 ].y + nodeShape.getHeight() / 2 ); .moveTo( sX, sY )
endPos = new kity.BezierPoint( nodeClosurePoints[ 2 ].x + 3, nodeClosurePoints[ 2 ].y + nodeShape.getHeight() / 2 ); .lineTo( sX, transY )
} else { .lineTo( transX, transY )
sPos = new kity.BezierPoint( rootX + 30, nodeClosurePoints[ 3 ].y + nodeShape.getHeight() / 2 ); .lineTo( transX, Layout.y );
endPos = new kity.BezierPoint( nodeClosurePoints[ 3 ].x - 3, nodeClosurePoints[ 3 ].y + nodeShape.getHeight() / 2 ); connect.stroke( nodeStyles.main.stroke );
}
var sPosV = sPos.getVertex();
var endPosV = endPos.getVertex();
sPos.setVertex( rootX, rootY );
connect.bezier.setPoints( [ sPos, endPos ] ).stroke( nodeStyle.stroke );
connect.circle.setCenter( endPosV.x + ( Layout.appendside === "left" ? 1 : -1.5 ), endPosV.y ).fill( "white" ).setRadius( 4 );
} else if ( nodeType === "sub" ) { } else if ( nodeType === "sub" ) {
var parent = node.getParent();
var parentLayout = parent.getLayout();
if ( !Layout.connect ) { if ( !Layout.connect ) {
connect = Layout.connect = new kity.Path(); connect = Layout.connect = new kity.Path();
minder.getRenderContainer().addShape( connect ); Layout.subgroup.addShape( connect );
} }
connect = Layout.connect; connect = Layout.connect;
var parentShape = node.getParent().getRenderContainer(); var ssX, ssY;
var parentBox = parentShape.getRenderBox(); if ( parent.getType() === "main" ) {
var parentLayout = node.getParent().getLayout(); ssX = 10;
var parentStyle = nodeStyles[ node.getParent().getType() ]; ssY = 0;
var Shape = node.getRenderContainer();
var sX, sY = parentLayout.y;
var nodeX, nodeY = Shape.getRenderBox().closurePoints[ 1 ].y;
if ( Layout.appendside === "left" ) {
sX = parentBox.closurePoints[ 1 ].x - parentStyle.margin[ 1 ];
nodeX = Shape.getRenderBox().closurePoints[ 0 ].x;
connect.getDrawer()
.clear()
.moveTo( sX, sY )
.lineTo( sX, nodeY > sY ? ( nodeY - nodeStyle.margin[ 3 ] ) : ( nodeY + nodeStyle.margin[ 3 ] ) );
if ( nodeY > sY ) connect.getDrawer().carcTo( nodeStyle.margin[ 3 ], nodeX, nodeY, 0, 1 );
else connect.getDrawer().carcTo( nodeStyle.margin[ 3 ], nodeX, nodeY );
connect.stroke( nodeStyle.stroke );
} else { } else {
sX = parentBox.closurePoints[ 0 ].x + parentStyle.margin[ 1 ]; ssX = parentLayout.x + 10;
nodeX = Shape.getRenderBox().closurePoints[ 1 ].x + 1; ssY = parentLayout.y + parent.getRenderContainer().getHeight() + 10;
connect.getDrawer()
.clear()
.moveTo( sX, sY )
.lineTo( sX, nodeY > sY ? ( nodeY - nodeStyle.margin[ 3 ] ) : ( nodeY + nodeStyle.margin[ 3 ] ) );
if ( nodeY > sY ) connect.getDrawer().carcTo( nodeStyle.margin[ 3 ], nodeX, nodeY );
else connect.getDrawer().carcTo( nodeStyle.margin[ 3 ], nodeX, nodeY, 0, 1 );
connect.stroke( nodeStyle.stroke );
} }
var transsY = Layout.y + node.getRenderContainer().getHeight() / 2;
connect.getDrawer().clear()
.moveTo( ssX, ssY )
.lineTo( ssX, transsY )
.lineTo( Layout.x, transsY );
connect.stroke( nodeStyles.sub.stroke );
} }
//更新收放icon //更新收放icon
if ( nodeType !== "root" ) { if ( nodeType !== "root" && node.getChildren().length !== 0 ) {
if ( !Layout.shicon ) { if ( !Layout.shicon ) {
Layout.shicon = new ShIcon( node ); Layout.shicon = new ShIcon( node );
} }
...@@ -2941,21 +2984,13 @@ KityMinder.registerModule( "LayoutBottom", function () { ...@@ -2941,21 +2984,13 @@ KityMinder.registerModule( "LayoutBottom", function () {
switch ( nodeType ) { switch ( nodeType ) {
case "root": case "root":
case "main": case "main":
case "sub":
if ( highlight ) { if ( highlight ) {
Layout.bgRect.fill( nodeStyle.highlight ); Layout.bgRect.fill( nodeStyle.highlight );
} else { } else {
Layout.bgRect.fill( nodeStyle.fill ); Layout.bgRect.fill( nodeStyle.fill );
} }
break; break;
case "sub":
if ( highlight ) {
Layout.highlightshape.fill( nodeStyle.highlight ).setOpacity( 1 );
node.getTextShape().fill( 'black' );
} else {
Layout.highlightshape.setOpacity( 0 );
node.getTextShape().fill( 'white' );
}
break;
default: default:
break; break;
} }
...@@ -2969,13 +3004,18 @@ KityMinder.registerModule( "LayoutBottom", function () { ...@@ -2969,13 +3004,18 @@ KityMinder.registerModule( "LayoutBottom", function () {
}, false ) ); }, false ) );
updateShapeByCont( node ); updateShapeByCont( node );
var set1 = updateLayoutHorizon( node ); var set = updateLayoutAll( node, node.getParent(), "change" );
var set2 = updateLayoutVertical( node, node.getParent(), "change" );
var set = uSet( set1, set2 );
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" ) {
var set1 = updateLayoutMain();
for ( var j = 0; j < set1.length; j++ ) {
translateNode( set1[ j ] );
updateConnectAndshIcon( set1[ j ] );
}
}
}, },
initStyle: function () { initStyle: function () {
var _root = minder.getRoot(); var _root = minder.getRoot();
...@@ -2991,8 +3031,7 @@ KityMinder.registerModule( "LayoutBottom", function () { ...@@ -2991,8 +3031,7 @@ KityMinder.registerModule( "LayoutBottom", function () {
node: _root node: _root
}, false ) ); }, false ) );
updateShapeByCont( _root ); updateShapeByCont( _root );
updateLayoutHorizon( _root ); updateLayoutAll( _root );
updateLayoutVertical( _root );
translateNode( _root ); translateNode( _root );
var _buffer = [ _root ]; var _buffer = [ _root ];
var _cleanbuffer = []; var _cleanbuffer = [];
...@@ -3013,13 +3052,22 @@ KityMinder.registerModule( "LayoutBottom", function () { ...@@ -3013,13 +3052,22 @@ KityMinder.registerModule( "LayoutBottom", function () {
} }
}, },
appendChildNode: function ( parent, node, sibling ) { appendChildNode: function ( parent, node, sibling ) {
minder.handelNodeInsert( node );
node.clearLayout(); node.clearLayout();
var parentLayout = parent.getLayout();
//设置分支类型 //设置分支类型
if ( parent.getType() === "root" ) { if ( parent.getType() === "root" ) {
node.setType( "main" ); node.setType( "main" );
minder.handelNodeInsert( node );
} else { } else {
node.setType( "sub" ); node.setType( "sub" );
//将节点加入到main分支的subgroup中
parentLayout.subgroup.addShape( node.getRenderContainer() );
node.getLayout().subgroup = parentLayout.subgroup;
}
if ( sibling ) {
parent.insertChild( node, sibling.getIndex() + 1 );
} else {
parent.appendChild( node );
} }
//计算位置等流程 //计算位置等流程
updateBg( node ); updateBg( node );
...@@ -3031,22 +3079,92 @@ KityMinder.registerModule( "LayoutBottom", function () { ...@@ -3031,22 +3079,92 @@ KityMinder.registerModule( "LayoutBottom", function () {
node: node node: node
}, false ) ); }, false ) );
updateShapeByCont( node ); updateShapeByCont( node );
var set2 = updateLayoutHorizon( node, parent, "append" ); var set = updateLayoutAll( node, parent, "append" );
var set1 = updateLayoutVertical( node );
var set = uSet( set1, set2 );
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" ) {
var set1 = updateLayoutMain();
for ( var j = 0; j < set1.length; j++ ) {
translateNode( set1[ j ] );
updateConnectAndshIcon( set1[ j ] );
}
}
}, },
appendSiblingNode: function ( sibling, node ) { appendSiblingNode: function ( sibling, node ) {
var parent = sibling.getParent();
this.appendChildNode( parent, node, sibling );
}, },
removeNode: function ( nodes ) { removeNode: function ( nodes ) {
while ( nodes.length !== 0 ) {
var parent = nodes[ 0 ].getParent();
if ( !parent ) {
nodes.splice( 0, 1 );
return false;
}
var nodeLayout = nodes[ 0 ].getLayout();
parent.removeChild( nodes[ 0 ] );
var set = updateLayoutAll( nodes[ 0 ], parent, "remove" );
for ( var j = 0; j < set.length; j++ ) {
translateNode( set[ j ] );
updateConnectAndshIcon( set[ j ] );
}
var _buffer = [ nodes[ 0 ] ];
while ( _buffer.length !== 0 ) {
_buffer = _buffer.concat( _buffer[ 0 ].getChildren() );
try {
_buffer[ 0 ].getRenderContainer().remove();
var Layout = _buffer[ 0 ].getLayout();
Layout.connect.remove();
Layout.shicon.remove();
} catch ( error ) {
console.log( "isRemoved" );
}
//检测当前节点是否在选中的数组中,如果在的话,从选中数组中去除
var idx = nodes.indexOf( _buffer[ 0 ] );
if ( idx !== -1 ) {
nodes.splice( idx, 1 );
}
_buffer.shift();
}
}
}, },
expandNode: function ( ico ) { expandNode: function ( ico ) {
var isExpand = ico.icon.switchState();
var node = ico.icon._node;
var _buffer = node.getChildren();
var _cleanbuffer = [];
while ( _buffer.length !== 0 ) {
var Layout = _buffer[ 0 ].getLayout();
if ( isExpand ) {
var parent = _buffer[ 0 ].getParent();
Layout.parent = parent;
_cleanbuffer.push( _buffer[ 0 ] );
Layout.connect = null;
Layout.shicon = null;
} else {
_buffer[ 0 ].getRenderContainer().remove();
Layout.connect.remove();
if ( Layout.shicon ) Layout.shicon.remove();
}
_buffer = _buffer.concat( _buffer[ 0 ].getChildren() );
_buffer.shift();
}
if ( isExpand ) {
node.clearChildren();
for ( var j = 0; j < _cleanbuffer.length; j++ ) {
_cleanbuffer[ j ].clearChildren();
minder.appendChildNode( _cleanbuffer[ j ].getLayout().parent, _cleanbuffer[ j ] );
}
}
var set = [];
if ( !isExpand ) set = updateLayoutAll( node, node.getParent(), "contract" );
for ( var i = 0; i < set.length; i++ ) {
translateNode( set[ i ] );
updateConnectAndshIcon( set[ i ] );
}
} }
}; };
this.addLayoutStyle( "bottom", _style ); this.addLayoutStyle( "bottom", _style );
...@@ -3791,9 +3909,11 @@ KityMinder.registerModule( "Select", function () { ...@@ -3791,9 +3909,11 @@ KityMinder.registerModule( "Select", function () {
startPosition = g.snapToSharp( e.getPosition() ); startPosition = g.snapToSharp( e.getPosition() );
}, },
selectMove: function ( e ) { selectMove: function ( e ) {
if ( minder.isTextEditStatus() ) {
return;
}
if ( !startPosition ) return; if ( !startPosition ) return;
var p1 = startPosition, var p1 = startPosition,
p2 = e.getPosition(); p2 = e.getPosition();
...@@ -3827,7 +3947,7 @@ KityMinder.registerModule( "Select", function () { ...@@ -3827,7 +3947,7 @@ KityMinder.registerModule( "Select", function () {
// 计算选中范围 // 计算选中范围
minder.getRoot().traverse( function ( node ) { minder.getRoot().traverse( function ( node ) {
var renderBox = node.getRenderContainer().getRenderBox(); var renderBox = node.getRenderContainer().getRenderBox( "top" );
if ( g.isBoxIntersect( renderBox, marquee ) ) { if ( g.isBoxIntersect( renderBox, marquee ) ) {
selectedNodes.push( node ); selectedNodes.push( node );
} }
...@@ -3842,7 +3962,7 @@ KityMinder.registerModule( "Select", function () { ...@@ -3842,7 +3962,7 @@ KityMinder.registerModule( "Select", function () {
} }
if ( marqueeMode ) { if ( marqueeMode ) {
marqueeShape.fadeOut( 200, 'ease', 0, function () { marqueeShape.fadeOut( 200, 'ease', 0, function () {
if(marqueeShape.remove) marqueeShape.remove(); if ( marqueeShape.remove ) marqueeShape.remove();
} ); } );
marqueeMode = false; marqueeMode = false;
} }
...@@ -4039,8 +4159,8 @@ KityMinder.registerModule( "HistoryModule", function () { ...@@ -4039,8 +4159,8 @@ KityMinder.registerModule( "HistoryModule", function () {
} ) } )
}, },
addShortcutKeys: { addShortcutKeys: {
"Undo": "ctrl+90", //undo "Undo": "ctrl+z", //undo
"Redo": "ctrl+89" //redo "Redo": "ctrl+y" //redo
}, },
"events": { "events": {
"saveScene": function ( e ) { "saveScene": function ( e ) {
...@@ -4093,7 +4213,9 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -4093,7 +4213,9 @@ KityMinder.registerModule( "TextEditModule", function () {
var lastEvtPosition,dir = 1; var lastEvtPosition,dir = 1;
km.isTextEditStatus = function(){
return km.receiver.isTextEditStatus();
}
return { return {
//插入光标 //插入光标
...@@ -4108,7 +4230,7 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -4108,7 +4230,7 @@ KityMinder.registerModule( "TextEditModule", function () {
var textShape = node.getTextShape(); var textShape = node.getTextShape();
textShape.setStyle('cursor','default'); textShape.setStyle('cursor','default');
if ( this.isSingleSelect() && node.isSelected() && e.kityEvent.targetShape.getType().toLowerCase()== 'text') { if ( this.isSingleSelect() && node.isSelected()) {// && e.kityEvent.targetShape.getType().toLowerCase()== 'text'
sel.collapse(); sel.collapse();
node.getTextShape().setStyle('cursor','text'); node.getTextShape().setStyle('cursor','text');
...@@ -4138,12 +4260,20 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -4138,12 +4260,20 @@ KityMinder.registerModule( "TextEditModule", function () {
'beforemousemove':function(e){ 'beforemousemove':function(e){
if(mouseDownStatus){ if(mouseDownStatus){
e.stopPropagationImmediately(); e.stopPropagationImmediately();
var offset = e.getPosition(); var offset = e.getPosition();
if(Math.abs(offset.y - lastEvtPosition.y) > 2){
sel.setHide();
mouseDownStatus = false;
return;
}
dir = offset.x > lastEvtPosition.x ? 1 : (offset.x < lastEvtPosition.x ? -1 : dir); dir = offset.x > lastEvtPosition.x ? 1 : (offset.x < lastEvtPosition.x ? -1 : dir);
receiver.updateSelectionByMousePosition(offset,dir) receiver.updateSelectionByMousePosition(offset,dir)
.updateSelectionShow(dir); .updateSelectionShow(dir);
sel.stroke('none',0); sel.stroke('none',0);
lastEvtPosition = e.getPosition(); lastEvtPosition = e.getPosition();
} }
}, },
'dblclick':function(e){ 'dblclick':function(e){
...@@ -4154,8 +4284,8 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -4154,8 +4284,8 @@ KityMinder.registerModule( "TextEditModule", function () {
sel.setStartOffset(0); sel.setStartOffset(0);
sel.setEndOffset(text.getContent().length); sel.setEndOffset(text.getContent().length);
sel.setShow(); sel.setShow();
receiver.updateSelectionShow(1) receiver.setContainerTxt(text.getContent()).updateSelectionShow(1)
.updateRange(range); .updateRange(range).setTextEditStatus(true)
} }
}, },
...@@ -4198,7 +4328,7 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -4198,7 +4328,7 @@ KityMinder.registerModule( "TextEditModule", function () {
receiver.updateSelectionShow(1) receiver.updateSelectionShow(1)
.updateRange(range); .updateRange(range);
return;
} }
...@@ -4211,10 +4341,11 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -4211,10 +4341,11 @@ KityMinder.registerModule( "TextEditModule", function () {
}else{ }else{
receiver.updateSelectionShow(1) receiver.updateSelectionShow(1)
} }
return;
} }
receiver.clear().setTextEditStatus(false);
}, },
'selectionclear':function(){ 'selectionclear':function(){
receiver.setTextEditStatus(false).clear() receiver.setTextEditStatus(false).clear()
...@@ -4241,7 +4372,12 @@ Minder.Range = kity.createClass('Range',{ ...@@ -4241,7 +4372,12 @@ Minder.Range = kity.createClass('Range',{
return this; return this;
}, },
setStart:function(node,index){ setStart:function(node,index){
this.nativeRange.setStart(node,index); try{
this.nativeRange.setStart(node,index);
}catch(e){
console.log(e)
}
return this; return this;
}, },
setEnd:function(node,index){ setEnd:function(node,index){
...@@ -4490,16 +4626,17 @@ Minder.Receiver = kity.createClass('Receiver',{ ...@@ -4490,16 +4626,17 @@ Minder.Receiver = kity.createClass('Receiver',{
return false; return false;
} }
if(offset.x >= v.x && offset.x <= v.x + v.width){ if(offset.x >= v.x && offset.x <= v.x + v.width){
if(me.index == i){ if(me.index == i){
if(i == 0){ if(i == 0){
me.selection.setStartOffset(i) me.selection.setStartOffset(i)
} }
me.selection.setEndOffset(i + (dir == 1 ? 1 : 0)) me.selection.setEndOffset(i + (dir == 1 ? 1 : 0))
}else if(i > me.index){ }else if(i > me.index){
me.selection.setStartOffset(me.index);
me.selection.setEndOffset(i + (dir == 1 ? 1 : 0)) me.selection.setEndOffset(i + (dir == 1 ? 1 : 0))
}else{ }else{
me.selection.setStartOffset(i + (dir == 1 ? 1 : 0)) me.selection.setStartOffset(i + (dir == 1 ? 1 : 0));
me.selection.setEndOffset(me.index)
} }
return false; return false;
...@@ -4513,7 +4650,7 @@ Minder.Receiver = kity.createClass('Receiver',{ ...@@ -4513,7 +4650,7 @@ Minder.Receiver = kity.createClass('Receiver',{
width = 0 ; width = 0 ;
if(this.selection.collapsed){ if(this.selection.collapsed){
this.selection.updateShow(startOffset,0); this.selection.updateShow(startOffset||this.textData[this.textData.length-1],0);
return this; return this;
} }
if(!endOffset){ if(!endOffset){
...@@ -4536,6 +4673,10 @@ Minder.Receiver = kity.createClass('Receiver',{ ...@@ -4536,6 +4673,10 @@ Minder.Receiver = kity.createClass('Receiver',{
setIndex:function(index){ setIndex:function(index){
this.index = index; this.index = index;
return this return this
},
setContainerTxt:function(txt){
this.container.textContent = txt;
return this;
} }
}); });
...@@ -4553,7 +4694,8 @@ Minder.Selection = kity.createClass( 'Selection', { ...@@ -4553,7 +4694,8 @@ Minder.Selection = kity.createClass( 'Selection', {
this.timer = null; this.timer = null;
this.collapsed = true; this.collapsed = true;
this.startOffset = this.endOffset = 0; this.startOffset = this.endOffset = 0;
this.setOpacity(0.5) this.setOpacity(0.5);
this.setStyle('cursor','text');
}, },
collapse : function(toEnd){ collapse : function(toEnd){
...@@ -4605,7 +4747,7 @@ Minder.Selection = kity.createClass( 'Selection', { ...@@ -4605,7 +4747,7 @@ Minder.Selection = kity.createClass( 'Selection', {
this.y = offset.y; this.y = offset.y;
} catch ( e ) { } catch ( e ) {
console.log(e) debugger
} }
return this.update(); return this.update();
...@@ -4728,8 +4870,8 @@ KityMinder.registerModule( "basestylemodule", function () { ...@@ -4728,8 +4870,8 @@ KityMinder.registerModule( "basestylemodule", function () {
} ) } )
}, },
addShortcutKeys: { addShortcutKeys: {
"bold": "ctrl+66", //bold "bold": "ctrl+b", //bold
"italic": "ctrl+73" //italic "italic": "ctrl+i" //italic
}, },
"events": { "events": {
"beforeRenderNode": function ( e ) { "beforeRenderNode": function ( e ) {
...@@ -4909,7 +5051,7 @@ KityMinder.registerModule( 'Zoom', function () { ...@@ -4909,7 +5051,7 @@ KityMinder.registerModule( 'Zoom', function () {
'zoom-out': ZoomOutCommand 'zoom-out': ZoomOutCommand
}, },
addShortcutKeys: { addShortcutKeys: {
"zoom-in": "+", //= "zoom-in": "=", //=
"zoom-out": "-" //- "zoom-out": "-" //-
}, },
events: { events: {
...@@ -5755,7 +5897,7 @@ KM.ui.define('colorpicker', { ...@@ -5755,7 +5897,7 @@ KM.ui.define('colorpicker', {
"<%if(autoRecord) {%>" + "<%if(autoRecord) {%>" +
"<%for( var i=0, len = recordStack.length; i<len; i++ ) {%>" + "<%for( var i=0, len = recordStack.length; i<len; i++ ) {%>" +
"<%var index = recordStack[i];%>" + "<%var index = recordStack[i];%>" +
"<li class=\"<%=itemClassName%><%if( selected == index ) {%> kmui-combobox-checked<%}%>\" data-item-index=\"<%=index%>\" unselectable=\"on\" onmousedown=\"return false\">" + "<li class=\"<%=itemClassName%><%if( selected == index ) {%> kmui-combobox-checked<%}%><%if( disabled[ index ] === true ) {%> kmui-combobox-item-disabled<%}%>\" data-item-index=\"<%=index%>\" unselectable=\"on\" onmousedown=\"return false\">" +
"<span class=\"kmui-combobox-icon\" unselectable=\"on\" onmousedown=\"return false\"></span>" + "<span class=\"kmui-combobox-icon\" unselectable=\"on\" onmousedown=\"return false\"></span>" +
"<label class=\"<%=labelClassName%>\" style=\"<%=itemStyles[ index ]%>\" unselectable=\"on\" onmousedown=\"return false\"><%=items[index]%></label>" + "<label class=\"<%=labelClassName%>\" style=\"<%=itemStyles[ index ]%>\" unselectable=\"on\" onmousedown=\"return false\"><%=items[index]%></label>" +
"</li>" + "</li>" +
...@@ -5765,7 +5907,7 @@ KM.ui.define('colorpicker', { ...@@ -5765,7 +5907,7 @@ KM.ui.define('colorpicker', {
"<%}%>" + "<%}%>" +
"<%}%>" + "<%}%>" +
"<%for( var i=0, label; label = items[i]; i++ ) {%>" + "<%for( var i=0, label; label = items[i]; i++ ) {%>" +
"<li class=\"<%=itemClassName%><%if( selected == i ) {%> kmui-combobox-checked<%}%> kmui-combobox-item-<%=i%>\" data-item-index=\"<%=i%>\" unselectable=\"on\" onmousedown=\"return false\">" + "<li class=\"<%=itemClassName%><%if( selected == i ) {%> kmui-combobox-checked<%}%> kmui-combobox-item-<%=i%><%if( disabled[ i ] === true ) {%> kmui-combobox-item-disabled<%}%>\" data-item-index=\"<%=i%>\" unselectable=\"on\" onmousedown=\"return false\">" +
"<span class=\"kmui-combobox-icon\" unselectable=\"on\" onmousedown=\"return false\"></span>" + "<span class=\"kmui-combobox-icon\" unselectable=\"on\" onmousedown=\"return false\"></span>" +
"<label class=\"<%=labelClassName%>\" style=\"<%=itemStyles[ i ]%>\" unselectable=\"on\" onmousedown=\"return false\"><%=label%></label>" + "<label class=\"<%=labelClassName%>\" style=\"<%=itemStyles[ i ]%>\" unselectable=\"on\" onmousedown=\"return false\"><%=label%></label>" +
"</li>" + "</li>" +
...@@ -5780,10 +5922,13 @@ KM.ui.define('colorpicker', { ...@@ -5780,10 +5922,13 @@ KM.ui.define('colorpicker', {
value: [], value: [],
comboboxName: '', comboboxName: '',
selected: '', selected: '',
//初始禁用状态
disabled: {},
//自动记录 //自动记录
autoRecord: true, autoRecord: true,
//最多记录条数 //最多记录条数
recordCount: 5 recordCount: 5,
enabledRecord:true
}, },
init: function( options ){ init: function( options ){
...@@ -5821,6 +5966,7 @@ KM.ui.define('colorpicker', { ...@@ -5821,6 +5966,7 @@ KM.ui.define('colorpicker', {
initSelectItem: function(){ initSelectItem: function(){
var me = this, var me = this,
options = me.data( "options" ),
labelClass = "."+labelClassName; labelClass = "."+labelClassName;
me.root().delegate('.' + itemClassName, 'click', function(){ me.root().delegate('.' + itemClassName, 'click', function(){
...@@ -5828,6 +5974,10 @@ KM.ui.define('colorpicker', { ...@@ -5828,6 +5974,10 @@ KM.ui.define('colorpicker', {
var $li = $(this), var $li = $(this),
index = $li.attr('data-item-index'); index = $li.attr('data-item-index');
if ( options.disabled[ index ] ) {
return false;
}
me.trigger('comboboxselect', { me.trigger('comboboxselect', {
index: index, index: index,
label: $li.find(labelClass).text(), label: $li.find(labelClass).text(),
...@@ -5860,11 +6010,20 @@ KM.ui.define('colorpicker', { ...@@ -5860,11 +6010,20 @@ KM.ui.define('colorpicker', {
*/ */
select: function( index ){ select: function( index ){
var itemCount = this.data('options').itemCount, if(!this.data('options').enabledRecord){
items = this.data('options').autowidthitem; return this;
}
var options = this.data( 'options' ),
itemCount = options.itemCount,
items = options.autowidthitem;
if ( items && !items.length ) { if ( items && !items.length ) {
items = this.data('options').items; items = options.items;
}
// 禁用
if ( options.disabled[ index ] ) {
return null;
} }
if( itemCount == 0 ) { if( itemCount == 0 ) {
...@@ -5912,6 +6071,65 @@ KM.ui.define('colorpicker', { ...@@ -5912,6 +6071,65 @@ KM.ui.define('colorpicker', {
} ); } );
}, },
getItems: function () {
return this.data( "options" ).items;
},
traverseItems:function(fn){
var values = this.data('options').value;
var labels = this.data('options').items;
$.each(labels,function(i,label){
fn(label,values[i])
});
return this;
},
getItemMapping: function () {
return this.data( "options" ).itemMapping;
},
disableItemByIndex: function ( index ) {
var options = this.data( "options" );
options.disabled[ index ] = true;
this._repaint();
},
disableItemByLabel: function ( label ) {
var itemMapping = this.data('options').itemMapping,
index = itemMapping[ label ];
if ( typeof index === "number" ) {
return this.disableItemByIndex( index );
}
return false;
},
enableItemByIndex: function ( index ) {
var options = this.data( "options" );
delete options.disabled[ index ];
this._repaint();
},
enableItemByLabel: function ( label ) {
var itemMapping = this.data('options').itemMapping,
index = itemMapping[ label ];
if ( typeof index === "number" ) {
return this.enableItemByIndex( index );
}
return false;
},
/** /**
* 转换记录栈 * 转换记录栈
*/ */
...@@ -5990,8 +6208,7 @@ KM.ui.define('colorpicker', { ...@@ -5990,8 +6208,7 @@ KM.ui.define('colorpicker', {
_update: function ( index ) { _update: function ( index ) {
var options = this.data("options"), var options = this.data("options"),
newStack = [], newStack = [];
newChilds = null;
$.each( options.recordStack, function( i, item ){ $.each( options.recordStack, function( i, item ){
...@@ -6011,13 +6228,20 @@ KM.ui.define('colorpicker', { ...@@ -6011,13 +6228,20 @@ KM.ui.define('colorpicker', {
options.recordStack = newStack; options.recordStack = newStack;
options.selected = index; options.selected = index;
newChilds = $( $.parseTmpl( this.tpl, options ) ); this._repaint();
newStack = null;
},
_repaint: function () {
var newChilds = $( $.parseTmpl( this.tpl, this.data("options") ) );
//重新渲染 //重新渲染
this.root().html( newChilds.html() ); this.root().html( newChilds.html() );
newChilds = null; newChilds = null;
newStack = null;
} }
}; };
...@@ -6748,7 +6972,7 @@ KM.registerToolbarUI( 'bold italic redo undo', ...@@ -6748,7 +6972,7 @@ KM.registerToolbarUI( 'bold italic redo undo',
} }
); );
KM.registerToolbarUI( 'layoutstyle fontfamily fontsize', function ( name ) { KM.registerToolbarUI( 'fontfamily fontsize', function ( name ) {
var me = this, var me = this,
label = me.getLang( 'tooltips.' + name ), label = me.getLang( 'tooltips.' + name ),
...@@ -6769,17 +6993,15 @@ KM.registerToolbarUI( 'layoutstyle fontfamily fontsize', function ( name ) { ...@@ -6769,17 +6993,15 @@ KM.registerToolbarUI( 'layoutstyle fontfamily fontsize', function ( name ) {
} }
switch ( name ) { switch ( name ) {
case 'layoutstyle':
options = transForLayoutstyle( options );
break;
case 'fontfamily':
options = transForFontfamily( options );
break;
case 'fontsize': case 'fontfamily':
options = transForFontsize( options ); options = transForFontfamily( options );
break; break;
case 'fontsize':
options = transForFontsize( options );
break;
} }
...@@ -6812,24 +7034,6 @@ KM.registerToolbarUI( 'layoutstyle fontfamily fontsize', function ( name ) { ...@@ -6812,24 +7034,6 @@ KM.registerToolbarUI( 'layoutstyle fontfamily fontsize', function ( name ) {
return comboboxWidget.button().addClass( 'kmui-combobox' ); return comboboxWidget.button().addClass( 'kmui-combobox' );
function transForLayoutstyle( options ) {
var tempItems = [];
utils.each( options.items, function ( k, v ) {
options.value.push( k );
tempItems.push( k );
options.autowidthitem.push( $.wordCountAdaptive( tempItems[ tempItems.length - 1 ] ) );
} );
options.items = tempItems;
return options;
}
//字体参数转换 //字体参数转换
function transForFontfamily( options ) { function transForFontfamily( options ) {
...@@ -6969,7 +7173,6 @@ KM.registerToolbarUI( 'saveto', function ( name ) { ...@@ -6969,7 +7173,6 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
options.autowidthitem.push( $.wordCountAdaptive( text ), true ); options.autowidthitem.push( $.wordCountAdaptive( text ), true );
} ); } );
//实例化 //实例化
$combox = $.kmuibuttoncombobox( options ).css( 'zIndex', me.getOptions( 'zIndex' ) + 1 ); $combox = $.kmuibuttoncombobox( options ).css( 'zIndex', me.getOptions( 'zIndex' ) + 1 );
comboboxWidget = $combox.kmui(); comboboxWidget = $combox.kmui();
...@@ -6985,8 +7188,15 @@ KM.registerToolbarUI( 'saveto', function ( name ) { ...@@ -6985,8 +7188,15 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
if ( $combox.parent().length === 0 ) { if ( $combox.parent().length === 0 ) {
$combox.appendTo( me.$container.find( '.kmui-dialog-container' ) ); $combox.appendTo( me.$container.find( '.kmui-dialog-container' ) );
} }
} ).on( 'aftercomboboxselect', function () { var combox = $combox.kmui();
this.setLabelWithDefaultValue();
combox.traverseItems( function ( label, value ) {
if ( me.queryCommandState( value ) == -1 ) {
combox.disableItemByLabel( label )
} else {
combox.enableItemByLabel( label )
}
} )
} ); } );
...@@ -7085,6 +7295,106 @@ KM.registerUI( 'tooltips', ...@@ -7085,6 +7295,106 @@ KM.registerUI( 'tooltips',
} }
); );
KM.registerToolbarUI( 'layout', function ( name ) {
var me = this,
label = me.getLang( 'tooltips.' + name ),
options = {
label: label,
title: label,
comboboxName: name,
items: me.getLayoutStyleItems() || [],
itemStyles: [],
value: me.getLayoutStyleItems(),
autowidthitem: []
},
$combox = null;
if ( options.items.length == 0 ) {
return null;
}
//实例化
$combox = $.kmuibuttoncombobox( options ).css( 'zIndex', me.getOptions( 'zIndex' ) + 1 );
comboboxWidget = $combox.kmui();
comboboxWidget.on( 'comboboxselect', function ( evt, res ) {
me.execCommand( "switchlayout", res.value );
} ).on( "beforeshow", function () {
if ( $combox.parent().length === 0 ) {
$combox.appendTo( me.$container.find( '.kmui-dialog-container' ) );
}
} );
return comboboxWidget.button().addClass( 'kmui-combobox' );
} );
KM.registerToolbarUI( 'node', function ( name ) {
var shortcutKeys = {
"appendsiblingnode": "enter",
"appendchildnode": "tab",
"removenode": "del|backspace"
};
var me = this,
msg = me.getLang( 'node' ),
label = me.getLang( 'tooltips.' + name ),
options = {
label: label,
title: label,
comboboxName: name,
items: me.getOptions( name ) || [],
itemStyles: [],
value: [],
autowidthitem: [],
enabledRecord: false
},
$combox = null;
if ( options.items.length == 0 ) {
return null;
}
//实例化
$combox = $.kmuibuttoncombobox( transForInserttopic( options ) ).css( 'zIndex', me.getOptions( 'zIndex' ) + 1 );
comboboxWidget = $combox.kmui();
comboboxWidget.on( 'comboboxselect', function ( evt, res ) {
me.execCommand( res.value, new MinderNode( me.getLang().topic ) );
} ).on( "beforeshow", function () {
if ( $combox.parent().length === 0 ) {
$combox.appendTo( me.$container.find( '.kmui-dialog-container' ) );
}
var combox = $combox.kmui();
combox.traverseItems( function ( label, value ) {
if ( me.queryCommandState( value ) == -1 ) {
combox.disableItemByLabel( label )
} else {
combox.enableItemByLabel( label )
}
} )
} );
return comboboxWidget.button().addClass( 'kmui-combobox' );
function transForInserttopic( options ) {
var tempItems = [];
utils.each( options.items, function ( k, v ) {
options.value.push( v );
tempItems.push( ( msg[ k ] || k ) + '(' + shortcutKeys[ v ].toUpperCase() + ')' );
options.autowidthitem.push( $.wordCountAdaptive( tempItems[ tempItems.length - 1 ] ) );
} );
options.items = tempItems;
return options;
}
} );
KityMinder.registerProtocal( "plain", function () { KityMinder.registerProtocal( "plain", function () {
var LINE_ENDING = '\n', var LINE_ENDING = '\n',
TAB_CHAR = '\t'; TAB_CHAR = '\t';
......
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