Commit c0f3895f authored by campaign's avatar campaign

添加粘贴剪贴节点功能

parent 50d3aa4b
......@@ -59,6 +59,7 @@
'module/zoom.js',
'module/hyperlink.js',
'module/arrange.js',
'module/paste.js',
'ui/jquery-ui-1.10.4.custom.min.js',
'ui/widget.js',
'ui/button.js',
......
......@@ -51,9 +51,11 @@ var keymap = KityMinder.keymap = (function(origin) {
//回退
'z': 90,
'y': 89,
//粘贴
//复制粘贴
'v': 86,
'x': 88,
'c': 67,
's': 83,
......
......@@ -60,6 +60,6 @@ kity.extendClass(Minder, {
kity.extendClass(MinderNode, {
getMinder: function() {
return this.root.minder;
return this.getRoot().minder;
}
});
\ No newline at end of file
......@@ -81,14 +81,14 @@ kity.extendClass(Minder, {
return this._selectedNodes.length == 1;
},
getSelectedAncestors: function() {
getSelectedAncestors: function(includeRoot) {
var nodes = this.getSelectedNodes().slice(0),
ancestors = [],
judge;
// 根节点不参与计算
var rootIndex = nodes.indexOf(this.getRoot());
if (~rootIndex) {
if (~rootIndex && !includeRoot) {
nodes.splice(rootIndex, 1);
}
......
......@@ -268,6 +268,9 @@ var utils = Utils = KityMinder.Utils = {
}[a]
}
}) : '';
},
cloneArr:function(arr){
return [].concat(arr);
}
};
......
......@@ -91,7 +91,9 @@ KityMinder.registerModule("HistoryModule", function() {
}
km.appendNode(child,parent);
child.render();
for (var i = 0, ci; ci = child.children[i++];) {
var children = utils.cloneArr(child.children);
for (var i = 0, ci; ci = children[i++];) {
appendChildNode(child, ci);
}
}
......@@ -122,7 +124,7 @@ KityMinder.registerModule("HistoryModule", function() {
traverseNode(km.getRoot(), target);
km.layout();
km.select(selectedNodes,true);
selectedNodes = [];
},
restore: function(index) {
......
KityMinder.registerModule( "pasteModule", function () {
var km = this;
//getSelectedTopNodes
var km = this,
_cacheNodes = [],
_selectedNodes = [],
_copystatus= false,
_curstatus = false;
function appendChildNode(parent, child) {
_selectedNodes.push(child);
km.appendNode(child,parent);
child.render();
child.setLayoutOffset(null);
var children = utils.cloneArr(child.children);
for (var i = 0, ci; ci = children[i++]; ) {
appendChildNode(child, ci);
}
}
function getNodes(arr,isCut){
_cacheNodes = [];
for(var i= 0,ni;ni=arr[i++];){
_cacheNodes.push(ni.clone());
if(isCut && !ni.isRoot()){
km.removeNode(ni);
}
}
}
return {
'events': {
'normal.keydown': function (e) {
var keys = KityMinder.keymap;
var keyEvent = e.originEvent;
if (keyEvent.ctrlKey || keyEvent.metaKey) {
switch (keyEvent.keyCode) {
case keys.c:
getNodes(km.getSelectedAncestors(true));
_copystatus = true;
break;
case keys.x:
getNodes(km.getSelectedAncestors(),true);
_curstatus = true;
break;
case keys.v:
if(_cacheNodes.length){
var node = km.getSelectedNode();
if(node){
km.fire('saveScene');
for(var i= 0,ni;ni=_cacheNodes[i++];){
appendChildNode(node,ni);
}
km.layout(300);
km.select(_selectedNodes,true);
_selectedNodes = [];
km.fire('saveScene');
}
}
}
}
}
}
};
} );
\ 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