mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 14:17:57 +01:00
fixing undo/redo when reparenting nodes
This commit is contained in:
parent
4a93b1b80d
commit
9499f579b9
@ -48,6 +48,7 @@ mindplot.commands.freeMind.ReconnectTopicCommand = mindplot.Command.extend(
|
||||
var oldParent = commandContext.findTopics(parseInt(this._oldParent))[0];
|
||||
node.relationship = this._relationship;
|
||||
node._relationship_oldParent = oldParent;
|
||||
node._relationship_index = this._index;
|
||||
commandContext.disconnect(node);
|
||||
var parentNode = targetNode;
|
||||
if(this._relationship != "Child"){
|
||||
@ -58,6 +59,7 @@ mindplot.commands.freeMind.ReconnectTopicCommand = mindplot.Command.extend(
|
||||
delete node.relationship;
|
||||
delete node._relationship_oldParent;
|
||||
delete node._relationship_sibling_node;
|
||||
delete node._relationship_index;
|
||||
},
|
||||
undoExecute: function(commandContext)
|
||||
{
|
||||
@ -76,23 +78,29 @@ mindplot.commands.freeMind.ReconnectTopicCommand = mindplot.Command.extend(
|
||||
topic.setPosition(pos.clone(), true);
|
||||
}
|
||||
if(id = this._node){
|
||||
node._originalPosition = modTopic.originalPos;
|
||||
node._originalPosition = modTopic.newPos;
|
||||
}
|
||||
}
|
||||
var oldParent = commandContext.findTopics(parseInt(this._targetNode))[0];
|
||||
node.relationship = this._relationship;
|
||||
if(this._relationship != "Child"){
|
||||
oldParent = oldParent.getParent();
|
||||
}
|
||||
node.relationship = "undo";
|
||||
node._relationship_oldParent = oldParent;
|
||||
node._relationship_index = this._index;
|
||||
commandContext.disconnect(node);
|
||||
commandContext.connect(node, targetNode);
|
||||
delete node.relationship;
|
||||
delete node._relationship_oldParent;
|
||||
delete node._relationship_index;
|
||||
},
|
||||
setModifiedTopics:function(modifiedTopics){
|
||||
this._modifiedTopics = modifiedTopics;
|
||||
},
|
||||
setDraggedTopic:function(node){
|
||||
setDraggedTopic:function(node, index){
|
||||
this._node = node.getId();
|
||||
this._oldParent = node.getOutgoingConnectedTopic().getId();
|
||||
this._index = index;
|
||||
},
|
||||
setTargetNode:function(node){
|
||||
this._targetNode = node.getId();
|
||||
|
@ -278,6 +278,9 @@ mindplot.layoutManagers.FreeMindLayoutManager = mindplot.layoutManagers.BaseLayo
|
||||
this._mouseOverListeners = new Hash();
|
||||
this._mouseOutListeners = new Hash();
|
||||
|
||||
var board = this.getTopicBoardForTopic(topic.getParent());
|
||||
this._currentIndex = board.findNodeEntryIndex(topic).index;
|
||||
|
||||
var topics = this.getDesigner()._getTopics();
|
||||
// Disable all mouse events.
|
||||
for (var i = 0; i < topics.length; i++)
|
||||
@ -377,6 +380,33 @@ mindplot.layoutManagers.FreeMindLayoutManager = mindplot.layoutManagers.BaseLayo
|
||||
|
||||
this._removeIndicatorShapes(node);
|
||||
|
||||
//Check that it has to be relocated
|
||||
if(this._createShape !=null){
|
||||
if(this._createShape == "Child"){
|
||||
if(node.getParent().getId() == this._targetNode.getId()){
|
||||
var mod = this._modifiedTopics.get(node.getId());
|
||||
if(Math.sign(mod.originalPos.x) == Math.sign(node.getPosition().x))
|
||||
this._createShape = null;
|
||||
}
|
||||
}else if(node.getParent().getId() == this._targetNode.getParent().getId()){
|
||||
var chkboard = this.getTopicBoardForTopic(this._targetNode.getParent());
|
||||
var chk = chkboard.findNodeEntryIndex(node);
|
||||
if(this._createShape == "Sibling_top"){
|
||||
if(chk.table>this._currentIndex+1){
|
||||
var nextEntry = chk.table[this._currentIndex+1];
|
||||
if(nextEntry.getNode().getId() == this._targetNode.getId()){
|
||||
this._createShape = null;
|
||||
}
|
||||
}
|
||||
} else if(this._currentIndex>0){
|
||||
var prevEntry = chk.table[this._currentIndex-1];
|
||||
if(prevEntry.getNode().getId() == this._targetNode.getId()){
|
||||
this._createShape = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(this._createShape == null){
|
||||
//cancel everything.
|
||||
var line = node.getOutgoingLine();
|
||||
@ -386,7 +416,7 @@ mindplot.layoutManagers.FreeMindLayoutManager = mindplot.layoutManagers.BaseLayo
|
||||
core.Utils.animatePosition(this._modifiedTopics, null, this.getDesigner());
|
||||
}else{
|
||||
this._command.setModifiedTopics(this._modifiedTopics);
|
||||
this._command.setDraggedTopic(node);
|
||||
this._command.setDraggedTopic(node, this._currentIndex);
|
||||
this._command.setTargetNode(this._targetNode);
|
||||
this._command.setAs(this._createShape);
|
||||
//todo:Create command
|
||||
@ -513,58 +543,73 @@ mindplot.layoutManagers.FreeMindLayoutManager = mindplot.layoutManagers.BaseLayo
|
||||
entryObj = parentBoard.findNodeEntryIndex(node);
|
||||
}
|
||||
var entry = entryObj.table[entryObj.index];
|
||||
parentBoard._removeEntry(node, entryObj.table, entryObj.index, this._modifiedTopics);
|
||||
parentBoard._removeEntry(node, entryObj.table, entryObj.index, []);
|
||||
var targetBoard = this.getTopicBoardForTopic(targetNode);
|
||||
var table = targetBoard._getTableForNode(node);
|
||||
var index;
|
||||
if(node.relationship == "Child"){
|
||||
if(node.relationship == 'undo'){
|
||||
index = node._relationship_index;
|
||||
//I need to update all entries because nodes position have been changed by command
|
||||
|
||||
var newNodePos=new core.Point();
|
||||
if(table.length>0){
|
||||
//if no children use the position set by Entry initializer. Otherwise place as last child
|
||||
var lastChild = table[table.length-1];
|
||||
newNodePos.y = lastChild.getPosition()+lastChild.getTotalMarginBottom() + entry.getTotalMarginTop();
|
||||
}else{
|
||||
if(node.relationship == "Child"){
|
||||
|
||||
var newNodePos=new core.Point();
|
||||
if(table.length>0){
|
||||
//if no children use the position set by Entry initializer. Otherwise place as last child
|
||||
var lastChild = table[table.length-1];
|
||||
newNodePos.y = lastChild.getPosition()+lastChild.getTotalMarginBottom() + entry.getTotalMarginTop();
|
||||
} else {
|
||||
newNodePos.y = targetNode.getPosition().y;
|
||||
}
|
||||
var parentPos = targetNode.getPosition();
|
||||
var pwidth = targetNode.getSize().width;
|
||||
var width = node.getSize().width;
|
||||
if(this._isCentralTopic(targetNode)){
|
||||
newNodePos.x = Math.sign(node.getPosition().x) * (entry._DEFAULT_X_GAP + pwidth/2 + width/2)
|
||||
}
|
||||
else{
|
||||
newNodePos.x = parentPos.x + Math.sign(parentPos.x) * (entry._DEFAULT_X_GAP + pwidth/2 + width/2);
|
||||
}
|
||||
|
||||
index = table.length;
|
||||
} else {
|
||||
newNodePos.y = targetNode.getPosition().y;
|
||||
}
|
||||
var parentPos = targetNode.getPosition();
|
||||
var pwidth = targetNode.getSize().width;
|
||||
var width = node.getSize().width;
|
||||
if(this._isCentralTopic(targetNode)){
|
||||
newNodePos.x = Math.sign(node.getPosition().x) * (entry._DEFAULT_X_GAP + pwidth/2 + width/2)
|
||||
}
|
||||
else{
|
||||
newNodePos.x = parentPos.x + Math.sign(parentPos.x) * (entry._DEFAULT_X_GAP + pwidth/2 + width/2);
|
||||
}
|
||||
//moving as sibling of targetNode
|
||||
|
||||
index = table.length;
|
||||
} else {
|
||||
//moving as sibling of targetNode
|
||||
var sibObj = targetBoard.findNodeEntryIndex(node._relationship_sibling_node);
|
||||
var siblingEntry =sibObj.table[sibObj.index];
|
||||
|
||||
var sibObj = targetBoard.findNodeEntryIndex(node._relationship_sibling_node);
|
||||
var siblingEntry =sibObj.table[sibObj.index];
|
||||
|
||||
var newNodePos=new core.Point();
|
||||
if(node.relationship == "Sibling_top"){
|
||||
newNodePos.y =siblingEntry.getPosition()-siblingEntry.getTotalMarginTop()+entry.getTotalMarginTop();
|
||||
index = sibObj.index==0?0:sibObj.index-1;
|
||||
var newNodePos=new core.Point();
|
||||
if(node.relationship == "Sibling_top"){
|
||||
if(sibObj.index==0){
|
||||
newNodePos.y = siblingEntry.getPosition();
|
||||
index = 0;
|
||||
}else{
|
||||
newNodePos.y =siblingEntry.getPosition()-siblingEntry.getTotalMarginTop()+entry.getTotalMarginTop();
|
||||
index = sibObj.index-1;
|
||||
}
|
||||
}
|
||||
else{
|
||||
newNodePos.y = siblingEntry.getPosition()+siblingEntry.getTotalMarginBottom() + entry.getTotalMarginTop();
|
||||
index = sibObj.index+1;
|
||||
}
|
||||
var parentPos = targetNode.getPosition();
|
||||
var pwidth = targetNode.getSize().width;
|
||||
var width = node.getSize().width;
|
||||
if(this._isCentralTopic(targetNode)){
|
||||
newNodePos.x = Math.sign(node.getPosition().x) * (entry._DEFAULT_X_GAP + pwidth/2 + width/2)
|
||||
}
|
||||
else{
|
||||
newNodePos.x = parentPos.x + Math.sign(parentPos.x) * (entry._DEFAULT_X_GAP + pwidth/2 + width/2);
|
||||
}
|
||||
}
|
||||
else{
|
||||
newNodePos.y = siblingEntry.getPosition()+siblingEntry.getTotalMarginBottom() + entry.getTotalMarginTop();
|
||||
index = sibObj.index+1;
|
||||
}
|
||||
var parentPos = targetNode.getPosition();
|
||||
var pwidth = targetNode.getSize().width;
|
||||
var width = node.getSize().width;
|
||||
newNodePos.x = parentPos.x + Math.sign(parentPos.x) * (entry._DEFAULT_X_GAP + pwidth/2 + width/2);
|
||||
var nodePos = node.getPosition();
|
||||
var x = nodePos.x - newNodePos.x;
|
||||
var y = nodePos.y - newNodePos.y;
|
||||
var delta = new core.Point(Math.round(x), Math.round(y));
|
||||
entry.setPosition(newNodePos.x, newNodePos.y);
|
||||
this._updateChildrenBoards(node, delta, []);
|
||||
}
|
||||
var nodePos = node.getPosition();
|
||||
var x = nodePos.x - newNodePos.x;
|
||||
var y = nodePos.y - newNodePos.y;
|
||||
var delta = new core.Point(Math.round(x), Math.round(y));
|
||||
entry.setPosition(newNodePos.x, newNodePos.y);
|
||||
this._updateChildrenBoards(node, delta, this._modifiedTopics);
|
||||
|
||||
targetBoard._addEntry(entry, table, index);
|
||||
targetBoard._updateTable(index, table, [], true);
|
||||
this._updateBoard(targetNode,[]);
|
||||
|
@ -18,7 +18,6 @@ mindplot.layoutManagers.boards.freeMindBoards.Entry = new Class({
|
||||
|
||||
}
|
||||
}
|
||||
this._position = pos.y;
|
||||
this._DEFAULT_GAP = 10;
|
||||
var height = this.getNode().getSize().height;
|
||||
this._minimalMargin = this._DEFAULT_GAP + height/2;
|
||||
@ -34,7 +33,7 @@ mindplot.layoutManagers.boards.freeMindBoards.Entry = new Class({
|
||||
return this.getNode().getId();
|
||||
},
|
||||
getPosition:function(){
|
||||
return this._position;
|
||||
return this._node.getPosition().y;
|
||||
},
|
||||
setPosition:function(x,y){
|
||||
var position = this._node.getPosition().clone();
|
||||
@ -44,7 +43,6 @@ mindplot.layoutManagers.boards.freeMindBoards.Entry = new Class({
|
||||
}
|
||||
|
||||
this._node.setPosition(position, false);
|
||||
this._position = y;
|
||||
},
|
||||
getMarginTop:function(){
|
||||
return this._marginTop;
|
||||
|
Loading…
Reference in New Issue
Block a user