mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 14:17:57 +01:00
adding support for independent topics in freemind layout
This commit is contained in:
parent
9532c95831
commit
75564c17ec
@ -1193,6 +1193,8 @@ mindplot.Topic.prototype.disconnect = function(workspace)
|
|||||||
var childModel = this.getModel();
|
var childModel = this.getModel();
|
||||||
childModel.disconnect();
|
childModel.disconnect();
|
||||||
|
|
||||||
|
this._parent = null;
|
||||||
|
|
||||||
// Remove graphical element from the workspace...
|
// Remove graphical element from the workspace...
|
||||||
outgoingLine.removeFromWorkspace(workspace);
|
outgoingLine.removeFromWorkspace(workspace);
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ mindplot.commands.freeMind.ReconnectTopicCommand = mindplot.Command.extend(
|
|||||||
node._originalPosition = modTopic.originalPos;
|
node._originalPosition = modTopic.originalPos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var oldParent = commandContext.findTopics(parseInt(this._oldParent))[0];
|
var oldParent = this._oldParent!=null?commandContext.findTopics(parseInt(this._oldParent))[0]:null;
|
||||||
node.relationship = this._relationship;
|
node.relationship = this._relationship;
|
||||||
node._relationship_oldParent = oldParent;
|
node._relationship_oldParent = oldParent;
|
||||||
node._relationship_index = this._index;
|
node._relationship_index = this._index;
|
||||||
@ -60,11 +60,12 @@ mindplot.commands.freeMind.ReconnectTopicCommand = mindplot.Command.extend(
|
|||||||
delete node._relationship_oldParent;
|
delete node._relationship_oldParent;
|
||||||
delete node._relationship_sibling_node;
|
delete node._relationship_sibling_node;
|
||||||
delete node._relationship_index;
|
delete node._relationship_index;
|
||||||
|
delete node._originalPosition;
|
||||||
},
|
},
|
||||||
undoExecute: function(commandContext)
|
undoExecute: function(commandContext)
|
||||||
{
|
{
|
||||||
var node = commandContext.findTopics(parseInt(this._node))[0];
|
var node = commandContext.findTopics(parseInt(this._node))[0];
|
||||||
var targetNode = commandContext.findTopics(parseInt(this._oldParent))[0];
|
var targetNode = this._oldParent!=null?commandContext.findTopics(parseInt(this._oldParent))[0]:null;
|
||||||
|
|
||||||
var keys = this._modifiedTopics.keys();
|
var keys = this._modifiedTopics.keys();
|
||||||
for(var i=0; i<keys.length; i++){
|
for(var i=0; i<keys.length; i++){
|
||||||
@ -85,21 +86,27 @@ mindplot.commands.freeMind.ReconnectTopicCommand = mindplot.Command.extend(
|
|||||||
if(this._relationship != "Child"){
|
if(this._relationship != "Child"){
|
||||||
oldParent = oldParent.getParent();
|
oldParent = oldParent.getParent();
|
||||||
}
|
}
|
||||||
node.relationship = "undo";
|
if(targetNode!=null){
|
||||||
node._relationship_oldParent = oldParent;
|
node.relationship = "undo";
|
||||||
node._relationship_index = this._index;
|
node._relationship_oldParent = oldParent;
|
||||||
|
node._relationship_index = this._index;
|
||||||
|
}
|
||||||
commandContext.disconnect(node);
|
commandContext.disconnect(node);
|
||||||
commandContext.connect(node, targetNode);
|
if(targetNode!=null){
|
||||||
delete node.relationship;
|
commandContext.connect(node, targetNode);
|
||||||
delete node._relationship_oldParent;
|
delete node.relationship;
|
||||||
delete node._relationship_index;
|
delete node._relationship_oldParent;
|
||||||
|
delete node._relationship_index;
|
||||||
|
}
|
||||||
|
delete node._originalPosition;
|
||||||
},
|
},
|
||||||
setModifiedTopics:function(modifiedTopics){
|
setModifiedTopics:function(modifiedTopics){
|
||||||
this._modifiedTopics = modifiedTopics;
|
this._modifiedTopics = modifiedTopics;
|
||||||
},
|
},
|
||||||
setDraggedTopic:function(node, index){
|
setDraggedTopic:function(node, index){
|
||||||
this._node = node.getId();
|
this._node = node.getId();
|
||||||
this._oldParent = node.getOutgoingConnectedTopic().getId();
|
var outgoingConnectedTopic = node.getOutgoingConnectedTopic();
|
||||||
|
this._oldParent = outgoingConnectedTopic!=null?outgoingConnectedTopic.getId():null;
|
||||||
this._index = index;
|
this._index = index;
|
||||||
},
|
},
|
||||||
setTargetNode:function(node){
|
setTargetNode:function(node){
|
||||||
|
@ -31,7 +31,7 @@ mindplot.layoutManagers.BaseLayoutManager = new Class({
|
|||||||
},
|
},
|
||||||
_nodeRepositionateEvent:function(node){
|
_nodeRepositionateEvent:function(node){
|
||||||
},
|
},
|
||||||
_NodeShrinkEvent:function(node){
|
_nodeShrinkEvent:function(node){
|
||||||
},
|
},
|
||||||
_createBoard:function(){
|
_createBoard:function(){
|
||||||
this._boards = new Hash();
|
this._boards = new Hash();
|
||||||
|
@ -26,7 +26,10 @@ mindplot.layoutManagers.FreeMindLayoutManager = mindplot.layoutManagers.BaseLayo
|
|||||||
},
|
},
|
||||||
prepareChildrenList:function(node, children){
|
prepareChildrenList:function(node, children){
|
||||||
var result = children.sort(function(n1, n2){
|
var result = children.sort(function(n1, n2){
|
||||||
return n1.getPosition().y>n2.getPosition().y;
|
if(n1.getPosition() && n2.getPosition())
|
||||||
|
return n1.getPosition().y>n2.getPosition().y;
|
||||||
|
else
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
@ -106,31 +109,50 @@ mindplot.layoutManagers.FreeMindLayoutManager = mindplot.layoutManagers.BaseLayo
|
|||||||
var pos = screen.getWorkspaceMousePosition(event);
|
var pos = screen.getWorkspaceMousePosition(event);
|
||||||
pos.x = Math.round(pos.x);
|
pos.x = Math.round(pos.x);
|
||||||
pos.y = Math.round(pos.y);
|
pos.y = Math.round(pos.y);
|
||||||
//If still in same side
|
//if isolated topic
|
||||||
if(Math.sign(nodePos.x)==Math.sign(pos.x) || (Math.sign(nodePos.x)!=Math.sign(pos.x) && !this._isCentralTopic(node.getParent()))){
|
if(node.getParent()==null){
|
||||||
var x = nodePos.x - pos.x;
|
//If still in same side
|
||||||
var y = nodePos.y - pos.y;
|
if(Math.sign(nodePos.x)==Math.sign(pos.x)){
|
||||||
var delta = new core.Point(Math.round(x), Math.round(y));
|
var x = nodePos.x - pos.x;
|
||||||
var board = this.getTopicBoardForTopic(node.getParent());
|
var y = nodePos.y - pos.y;
|
||||||
board.updateEntry(node, delta, this._modifiedTopics);
|
var delta = new core.Point(Math.round(x), Math.round(y));
|
||||||
} else {
|
var actualPos = node.getPosition().clone();
|
||||||
var parentBoard = this.getTopicBoardForTopic(node.getParent());
|
var newPos = new core.Point(actualPos.x-(delta.x==null?0:delta.x), actualPos.y-delta.y);
|
||||||
var entryObj = parentBoard.findNodeEntryIndex(node);
|
node.setPosition(newPos, false);
|
||||||
var entry = entryObj.table[entryObj.index];
|
this._addToModifiedList(this._modifiedTopics, node.getId(), actualPos, newPos);
|
||||||
parentBoard._removeEntry(node, entryObj.table, entryObj.index, this._modifiedTopics);
|
this._updateChildrenBoards(node, delta, this._modifiedTopics);
|
||||||
this._changeChildrenSide(node, pos, this._modifiedTopics);
|
}else{
|
||||||
node.setPosition(pos.clone(), false);
|
this._changeChildrenSide(node, pos, this._modifiedTopics);
|
||||||
if(this._modifiedTopics.set){
|
node.setPosition(pos.clone(), false);
|
||||||
var key = node.getId();
|
this._addToModifiedList(this._modifiedTopics, node.getId(), nodePos, pos);
|
||||||
if(this._modifiedTopics.hasKey(key)){
|
|
||||||
nodePos = this._modifiedTopics.get(key).originalPos;
|
|
||||||
}
|
|
||||||
this._modifiedTopics.set(key,{originalPos:nodePos, newPos:pos});
|
|
||||||
}
|
}
|
||||||
entryObj = parentBoard.findNewNodeEntryIndex(entry);
|
}else{
|
||||||
parentBoard._addEntry(entry, entryObj.table, entryObj.index);
|
//If still in same side
|
||||||
parentBoard._updateTable(entryObj.index, entryObj.table, this._modifiedTopics, true);
|
if(Math.sign(nodePos.x)==Math.sign(pos.x) || (Math.sign(nodePos.x)!=Math.sign(pos.x) && !this._isCentralTopic(node.getParent()))){
|
||||||
|
var x = nodePos.x - pos.x;
|
||||||
|
var y = nodePos.y - pos.y;
|
||||||
|
var delta = new core.Point(Math.round(x), Math.round(y));
|
||||||
|
var board = this.getTopicBoardForTopic(node.getParent());
|
||||||
|
board.updateEntry(node, delta, this._modifiedTopics);
|
||||||
|
} else {
|
||||||
|
var parentBoard = this.getTopicBoardForTopic(node.getParent());
|
||||||
|
var entryObj = parentBoard.findNodeEntryIndex(node);
|
||||||
|
var entry = entryObj.table[entryObj.index];
|
||||||
|
parentBoard._removeEntry(node, entryObj.table, entryObj.index, this._modifiedTopics);
|
||||||
|
this._changeChildrenSide(node, pos, this._modifiedTopics);
|
||||||
|
node.setPosition(pos.clone(), false);
|
||||||
|
if(this._modifiedTopics.set){
|
||||||
|
var key = node.getId();
|
||||||
|
if(this._modifiedTopics.hasKey(key)){
|
||||||
|
nodePos = this._modifiedTopics.get(key).originalPos;
|
||||||
|
}
|
||||||
|
this._modifiedTopics.set(key,{originalPos:nodePos, newPos:pos});
|
||||||
|
}
|
||||||
|
entryObj = parentBoard.findNewNodeEntryIndex(entry);
|
||||||
|
parentBoard._addEntry(entry, entryObj.table, entryObj.index);
|
||||||
|
parentBoard._updateTable(entryObj.index, entryObj.table, this._modifiedTopics, true);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this._isMovingNode=false;
|
this._isMovingNode=false;
|
||||||
}
|
}
|
||||||
@ -202,7 +224,7 @@ mindplot.layoutManagers.FreeMindLayoutManager = mindplot.layoutManagers.BaseLayo
|
|||||||
},
|
},
|
||||||
_updateBoard:function(node, modifiedTopics){
|
_updateBoard:function(node, modifiedTopics){
|
||||||
var parent = node;
|
var parent = node;
|
||||||
if(!this._isCentralTopic(parent)){
|
if(!this._isCentralTopic(parent) && parent.getParent()!=null){
|
||||||
var parentBoard = this.getTopicBoardForTopic(parent.getParent());
|
var parentBoard = this.getTopicBoardForTopic(parent.getParent());
|
||||||
var result = parentBoard.findNodeEntryIndex(parent);
|
var result = parentBoard.findNodeEntryIndex(parent);
|
||||||
var parentEntry = result.table[result.index];
|
var parentEntry = result.table[result.index];
|
||||||
@ -278,8 +300,10 @@ 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());
|
if(topic.getParent()!=null){
|
||||||
this._currentIndex = board.findNodeEntryIndex(topic).index;
|
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.
|
||||||
@ -383,12 +407,12 @@ mindplot.layoutManagers.FreeMindLayoutManager = mindplot.layoutManagers.BaseLayo
|
|||||||
//Check that it has to be relocated
|
//Check that it has to be relocated
|
||||||
if(this._createShape !=null){
|
if(this._createShape !=null){
|
||||||
if(this._createShape == "Child"){
|
if(this._createShape == "Child"){
|
||||||
if(node.getParent().getId() == this._targetNode.getId()){
|
if(node.getParent()!=null && node.getParent().getId() == this._targetNode.getId()){
|
||||||
var mod = this._modifiedTopics.get(node.getId());
|
var mod = this._modifiedTopics.get(node.getId());
|
||||||
if(Math.sign(mod.originalPos.x) == Math.sign(node.getPosition().x))
|
if(Math.sign(mod.originalPos.x) == Math.sign(node.getPosition().x))
|
||||||
this._createShape = null;
|
this._createShape = null;
|
||||||
}
|
}
|
||||||
}else if(node.getParent().getId() == this._targetNode.getParent().getId()){
|
}else if(node.getParent()!=null && this._targetNode.getParent()!= null && node.getParent().getId() == this._targetNode.getParent().getId()){
|
||||||
var chkboard = this.getTopicBoardForTopic(this._targetNode.getParent());
|
var chkboard = this.getTopicBoardForTopic(this._targetNode.getParent());
|
||||||
var mod = this._modifiedTopics.get(node.getId());
|
var mod = this._modifiedTopics.get(node.getId());
|
||||||
var chk = chkboard.findNodeEntryIndex(node, mod.originalPos);
|
var chk = chkboard.findNodeEntryIndex(node, mod.originalPos);
|
||||||
@ -447,7 +471,7 @@ mindplot.layoutManagers.FreeMindLayoutManager = mindplot.layoutManagers.BaseLayo
|
|||||||
pos.y = Math.round(pos.y);
|
pos.y = Math.round(pos.y);
|
||||||
var nodePos = this.getPosition();
|
var nodePos = this.getPosition();
|
||||||
//if it is on the child half side, or it is central topic add it as child
|
//if it is on the child half side, or it is central topic add it as child
|
||||||
if(layoutManager._isCentralTopic(this) || ((Math.sign(nodePos.x)>0 && pos.x>nodePos.x) || (Math.sign(nodePos.x)<0 && pos.x<nodePos.x))){
|
if(layoutManager._isCentralTopic(this) || this.getParent()==null || ((Math.sign(nodePos.x)>0 && pos.x>nodePos.x) || (Math.sign(nodePos.x)<0 && pos.x<nodePos.x))){
|
||||||
layoutManager._updateIndicatorShapes(this, mindplot.layoutManagers.FreeMindLayoutManager.RECONNECT_SHAPE_CHILD, pos);
|
layoutManager._updateIndicatorShapes(this, mindplot.layoutManagers.FreeMindLayoutManager.RECONNECT_SHAPE_CHILD, pos);
|
||||||
}else{
|
}else{
|
||||||
//is a sibling. if mouse in top half sibling goes above this one
|
//is a sibling. if mouse in top half sibling goes above this one
|
||||||
@ -535,16 +559,36 @@ mindplot.layoutManagers.FreeMindLayoutManager = mindplot.layoutManagers.BaseLayo
|
|||||||
topic.moveToFront();
|
topic.moveToFront();
|
||||||
},
|
},
|
||||||
_movingNode:function(targetNode, node){
|
_movingNode:function(targetNode, node){
|
||||||
var parentBoard = this.getTopicBoardForTopic(node._relationship_oldParent);
|
var entry;
|
||||||
var entryObj;
|
if(node._relationship_oldParent!=null){
|
||||||
if(this._isCentralTopic(node._relationship_oldParent)){
|
var parentBoard = this.getTopicBoardForTopic(node._relationship_oldParent);
|
||||||
var oldPos = node._originalPosition;
|
var entryObj;
|
||||||
|
if(this._isCentralTopic(node._relationship_oldParent)){
|
||||||
|
var oldPos = node._originalPosition;
|
||||||
entryObj = parentBoard.findNodeEntryIndex(node,oldPos);
|
entryObj = parentBoard.findNodeEntryIndex(node,oldPos);
|
||||||
}else{
|
}else{
|
||||||
entryObj = parentBoard.findNodeEntryIndex(node);
|
entryObj = parentBoard.findNodeEntryIndex(node);
|
||||||
|
}
|
||||||
|
entry = entryObj.table[entryObj.index];
|
||||||
|
parentBoard._removeEntry(node, entryObj.table, entryObj.index, []);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
//if is an isolated topic, create entry and update margins.
|
||||||
|
entry = new mindplot.layoutManagers.boards.freeMindBoards.Entry(node, false);
|
||||||
|
var board = this.getTopicBoardForTopic(node);
|
||||||
|
var table = board._getTableForNode(null);
|
||||||
|
if(table.length>0){
|
||||||
|
var firstChild = table[0];
|
||||||
|
var marginTop = entry.getPosition()-(firstChild.getPosition()-firstChild.getTotalMarginTop());
|
||||||
|
board.setNodeChildrenMarginTop(entry,marginTop);
|
||||||
|
var lastChild = table[table.length-1];
|
||||||
|
var marginBottom = (lastChild.getPosition()+lastChild.getTotalMarginBottom())-entry.getPosition();
|
||||||
|
board.setNodeChildrenMarginBottom(entry,marginBottom);
|
||||||
|
} else {
|
||||||
|
board.setNodeChildrenMarginTop(entry, 0);
|
||||||
|
board.setNodeChildrenMarginBottom(entry, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var entry = entryObj.table[entryObj.index];
|
|
||||||
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;
|
||||||
@ -613,8 +657,18 @@ mindplot.layoutManagers.FreeMindLayoutManager = mindplot.layoutManagers.BaseLayo
|
|||||||
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,[]);
|
||||||
this._updateBoard(node._relationship_oldParent,[]);
|
if(node._relationship_oldParent!=null)
|
||||||
|
this._updateBoard(node._relationship_oldParent,[]);
|
||||||
|
|
||||||
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeMouseOutEvent,[node ]);
|
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.NodeMouseOutEvent,[node ]);
|
||||||
|
},
|
||||||
|
_addToModifiedList:function(modifiedTopics, key, originalpos, newPos){
|
||||||
|
if(modifiedTopics.set){
|
||||||
|
if(modifiedTopics.hasKey(key)){
|
||||||
|
originalpos = modifiedTopics.get(key).originalPos;
|
||||||
|
}
|
||||||
|
modifiedTopics.set(key,{originalPos:originalpos, newPos:newPos});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -33,11 +33,7 @@ mindplot.layoutManagers.OriginalLayoutManager = mindplot.layoutManagers.BaseLayo
|
|||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
_nodeResizeEvent:function(node){
|
_nodeResizeEvent:function(node){
|
||||||
if(this._isCentralTopic(node)){
|
|
||||||
var size = node.getSize();
|
|
||||||
if(!this._isCentralTopic(node))
|
|
||||||
this.getTopicBoardForTopic(node).updateChildrenPosition(node,size.height/2, []);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
_nodeRepositionateEvent:function(node){
|
_nodeRepositionateEvent:function(node){
|
||||||
this.getTopicBoardForTopic(node).repositionate();
|
this.getTopicBoardForTopic(node).repositionate();
|
||||||
|
@ -15,7 +15,10 @@ mindplot.layoutManagers.boards.freeMindBoards.Board = mindplot.layoutManagers.bo
|
|||||||
core.assert(false, "no Board implementation found!")
|
core.assert(false, "no Board implementation found!")
|
||||||
},
|
},
|
||||||
removeTopicFromBoard:function(node, modifiedTopics){
|
removeTopicFromBoard:function(node, modifiedTopics){
|
||||||
var result = this.findNodeEntryIndex(node);
|
var pos;
|
||||||
|
if(node._originalPosition)
|
||||||
|
pos = node._originalPosition;
|
||||||
|
var result = this.findNodeEntryIndex(node, pos);
|
||||||
core.assert(result.index<result.table.length,"node not found. Could not remove");
|
core.assert(result.index<result.table.length,"node not found. Could not remove");
|
||||||
this._removeEntry(node, result.table, result.index, modifiedTopics);
|
this._removeEntry(node, result.table, result.index, modifiedTopics);
|
||||||
},
|
},
|
||||||
@ -67,7 +70,7 @@ mindplot.layoutManagers.boards.freeMindBoards.Board = mindplot.layoutManagers.bo
|
|||||||
nextEntry.setMarginTop((nextEntry.getPosition() - nextEntry.getTotalMarginTop())-pos.y);
|
nextEntry.setMarginTop((nextEntry.getPosition() - nextEntry.getTotalMarginTop())-pos.y);
|
||||||
}
|
}
|
||||||
var parent = node.getParent();
|
var parent = node.getParent();
|
||||||
if(!this._layoutManager._isCentralTopic(parent) && (result.index == 0 || result.index==result.table.length-1)){
|
if(!this._layoutManager._isCentralTopic(parent) && parent.getParent()!=null && (result.index == 0 || result.index==result.table.length-1)){
|
||||||
var board = this._layoutManager.getTopicBoardForTopic(parent.getParent());
|
var board = this._layoutManager.getTopicBoardForTopic(parent.getParent());
|
||||||
var res2 = board.findNodeEntryIndex(parent);
|
var res2 = board.findNodeEntryIndex(parent);
|
||||||
var parentEntry = res2.table[res2.index];
|
var parentEntry = res2.table[res2.index];
|
||||||
|
@ -11,7 +11,7 @@ mindplot.layoutManagers.boards.freeMindBoards.CentralTopicBoard = mindplot.layou
|
|||||||
_getTableForNode:function(node, altPosition){
|
_getTableForNode:function(node, altPosition){
|
||||||
var i = 0;
|
var i = 0;
|
||||||
var position = node.getPosition();
|
var position = node.getPosition();
|
||||||
if(typeof altPosition != "undefined")
|
if(typeof altPosition != "undefined" && altPosition!=null)
|
||||||
{
|
{
|
||||||
position = altPosition;
|
position = altPosition;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user