mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-25 23:44:54 +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];
|
var oldParent = commandContext.findTopics(parseInt(this._oldParent))[0];
|
||||||
node.relationship = this._relationship;
|
node.relationship = this._relationship;
|
||||||
node._relationship_oldParent = oldParent;
|
node._relationship_oldParent = oldParent;
|
||||||
|
node._relationship_index = this._index;
|
||||||
commandContext.disconnect(node);
|
commandContext.disconnect(node);
|
||||||
var parentNode = targetNode;
|
var parentNode = targetNode;
|
||||||
if(this._relationship != "Child"){
|
if(this._relationship != "Child"){
|
||||||
@ -58,6 +59,7 @@ mindplot.commands.freeMind.ReconnectTopicCommand = mindplot.Command.extend(
|
|||||||
delete node.relationship;
|
delete node.relationship;
|
||||||
delete node._relationship_oldParent;
|
delete node._relationship_oldParent;
|
||||||
delete node._relationship_sibling_node;
|
delete node._relationship_sibling_node;
|
||||||
|
delete node._relationship_index;
|
||||||
},
|
},
|
||||||
undoExecute: function(commandContext)
|
undoExecute: function(commandContext)
|
||||||
{
|
{
|
||||||
@ -76,23 +78,29 @@ mindplot.commands.freeMind.ReconnectTopicCommand = mindplot.Command.extend(
|
|||||||
topic.setPosition(pos.clone(), true);
|
topic.setPosition(pos.clone(), true);
|
||||||
}
|
}
|
||||||
if(id = this._node){
|
if(id = this._node){
|
||||||
node._originalPosition = modTopic.originalPos;
|
node._originalPosition = modTopic.newPos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var oldParent = commandContext.findTopics(parseInt(this._targetNode))[0];
|
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_oldParent = oldParent;
|
||||||
|
node._relationship_index = this._index;
|
||||||
commandContext.disconnect(node);
|
commandContext.disconnect(node);
|
||||||
commandContext.connect(node, targetNode);
|
commandContext.connect(node, targetNode);
|
||||||
delete node.relationship;
|
delete node.relationship;
|
||||||
delete node._relationship_oldParent;
|
delete node._relationship_oldParent;
|
||||||
|
delete node._relationship_index;
|
||||||
},
|
},
|
||||||
setModifiedTopics:function(modifiedTopics){
|
setModifiedTopics:function(modifiedTopics){
|
||||||
this._modifiedTopics = modifiedTopics;
|
this._modifiedTopics = modifiedTopics;
|
||||||
},
|
},
|
||||||
setDraggedTopic:function(node){
|
setDraggedTopic:function(node, index){
|
||||||
this._node = node.getId();
|
this._node = node.getId();
|
||||||
this._oldParent = node.getOutgoingConnectedTopic().getId();
|
this._oldParent = node.getOutgoingConnectedTopic().getId();
|
||||||
|
this._index = index;
|
||||||
},
|
},
|
||||||
setTargetNode:function(node){
|
setTargetNode:function(node){
|
||||||
this._targetNode = node.getId();
|
this._targetNode = node.getId();
|
||||||
|
@ -278,6 +278,9 @@ mindplot.layoutManagers.FreeMindLayoutManager = mindplot.layoutManagers.BaseLayo
|
|||||||
this._mouseOverListeners = new Hash();
|
this._mouseOverListeners = new Hash();
|
||||||
this._mouseOutListeners = new Hash();
|
this._mouseOutListeners = new Hash();
|
||||||
|
|
||||||
|
var board = this.getTopicBoardForTopic(topic.getParent());
|
||||||
|
this._currentIndex = board.findNodeEntryIndex(topic).index;
|
||||||
|
|
||||||
var topics = this.getDesigner()._getTopics();
|
var topics = this.getDesigner()._getTopics();
|
||||||
// Disable all mouse events.
|
// Disable all mouse events.
|
||||||
for (var i = 0; i < topics.length; i++)
|
for (var i = 0; i < topics.length; i++)
|
||||||
@ -377,6 +380,33 @@ mindplot.layoutManagers.FreeMindLayoutManager = mindplot.layoutManagers.BaseLayo
|
|||||||
|
|
||||||
this._removeIndicatorShapes(node);
|
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){
|
if(this._createShape == null){
|
||||||
//cancel everything.
|
//cancel everything.
|
||||||
var line = node.getOutgoingLine();
|
var line = node.getOutgoingLine();
|
||||||
@ -386,7 +416,7 @@ mindplot.layoutManagers.FreeMindLayoutManager = mindplot.layoutManagers.BaseLayo
|
|||||||
core.Utils.animatePosition(this._modifiedTopics, null, this.getDesigner());
|
core.Utils.animatePosition(this._modifiedTopics, null, this.getDesigner());
|
||||||
}else{
|
}else{
|
||||||
this._command.setModifiedTopics(this._modifiedTopics);
|
this._command.setModifiedTopics(this._modifiedTopics);
|
||||||
this._command.setDraggedTopic(node);
|
this._command.setDraggedTopic(node, this._currentIndex);
|
||||||
this._command.setTargetNode(this._targetNode);
|
this._command.setTargetNode(this._targetNode);
|
||||||
this._command.setAs(this._createShape);
|
this._command.setAs(this._createShape);
|
||||||
//todo:Create command
|
//todo:Create command
|
||||||
@ -513,58 +543,73 @@ mindplot.layoutManagers.FreeMindLayoutManager = mindplot.layoutManagers.BaseLayo
|
|||||||
entryObj = parentBoard.findNodeEntryIndex(node);
|
entryObj = parentBoard.findNodeEntryIndex(node);
|
||||||
}
|
}
|
||||||
var entry = entryObj.table[entryObj.index];
|
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 targetBoard = this.getTopicBoardForTopic(targetNode);
|
||||||
var table = targetBoard._getTableForNode(node);
|
var table = targetBoard._getTableForNode(node);
|
||||||
var index;
|
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();
|
}else{
|
||||||
if(table.length>0){
|
if(node.relationship == "Child"){
|
||||||
//if no children use the position set by Entry initializer. Otherwise place as last child
|
|
||||||
var lastChild = table[table.length-1];
|
var newNodePos=new core.Point();
|
||||||
newNodePos.y = lastChild.getPosition()+lastChild.getTotalMarginBottom() + entry.getTotalMarginTop();
|
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 {
|
} else {
|
||||||
newNodePos.y = targetNode.getPosition().y;
|
//moving as sibling of targetNode
|
||||||
}
|
|
||||||
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;
|
var sibObj = targetBoard.findNodeEntryIndex(node._relationship_sibling_node);
|
||||||
} else {
|
var siblingEntry =sibObj.table[sibObj.index];
|
||||||
//moving as sibling of targetNode
|
|
||||||
|
|
||||||
var sibObj = targetBoard.findNodeEntryIndex(node._relationship_sibling_node);
|
var newNodePos=new core.Point();
|
||||||
var siblingEntry =sibObj.table[sibObj.index];
|
if(node.relationship == "Sibling_top"){
|
||||||
|
if(sibObj.index==0){
|
||||||
var newNodePos=new core.Point();
|
newNodePos.y = siblingEntry.getPosition();
|
||||||
if(node.relationship == "Sibling_top"){
|
index = 0;
|
||||||
newNodePos.y =siblingEntry.getPosition()-siblingEntry.getTotalMarginTop()+entry.getTotalMarginTop();
|
}else{
|
||||||
index = sibObj.index==0?0:sibObj.index-1;
|
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{
|
var nodePos = node.getPosition();
|
||||||
newNodePos.y = siblingEntry.getPosition()+siblingEntry.getTotalMarginBottom() + entry.getTotalMarginTop();
|
var x = nodePos.x - newNodePos.x;
|
||||||
index = sibObj.index+1;
|
var y = nodePos.y - newNodePos.y;
|
||||||
}
|
var delta = new core.Point(Math.round(x), Math.round(y));
|
||||||
var parentPos = targetNode.getPosition();
|
entry.setPosition(newNodePos.x, newNodePos.y);
|
||||||
var pwidth = targetNode.getSize().width;
|
this._updateChildrenBoards(node, delta, []);
|
||||||
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, this._modifiedTopics);
|
|
||||||
|
|
||||||
targetBoard._addEntry(entry, table, index);
|
targetBoard._addEntry(entry, table, index);
|
||||||
targetBoard._updateTable(index, table, [], true);
|
targetBoard._updateTable(index, table, [], true);
|
||||||
this._updateBoard(targetNode,[]);
|
this._updateBoard(targetNode,[]);
|
||||||
|
@ -18,7 +18,6 @@ mindplot.layoutManagers.boards.freeMindBoards.Entry = new Class({
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._position = pos.y;
|
|
||||||
this._DEFAULT_GAP = 10;
|
this._DEFAULT_GAP = 10;
|
||||||
var height = this.getNode().getSize().height;
|
var height = this.getNode().getSize().height;
|
||||||
this._minimalMargin = this._DEFAULT_GAP + height/2;
|
this._minimalMargin = this._DEFAULT_GAP + height/2;
|
||||||
@ -34,7 +33,7 @@ mindplot.layoutManagers.boards.freeMindBoards.Entry = new Class({
|
|||||||
return this.getNode().getId();
|
return this.getNode().getId();
|
||||||
},
|
},
|
||||||
getPosition:function(){
|
getPosition:function(){
|
||||||
return this._position;
|
return this._node.getPosition().y;
|
||||||
},
|
},
|
||||||
setPosition:function(x,y){
|
setPosition:function(x,y){
|
||||||
var position = this._node.getPosition().clone();
|
var position = this._node.getPosition().clone();
|
||||||
@ -44,7 +43,6 @@ mindplot.layoutManagers.boards.freeMindBoards.Entry = new Class({
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._node.setPosition(position, false);
|
this._node.setPosition(position, false);
|
||||||
this._position = y;
|
|
||||||
},
|
},
|
||||||
getMarginTop:function(){
|
getMarginTop:function(){
|
||||||
return this._marginTop;
|
return this._marginTop;
|
||||||
|
Loading…
Reference in New Issue
Block a user