Commit 9f991aea authored by techird's avatar techird

Merge branch 'dev' of github.com:fex-team/kityminder into dev

parents 7094dbce fbb1b81e
......@@ -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,
......
......@@ -40,6 +40,7 @@ kity.extendClass(Minder, {
handelNodeCreate: function(node) {
var rc = this._rc;
node.traverse(function(current) {
current.attached = true;
rc.addShape(current.getRenderContainer());
});
rc.addShape(node.getRenderContainer());
......@@ -48,6 +49,7 @@ kity.extendClass(Minder, {
handelNodeRemove: function(node) {
var rc = this._rc;
node.traverse(function(current) {
current.attached = false;
rc.removeShape(current.getRenderContainer());
});
},
......@@ -60,6 +62,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);
}
......
......@@ -185,6 +185,7 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', {
if (index >= 0) {
removed = this.children.splice(index, 1)[0];
removed.parent = null;
removed.root = removed;
}
},
......@@ -255,22 +256,49 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', {
return cloneNode(null, this);
},
equals: function(node) {
equals: function(node,ignoreSelected) {
var me = this;
function restoreSelected(){
if(isSelectedA){
me.setSelectedFlag();
}
if(isSelectedB){
node.setSelectedFlag();
}
}
if(ignoreSelected){
var isSelectedA = false;
var isSelectedB = false;
if(me.isSelected()){
isSelectedA = true;
me.clearSelectedFlag();
}
if(node.isSelected()){
isSelectedB = true;
node.clearSelectedFlag();
}
}
if (node.children.length != this.children.length) {
restoreSelected();
return false;
}
if (utils.compareObject(node.getData(), this.getData()) === false) {
if (utils.compareObject(node.getData(), me.getData()) === false) {
restoreSelected();
return false;
}
if (utils.compareObject(node.getTmpData(), this.getTmpData()) === false) {
if (utils.compareObject(node.getTmpData(), me.getTmpData()) === false) {
restoreSelected();
return false;
}
for (var i = 0, ci;
(ci = this.children[i]); i++) {
if (ci.equals(node.children[i]) === false) {
(ci = me.children[i]); i++) {
if (ci.equals(node.children[i],ignoreSelected) === false) {
restoreSelected();
return false;
}
}
restoreSelected();
return true;
},
......
......@@ -27,6 +27,7 @@ var Renderer = KityMinder.Renderer = kity.createClass('Renderer', {
kity.extendClass(Minder, {
_createRendererForNode: function(node) {
var registered = this._renderers;
var renderers = [];
......@@ -48,6 +49,7 @@ kity.extendClass(Minder, {
},
renderNode: function(node) {
var rendererClasses = this._renderers;
var g = KityMinder.Geometry;
var i, latestBox, renderer;
......@@ -107,6 +109,7 @@ kity.extendClass(Minder, {
kity.extendClass(MinderNode, {
render: function() {
if (!this.attached) return;
this.getMinder().renderNode(this);
return this;
},
......
......@@ -268,6 +268,9 @@ var utils = Utils = KityMinder.Utils = {
}[a]
}
}) : '';
},
cloneArr:function(arr){
return [].concat(arr);
}
};
......
......@@ -14,27 +14,8 @@ KityMinder.registerModule("HistoryModule", function() {
return this.getData().clone();
},
equals: function(scene) {
var nodeA = scene.getData(),isSelectedA = false;
var nodeB = this.getData(),isSelectedB = false;
if(nodeA.isSelected()){
isSelectedA = true;
nodeA.clearSelectedFlag();
}
if(nodeB.isSelected()){
isSelectedB = true;
nodeB.clearSelectedFlag();
}
var result = nodeB.equals(nodeA);
if(isSelectedA){
nodeA.setSelectedFlag();
}
return this.getData().equals(scene.getData());
if(isSelectedB){
nodeB.setSelectedFlag();
}
return result;
},
isInputStatus:function(){
return this.inputStatus;
......@@ -110,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);
}
}
......@@ -140,8 +123,10 @@ 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