Commit 0034c01d authored by techird's avatar techird

添加节点收起功能

parent 0feacf5a
...@@ -137,7 +137,9 @@ KityMinder.LANG['zh-cn'] = { ...@@ -137,7 +137,9 @@ KityMinder.LANG['zh-cn'] = {
'editnode': '编辑', 'editnode': '编辑',
'arrangeup': '上移', 'arrangeup': '上移',
'arrangedown': '下移', 'arrangedown': '下移',
'resetlayout': '整理布局' 'resetlayout': '整理布局',
'expandtoleave': '展开全部节点',
'collapsetolevel1': '收起到一级节点'
}, },
'back': '返回', 'back': '返回',
......
...@@ -9,9 +9,17 @@ var keymap = KityMinder.keymap = (function(origin) { ...@@ -9,9 +9,17 @@ var keymap = KityMinder.keymap = (function(origin) {
var aKeyCode = 65; var aKeyCode = 65;
var aCharCode = 'a'.charCodeAt(0); var aCharCode = 'a'.charCodeAt(0);
// letters
'abcdefghijklmnopqrstuvwxyz'.split('').forEach(function(letter) { 'abcdefghijklmnopqrstuvwxyz'.split('').forEach(function(letter) {
ret[letter] = aKeyCode + (letter.charCodeAt(0) - aCharCode); ret[letter] = aKeyCode + (letter.charCodeAt(0) - aCharCode);
}); });
// numbers
var n = 9;
do {
ret[n.toString()] = n + 48;
} while(--n);
return ret; return ret;
})({ })({
'Backspace': 8, 'Backspace': 8,
...@@ -65,6 +73,7 @@ var keymap = KityMinder.keymap = (function(origin) { ...@@ -65,6 +73,7 @@ var keymap = KityMinder.keymap = (function(origin) {
'F11': 121, 'F11': 121,
'F12': 122, 'F12': 122,
'`': 192,
'=': 187, '=': 187,
'-': 189, '-': 189,
......
...@@ -151,7 +151,7 @@ KityMinder.registerModule('Expand', function() { ...@@ -151,7 +151,7 @@ KityMinder.registerModule('Expand', function() {
}); });
}, },
queryState: function(km) { queryState: function(km) {
return 0; return !km.getSelectedNode() ? 0 : -1;
} }
}); });
var CollapseNodeCommand = kity.createClass('CollapseNodeCommand', { var CollapseNodeCommand = kity.createClass('CollapseNodeCommand', {
...@@ -163,7 +163,7 @@ KityMinder.registerModule('Expand', function() { ...@@ -163,7 +163,7 @@ KityMinder.registerModule('Expand', function() {
}); });
}, },
queryState: function(km) { queryState: function(km) {
return 0; return !km.getSelectedNode() ? 0 : -1;
} }
}); });
var Expander = kity.createClass('Expander', { var Expander = kity.createClass('Expander', {
...@@ -241,8 +241,8 @@ KityMinder.registerModule('Expand', function() { ...@@ -241,8 +241,8 @@ KityMinder.registerModule('Expand', function() {
}); });
return { return {
commands: { commands: {
'ExpandNode': ExpandNodeCommand, 'expandtoleave': ExpandNodeCommand,
'CollapseNode': CollapseNodeCommand 'collapsetolevel1': CollapseNodeCommand
}, },
events: { events: {
'layoutapply': function(e) { 'layoutapply': function(e) {
...@@ -276,6 +276,17 @@ KityMinder.registerModule('Expand', function() { ...@@ -276,6 +276,17 @@ KityMinder.registerModule('Expand', function() {
}, },
renderers: { renderers: {
outside: ExpanderRenderer outside: ExpanderRenderer
},
contextmenu: [{
command: 'expandtoleave'
}, {
command: 'collapsetolevel1'
}, {
divider: true
}],
commandShortcutKeys: {
'expandtoleave': 'Alt+`',
'collapsetolevel1': 'Alt+1'
} }
}; };
}); });
\ No newline at end of file
...@@ -20,6 +20,13 @@ KityMinder.registerUI('contextmenu', function(minder) { ...@@ -20,6 +20,13 @@ KityMinder.registerUI('contextmenu', function(minder) {
var downPosition; var downPosition;
function distance(p1, p2) {
var dx = p1[0] - p2[0];
var dy = p1[1] - p2[1];
var ds = Math.sqrt(dx * dx + dy * dy);
return ds;
}
$menu.delegate('li', 'mousedown', function(e, info) { $menu.delegate('li', 'mousedown', function(e, info) {
var item = $(e.target).closest('li').data('menu'); var item = $(e.target).closest('li').data('menu');
if (item.command) { if (item.command) {
...@@ -34,7 +41,7 @@ KityMinder.registerUI('contextmenu', function(minder) { ...@@ -34,7 +41,7 @@ KityMinder.registerUI('contextmenu', function(minder) {
$('#content-wrapper').on('mousedown', function(e) { $('#content-wrapper').on('mousedown', function(e) {
$menu.hide(); $menu.hide();
if (e.button == 2) { if (e.button == 2) {
downPosition = [e.pageX, e.pageY].join(','); downPosition = [e.pageX, e.pageY];
} else { } else {
downPosition = null; downPosition = null;
} }
...@@ -47,7 +54,8 @@ KityMinder.registerUI('contextmenu', function(minder) { ...@@ -47,7 +54,8 @@ KityMinder.registerUI('contextmenu', function(minder) {
e = e.originEvent; e = e.originEvent;
if (downPosition != [e.pageX, e.pageY].join(',')) return; var d = distance(downPosition, [e.pageX, e.pageY]);
if (isNaN(d) || d > 5) return;
$menu.empty(); $menu.empty();
......
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