Commit 1711db1e authored by techird's avatar techird

支持归纳命令 && 移除旧代码

parent 67cb3b04
...@@ -94,62 +94,53 @@ define(function(require, exports, module) { ...@@ -94,62 +94,53 @@ define(function(require, exports, module) {
} }
}); });
/** var AppendParentCommand = kity.createClass('AppendParentCommand', {
* @command EditNode
* @description 编辑选中的节点
* @state
* 0: 当前有选中的节点
* -1: 当前没有选中的节点
*/
var EditNodeCommand = kity.createClass('EditNodeCommand', {
base: Command, base: Command,
execute: function(km) { execute: function(km, text) {
var selectedNode = km.getSelectedNode(); var nodes = km.getSelectedNodes();
if (!selectedNode) { if (!nodes.length) return;
return null; var parent = nodes[0].parent;
for (var i = 1; i < nodes.length; i++) {
if (nodes[i].parent != parent) return -1;
} }
km.select(selectedNode, true); nodes.sort(function(a, b) {
km.textEditNode(selectedNode); return a.getIndex() - b.getIndex();
});
var newParent = km.createNode(text, parent, nodes[0].getIndex());
nodes.forEach(function(node) {
newParent.appendChild(node);
});
newParent.setGlobalLayoutTransform(nodes[nodes.length >> 1].getGlobalLayoutTransform());
km.select(newParent, true);
km.layout(600);
}, },
queryState: function(km) { queryState: function(km) {
var selectedNode = km.getSelectedNode(); var nodes = km.getSelectedNodes();
if (!selectedNode) { if (!nodes.length) return;
return -1; var parent = nodes[0].parent;
} else { for (var i = 1; i < nodes.length; i++) {
return 0; if (nodes[i].parent != parent) return -1;
} }
}, return 0;
isNeedUndo: function() {
return false;
} }
}); });
Module.register('NodeModule', function() { Module.register('NodeModule', function() {
return { return {
commands: { commands: {
'AppendChildNode': AppendChildCommand, 'AppendChildNode': AppendChildCommand,
'AppendSiblingNode': AppendSiblingCommand, 'AppendSiblingNode': AppendSiblingCommand,
'RemoveNode': RemoveNodeCommand, 'RemoveNode': RemoveNodeCommand,
'EditNode': EditNodeCommand 'AppendParentNode': AppendParentCommand
}, },
'contextmenu': [{
command: 'appendsiblingnode'
}, {
command: 'appendchildnode'
}, {
command: 'editnode'
}, {
command: 'removenode'
}, {
divider: 1
}],
'commandShortcutKeys': { 'commandShortcutKeys': {
'appendsiblingnode': 'normal::Enter', 'appendsiblingnode': 'normal::Enter',
'appendchildnode': 'normal::Insert|Tab', 'appendchildnode': 'normal::Insert|Tab',
'editnode': 'normal::F2', 'appendparentnode': 'normal::Shift+Tab|normal::Shift+Insert',
'removenode': 'normal::Del|Backspace' 'removenode': 'normal::Del|Backspace'
} }
}; };
......
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