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 @@ ...@@ -63,7 +63,7 @@
'KITYMINDER_HOME_URL': getKMBasePath(), 'KITYMINDER_HOME_URL': getKMBasePath(),
//定义工具栏 //定义工具栏
toolbars: [ 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( ...@@ -62,6 +62,7 @@ $dependency = Array(
,'src/adapter/view.js' ,'src/adapter/view.js'
,'src/adapter/dialog.js' ,'src/adapter/dialog.js'
,'src/adapter/tooltips.js' ,'src/adapter/tooltips.js'
,'src/adapter/node.js'
,'src/protocal/plain.js' ,'src/protocal/plain.js'
,'src/protocal/json.js' ,'src/protocal/json.js'
); );
......
...@@ -10,6 +10,7 @@ KityMinder.LANG[ 'zh-cn' ] = { ...@@ -10,6 +10,7 @@ KityMinder.LANG[ 'zh-cn' ] = {
'fontfamily': '字体', 'fontfamily': '字体',
'fontsize': '字号', 'fontsize': '字号',
'layoutstyle': '主题', 'layoutstyle': '主题',
'node':'节点操作',
'saveto': '导出', 'saveto': '导出',
'hand': '允许拖拽', 'hand': '允许拖拽',
'zoom-in': '放大', 'zoom-in': '放大',
...@@ -35,9 +36,14 @@ KityMinder.LANG[ 'zh-cn' ] = { ...@@ -35,9 +36,14 @@ KityMinder.LANG[ 'zh-cn' ] = {
'quarterdone': '完成1/4', 'quarterdone': '完成1/4',
'halfdone': '完成1/2', 'halfdone': '完成1/2',
'threequartersdone': '完成3/4', '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, var me = this,
label = me.getLang( 'tooltips.' + name ), label = me.getLang( 'tooltips.' + name ),
...@@ -31,6 +31,8 @@ KM.registerToolbarUI( 'layoutstyle fontfamily fontsize', function ( name ) { ...@@ -31,6 +31,8 @@ KM.registerToolbarUI( 'layoutstyle fontfamily fontsize', function ( name ) {
options = transForFontsize( options ); options = transForFontsize( options );
break; 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 = { ...@@ -28,5 +28,14 @@ var keymap = KityMinder.keymap = {
'NumLock':144, '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", { ...@@ -87,25 +87,46 @@ 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();
}
} }
});
if(current == keys.length){
if ( me.queryCommandState( i ) != -1 )
me.execCommand( i );
originEvent.preventDefault();
break;
} }
} }
......
...@@ -69,8 +69,8 @@ KityMinder.registerModule( "basestylemodule", function () { ...@@ -69,8 +69,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 ) {
......
...@@ -138,8 +138,8 @@ KityMinder.registerModule( "HistoryModule", function () { ...@@ -138,8 +138,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 ) {
......
This diff is collapsed.
...@@ -605,7 +605,6 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -605,7 +605,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 {
......
...@@ -104,6 +104,14 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -104,6 +104,14 @@ KityMinder.registerModule( "LayoutModule", function () {
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;
}
} }
}; };
} )() ); } )() );
...@@ -124,6 +132,14 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -124,6 +132,14 @@ KityMinder.registerModule( "LayoutModule", function () {
} }
km.select( node, true ); km.select( node, true );
return node; 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 () { ...@@ -148,6 +164,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 === 1 && selectedNodes[ 0 ] === km.getRoot() ) || selectedNodes.length === 0 ) {
return -1;
} else {
return 0;
}
} }
}; };
} )() ); } )() );
...@@ -181,7 +205,12 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -181,7 +205,12 @@ KityMinder.registerModule( "LayoutModule", function () {
} }
}, },
"defaultOptions": { "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 () { ...@@ -62,7 +62,7 @@ KityMinder.registerModule( 'Zoom', function () {
'zoom-out': ZoomOutCommand 'zoom-out': ZoomOutCommand
}, },
addShortcutKeys: { addShortcutKeys: {
"zoom-in": "+", //= "zoom-in": "=", //=
"zoom-out": "-" //- "zoom-out": "-" //-
}, },
events: { events: {
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
"<%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>" +
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
"<%}%>" + "<%}%>" +
"<%}%>" + "<%}%>" +
"<%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>" +
...@@ -46,6 +46,8 @@ ...@@ -46,6 +46,8 @@
value: [], value: [],
comboboxName: '', comboboxName: '',
selected: '', selected: '',
//初始禁用状态
disabled: {},
//自动记录 //自动记录
autoRecord: true, autoRecord: true,
//最多记录条数 //最多记录条数
...@@ -87,6 +89,7 @@ ...@@ -87,6 +89,7 @@
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(){
...@@ -94,6 +97,10 @@ ...@@ -94,6 +97,10 @@
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(),
...@@ -126,11 +133,17 @@ ...@@ -126,11 +133,17 @@
*/ */
select: function( index ){ select: function( index ){
var itemCount = this.data('options').itemCount, var options = this.data( 'options' ),
items = this.data('options').autowidthitem; 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 ) {
...@@ -178,6 +191,65 @@ ...@@ -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 @@ ...@@ -256,8 +328,7 @@
_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 ){
...@@ -277,13 +348,20 @@ ...@@ -277,13 +348,20 @@
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;
} }
}; };
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
.kmui-combobox-menu .kmui-combobox-item { .kmui-combobox-menu .kmui-combobox-item {
display: block; display: block;
border: 1px solid white; border: 1px solid white;
white-space:nowrap;
} }
.kmui-combobox-menu .kmui-combobox-item-label { .kmui-combobox-menu .kmui-combobox-item-label {
...@@ -185,3 +186,12 @@ ...@@ -185,3 +186,12 @@
.kmui-combobox-paragraph .kmui-combobox-item-6 .kmui-combobox-item-label { .kmui-combobox-paragraph .kmui-combobox-item-6 .kmui-combobox-item-label {
font-size: 12px; 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