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 @@ ...@@ -59,6 +59,7 @@
'module/zoom.js', 'module/zoom.js',
'module/hyperlink.js', 'module/hyperlink.js',
'module/arrange.js', 'module/arrange.js',
'module/paste.js',
'ui/jquery-ui-1.10.4.custom.min.js', 'ui/jquery-ui-1.10.4.custom.min.js',
'ui/widget.js', 'ui/widget.js',
'ui/button.js', 'ui/button.js',
......
...@@ -51,9 +51,11 @@ var keymap = KityMinder.keymap = (function(origin) { ...@@ -51,9 +51,11 @@ var keymap = KityMinder.keymap = (function(origin) {
//回退 //回退
'z': 90, 'z': 90,
'y': 89, 'y': 89,
//粘贴
//复制粘贴
'v': 86, 'v': 86,
'x': 88, 'x': 88,
'c': 67,
's': 83, 's': 83,
......
...@@ -40,6 +40,7 @@ kity.extendClass(Minder, { ...@@ -40,6 +40,7 @@ kity.extendClass(Minder, {
handelNodeCreate: function(node) { handelNodeCreate: function(node) {
var rc = this._rc; var rc = this._rc;
node.traverse(function(current) { node.traverse(function(current) {
current.attached = true;
rc.addShape(current.getRenderContainer()); rc.addShape(current.getRenderContainer());
}); });
rc.addShape(node.getRenderContainer()); rc.addShape(node.getRenderContainer());
...@@ -48,6 +49,7 @@ kity.extendClass(Minder, { ...@@ -48,6 +49,7 @@ kity.extendClass(Minder, {
handelNodeRemove: function(node) { handelNodeRemove: function(node) {
var rc = this._rc; var rc = this._rc;
node.traverse(function(current) { node.traverse(function(current) {
current.attached = false;
rc.removeShape(current.getRenderContainer()); rc.removeShape(current.getRenderContainer());
}); });
}, },
...@@ -60,6 +62,6 @@ kity.extendClass(Minder, { ...@@ -60,6 +62,6 @@ kity.extendClass(Minder, {
kity.extendClass(MinderNode, { kity.extendClass(MinderNode, {
getMinder: function() { getMinder: function() {
return this.root.minder; return this.getRoot().minder;
} }
}); });
\ No newline at end of file
...@@ -81,14 +81,14 @@ kity.extendClass(Minder, { ...@@ -81,14 +81,14 @@ kity.extendClass(Minder, {
return this._selectedNodes.length == 1; return this._selectedNodes.length == 1;
}, },
getSelectedAncestors: function() { getSelectedAncestors: function(includeRoot) {
var nodes = this.getSelectedNodes().slice(0), var nodes = this.getSelectedNodes().slice(0),
ancestors = [], ancestors = [],
judge; judge;
// 根节点不参与计算 // 根节点不参与计算
var rootIndex = nodes.indexOf(this.getRoot()); var rootIndex = nodes.indexOf(this.getRoot());
if (~rootIndex) { if (~rootIndex && !includeRoot) {
nodes.splice(rootIndex, 1); nodes.splice(rootIndex, 1);
} }
......
...@@ -185,6 +185,7 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', { ...@@ -185,6 +185,7 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', {
if (index >= 0) { if (index >= 0) {
removed = this.children.splice(index, 1)[0]; removed = this.children.splice(index, 1)[0];
removed.parent = null; removed.parent = null;
removed.root = removed;
} }
}, },
...@@ -255,22 +256,49 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', { ...@@ -255,22 +256,49 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', {
return cloneNode(null, this); 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) { if (node.children.length != this.children.length) {
restoreSelected();
return false; return false;
} }
if (utils.compareObject(node.getData(), this.getData()) === false) { if (utils.compareObject(node.getData(), me.getData()) === false) {
restoreSelected();
return false; return false;
} }
if (utils.compareObject(node.getTmpData(), this.getTmpData()) === false) { if (utils.compareObject(node.getTmpData(), me.getTmpData()) === false) {
restoreSelected();
return false; return false;
} }
for (var i = 0, ci; for (var i = 0, ci;
(ci = this.children[i]); i++) { (ci = me.children[i]); i++) {
if (ci.equals(node.children[i]) === false) { if (ci.equals(node.children[i],ignoreSelected) === false) {
restoreSelected();
return false; return false;
} }
} }
restoreSelected();
return true; return true;
}, },
......
...@@ -27,6 +27,7 @@ var Renderer = KityMinder.Renderer = kity.createClass('Renderer', { ...@@ -27,6 +27,7 @@ var Renderer = KityMinder.Renderer = kity.createClass('Renderer', {
kity.extendClass(Minder, { kity.extendClass(Minder, {
_createRendererForNode: function(node) { _createRendererForNode: function(node) {
var registered = this._renderers; var registered = this._renderers;
var renderers = []; var renderers = [];
...@@ -48,6 +49,7 @@ kity.extendClass(Minder, { ...@@ -48,6 +49,7 @@ kity.extendClass(Minder, {
}, },
renderNode: function(node) { renderNode: function(node) {
var rendererClasses = this._renderers; var rendererClasses = this._renderers;
var g = KityMinder.Geometry; var g = KityMinder.Geometry;
var i, latestBox, renderer; var i, latestBox, renderer;
...@@ -107,6 +109,7 @@ kity.extendClass(Minder, { ...@@ -107,6 +109,7 @@ kity.extendClass(Minder, {
kity.extendClass(MinderNode, { kity.extendClass(MinderNode, {
render: function() { render: function() {
if (!this.attached) return;
this.getMinder().renderNode(this); this.getMinder().renderNode(this);
return this; return this;
}, },
......
...@@ -268,6 +268,9 @@ var utils = Utils = KityMinder.Utils = { ...@@ -268,6 +268,9 @@ var utils = Utils = KityMinder.Utils = {
}[a] }[a]
} }
}) : ''; }) : '';
},
cloneArr:function(arr){
return [].concat(arr);
} }
}; };
......
...@@ -14,27 +14,8 @@ KityMinder.registerModule("HistoryModule", function() { ...@@ -14,27 +14,8 @@ KityMinder.registerModule("HistoryModule", function() {
return this.getData().clone(); return this.getData().clone();
}, },
equals: function(scene) { equals: function(scene) {
var nodeA = scene.getData(),isSelectedA = false; return this.getData().equals(scene.getData());
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();
}
if(isSelectedB){
nodeB.setSelectedFlag();
}
return result;
}, },
isInputStatus:function(){ isInputStatus:function(){
return this.inputStatus; return this.inputStatus;
...@@ -110,7 +91,9 @@ KityMinder.registerModule("HistoryModule", function() { ...@@ -110,7 +91,9 @@ KityMinder.registerModule("HistoryModule", function() {
} }
km.appendNode(child,parent); km.appendNode(child,parent);
child.render(); 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); appendChildNode(child, ci);
} }
} }
...@@ -140,8 +123,10 @@ KityMinder.registerModule("HistoryModule", function() { ...@@ -140,8 +123,10 @@ KityMinder.registerModule("HistoryModule", function() {
traverseNode(km.getRoot(), target); traverseNode(km.getRoot(), target);
km.layout(); km.layout();
km.select(selectedNodes,true); km.select(selectedNodes,true);
selectedNodes = [];
}, },
restore: function(index) { restore: function(index) {
......
KityMinder.registerModule( "pasteModule", function () { KityMinder.registerModule( "pasteModule", function () {
var km = this; var km = this,
//getSelectedTopNodes
_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 { 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