Commit f3b162df authored by techird's avatar techird

Merge branch 'dev' of github.com:kitygraph/kityminder into dev

parents 98e0d3cd 80d4ac10
......@@ -63,7 +63,7 @@
'KITYMINDER_HOME_URL': getKMBasePath(),
//定义工具栏
toolbars: [
'hand zoom-in zoom-out | undo redo | bold italic | fontfamily fontsize forecolor | saveto | markers'
'hand zoom-in zoom-out | undo redo | bold italic | fontfamily fontsize forecolor | saveto | markers | node'
]
//设置主题
......
......@@ -62,6 +62,7 @@ $dependency = Array(
,'src/adapter/view.js'
,'src/adapter/dialog.js'
,'src/adapter/tooltips.js'
,'src/adapter/node.js'
,'src/protocal/plain.js'
,'src/protocal/json.js'
);
......
......@@ -10,6 +10,7 @@ KityMinder.LANG[ 'zh-cn' ] = {
'fontfamily': '字体',
'fontsize': '字号',
'layoutstyle': '主题',
'node':'节点操作',
'saveto': '导出',
'hand': '允许拖拽',
'zoom-in': '放大',
......@@ -35,9 +36,14 @@ KityMinder.LANG[ 'zh-cn' ] = {
'quarterdone': '完成1/4',
'halfdone': '完成1/2',
'threequartersdone': '完成3/4',
'done': '已完成',
'done': '已完成'
}
}
},
'node':{
'appendsiblingnode':'插入兄弟节点',
'appendchildnode':'插入孩子节点',
'removenode':'删除节点'
}
};
\ No newline at end of file
KM.registerToolbarUI( 'layoutstyle fontfamily fontsize', function ( name ) {
KM.registerToolbarUI( 'layoutstyle fontfamily fontsize inserttopic', function ( name ) {
var me = this,
label = me.getLang( 'tooltips.' + name ),
......@@ -19,18 +19,20 @@ KM.registerToolbarUI( 'layoutstyle fontfamily fontsize', function ( name ) {
}
switch ( name ) {
case 'layoutstyle':
options = transForLayoutstyle( options );
break;
case 'layoutstyle':
options = transForLayoutstyle( options );
break;
case 'fontfamily':
options = transForFontfamily( options );
break;
case 'fontfamily':
options = transForFontfamily( options );
break;
case 'fontsize':
options = transForFontsize( options );
break;
case 'fontsize':
options = transForFontsize( options );
break;
case 'inserttopic':
optons
}
//实例化
......
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: []
},
$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 );
}).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;
}
});
......@@ -28,5 +28,14 @@ var keymap = KityMinder.keymap = {
'NumLock':144,
'Cmd':91
'Cmd':91,
'=':187,
'-':189,
"b":66,
'i':73,
'z':90,
'y':89
};
\ No newline at end of file
......@@ -87,25 +87,46 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
_bindshortcutKeys: function () {
var me = this,
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 keyCode = originEvent.keyCode || originEvent.which;
for ( var i in shortcutkeys ) {
var tmp = shortcutkeys[ i ].split( ',' );
for ( var t = 0, ti; ti = tmp[ t++ ]; ) {
ti = ti.split( ':' );
var key = ti[ 0 ],
param = ti[ 1 ];
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();
}
var keys = shortcutkeys[ i ].toLowerCase().split('+');
var current = 0;
utils.each(keys,function(i,k){
if(checkkey(k,keyCode,originEvent)){
current++;
}
});
if(current == keys.length){
if ( me.queryCommandState( i ) != -1 )
me.execCommand( i );
originEvent.preventDefault();
break;
}
}
......
......@@ -69,8 +69,8 @@ KityMinder.registerModule( "basestylemodule", function () {
} )
},
addShortcutKeys: {
"bold": "ctrl+66", //bold
"italic": "ctrl+73" //italic
"bold": "ctrl+b", //bold
"italic": "ctrl+i" //italic
},
"events": {
"beforeRenderNode": function ( e ) {
......
......@@ -138,8 +138,8 @@ KityMinder.registerModule( "HistoryModule", function () {
} )
},
addShortcutKeys: {
"Undo": "ctrl+90", //undo
"Redo": "ctrl+89" //redo
"Undo": "ctrl+z", //undo
"Redo": "ctrl+y" //redo
},
"events": {
"saveScene": function ( e ) {
......
This diff is collapsed.
......@@ -605,7 +605,6 @@ KityMinder.registerModule( "LayoutDefault", function () {
var parent = _buffer[ 0 ].getParent();
Layout.parent = parent;
_cleanbuffer.push( _buffer[ 0 ] );
//minder.appendChildNode( parent, _buffer[ 0 ] );
Layout.connect = null;
Layout.shicon = null;
} else {
......
......@@ -104,6 +104,14 @@ KityMinder.registerModule( "LayoutModule", function () {
km.appendChildNode( parent, node );
km.select( node, true );
return node;
},
queryState: function ( km ) {
var selectedNode = km.getSelectedNode();
if ( !selectedNode ) {
return -1;
} else {
return 0;
}
}
};
} )() );
......@@ -124,6 +132,14 @@ KityMinder.registerModule( "LayoutModule", function () {
}
km.select( node, true );
return node;
},
queryState: function ( km ) {
var selectedNode = km.getSelectedNode();
if ( !selectedNode || selectedNode === km.getRoot() ) {
return -1;
} else {
return 0;
}
}
};
} )() );
......@@ -148,6 +164,14 @@ KityMinder.registerModule( "LayoutModule", function () {
} while ( _buffer.length > 1 );
km.removeNode( selectedNodes );
km.select( _buffer[ 0 ] );
},
queryState: function ( km ) {
var selectedNodes = km.getSelectedNodes();
if ( ( selectedNodes.length === 1 && selectedNodes[ 0 ] === km.getRoot() ) || selectedNodes.length === 0 ) {
return -1;
} else {
return 0;
}
}
};
} )() );
......@@ -181,7 +205,12 @@ KityMinder.registerModule( "LayoutModule", function () {
}
},
"defaultOptions": {
"defaultlayoutstyle": "default"
"defaultlayoutstyle": "default",
"node": {
'appendsiblingnode': 'appendsiblingnode',
'appendchildnode': 'appendchildnode',
'removenode': 'removenode'
}
}
};
} );
\ No newline at end of file
......@@ -62,7 +62,7 @@ KityMinder.registerModule( 'Zoom', function () {
'zoom-out': ZoomOutCommand
},
addShortcutKeys: {
"zoom-in": "+", //=
"zoom-in": "=", //=
"zoom-out": "-" //-
},
events: {
......
......@@ -21,7 +21,7 @@
"<%if(autoRecord) {%>" +
"<%for( var i=0, len = recordStack.length; i<len; 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>" +
"<label class=\"<%=labelClassName%>\" style=\"<%=itemStyles[ index ]%>\" unselectable=\"on\" onmousedown=\"return false\"><%=items[index]%></label>" +
"</li>" +
......@@ -31,7 +31,7 @@
"<%}%>" +
"<%}%>" +
"<%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>" +
"<label class=\"<%=labelClassName%>\" style=\"<%=itemStyles[ i ]%>\" unselectable=\"on\" onmousedown=\"return false\"><%=label%></label>" +
"</li>" +
......@@ -46,6 +46,8 @@
value: [],
comboboxName: '',
selected: '',
//初始禁用状态
disabled: {},
//自动记录
autoRecord: true,
//最多记录条数
......@@ -87,6 +89,7 @@
initSelectItem: function(){
var me = this,
options = me.data( "options" ),
labelClass = "."+labelClassName;
me.root().delegate('.' + itemClassName, 'click', function(){
......@@ -94,6 +97,10 @@
var $li = $(this),
index = $li.attr('data-item-index');
if ( options.disabled[ index ] ) {
return false;
}
me.trigger('comboboxselect', {
index: index,
label: $li.find(labelClass).text(),
......@@ -126,11 +133,17 @@
*/
select: function( index ){
var itemCount = this.data('options').itemCount,
items = this.data('options').autowidthitem;
var options = this.data( 'options' ),
itemCount = options.itemCount,
items = options.autowidthitem;
if ( items && !items.length ) {
items = this.data('options').items;
items = options.items;
}
// 禁用
if ( options.disabled[ index ] ) {
return null;
}
if( itemCount == 0 ) {
......@@ -178,6 +191,65 @@
} );
},
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;
},
/**
* 转换记录栈
*/
......@@ -256,8 +328,7 @@
_update: function ( index ) {
var options = this.data("options"),
newStack = [],
newChilds = null;
newStack = [];
$.each( options.recordStack, function( i, item ){
......@@ -277,13 +348,20 @@
options.recordStack = newStack;
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() );
newChilds = null;
newStack = null;
}
};
......
......@@ -19,6 +19,7 @@
.kmui-combobox-menu .kmui-combobox-item {
display: block;
border: 1px solid white;
white-space:nowrap;
}
.kmui-combobox-menu .kmui-combobox-item-label {
......@@ -184,4 +185,13 @@
/* h6 */
.kmui-combobox-paragraph .kmui-combobox-item-6 .kmui-combobox-item-label {
font-size: 12px;
}
.kmui-combobox-menu .kmui-combobox-item-disabled {
opacity: 0.3;
}
.kmui-combobox-menu .kmui-combobox-item-disabled:HOVER {
border-color: #fff;
background-color: #fff;
}
\ No newline at end of file
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