supporting change of layouts

This commit is contained in:
Pablo Luna 2011-04-15 12:59:21 +01:00
parent 75564c17ec
commit 0f496bb4b3
6 changed files with 44 additions and 19 deletions

View File

@ -20,7 +20,7 @@ core.Utils =
{ {
isDefined: function(val) isDefined: function(val)
{ {
return val !== null && val !== undefined; return val !== null && val !== undefined && typeof val !="undefined";
}, },
escapeInvalidTags: function (text) escapeInvalidTags: function (text)
{ {

View File

@ -354,7 +354,7 @@ mindplot.MindmapDesigner.prototype.save = function(onSavedHandler, saveHistory)
var persistantManager = mindplot.PersistanceManager; var persistantManager = mindplot.PersistanceManager;
var mindmap = this._mindmap; var mindmap = this._mindmap;
var properties = {zoom:this._zoom}; var properties = {zoom:this._zoom, layoutManager:this._layoutManager.getClassName()};
persistantManager.save(mindmap, properties, onSavedHandler, saveHistory); persistantManager.save(mindmap, properties, onSavedHandler, saveHistory);
this._fireEvent("save", {type:saveHistory}); this._fireEvent("save", {type:saveHistory});
@ -461,7 +461,7 @@ mindplot.MindmapDesigner.prototype._nodeModelToNodeGraph = function(nodeModel, i
var children = nodeModel.getChildren().slice(); var children = nodeModel.getChildren().slice();
children = this._layoutManager.prepareChildrenList(nodeGraph, children); children = this._layoutManager.prepareNode(nodeGraph, children);
for (var i = 0; i < children.length; i++) for (var i = 0; i < children.length; i++)
{ {

View File

@ -227,6 +227,7 @@ mindplot.XMLMindmapSerializer_Pela.prototype.loadFromDom = function(dom)
// Is a wisemap?. // Is a wisemap?.
core.assert(rootElem.tagName == mindplot.XMLMindmapSerializer_Pela.MAP_ROOT_NODE, "This seem not to be a map document."); core.assert(rootElem.tagName == mindplot.XMLMindmapSerializer_Pela.MAP_ROOT_NODE, "This seem not to be a map document.");
this._idsMap = new Hash();
// Start the loading process ... // Start the loading process ...
var mindmap = new mindplot.Mindmap(); var mindmap = new mindplot.Mindmap();
@ -251,6 +252,7 @@ mindplot.XMLMindmapSerializer_Pela.prototype.loadFromDom = function(dom)
} }
} }
} }
this._idsMap=null;
return mindmap; return mindmap;
}; };
@ -263,6 +265,12 @@ mindplot.XMLMindmapSerializer_Pela.prototype._deserializeNode = function(domElem
id=parseInt(id); id=parseInt(id);
} }
if(this._idsMap.hasKey(id)){
id=null;
}else{
this._idsMap.set(id,domElem);
}
var topic = mindmap.createNode(type, id); var topic = mindmap.createNode(type, id);
var text = domElem.getAttribute('text'); var text = domElem.getAttribute('text');
@ -272,7 +280,7 @@ mindplot.XMLMindmapSerializer_Pela.prototype._deserializeNode = function(domElem
var order = domElem.getAttribute('order'); var order = domElem.getAttribute('order');
if (order) { if (order) {
topic.setOrder(order); topic.setOrder(parseInt(order));
} }
var shape = domElem.getAttribute('shape'); var shape = domElem.getAttribute('shape');

View File

@ -60,7 +60,7 @@ mindplot.layoutManagers.BaseLayoutManager = new Class({
_createCentralTopicBoard:function(node){ _createCentralTopicBoard:function(node){
return new mindplot.layoutManagers.boards.Board(node, this); return new mindplot.layoutManagers.boards.Board(node, this);
}, },
prepareChildrenList:function(node, children){ prepareNode:function(node, children){
}, },
addHelpers:function(node){ addHelpers:function(node){

View File

@ -24,13 +24,20 @@ mindplot.layoutManagers.FreeMindLayoutManager = mindplot.layoutManagers.BaseLayo
_nodeShrinkEvent:function(node){ _nodeShrinkEvent:function(node){
this._updateBoard(node,[]); this._updateBoard(node,[]);
}, },
prepareChildrenList:function(node, children){ prepareNode:function(node, children){
var result = children.sort(function(n1, n2){ var layoutManagerName = editorProperties.layoutManager;
if(n1.getPosition() && n2.getPosition()) //if last layout used is this one
return n1.getPosition().y>n2.getPosition().y; if(typeof layoutManagerName != "undefined" && layoutManagerName == this.getClassName()){
else var result = children.sort(function(n1, n2){
return true; if(n1.getPosition() && n2.getPosition())
}); return n1.getPosition().y>n2.getPosition().y;
else
return true;
});
} else {
delete node.getModel()._finalPosition;
result = children;
}
return result; return result;
}, },
registerListenersOnNode : function(topic) registerListenersOnNode : function(topic)

View File

@ -12,24 +12,34 @@ mindplot.layoutManagers.OriginalLayoutManager = mindplot.layoutManagers.BaseLayo
// Add shapes to speed up the loading process ... // Add shapes to speed up the loading process ...
mindplot.DragTopic.initialize(workSpace); mindplot.DragTopic.initialize(workSpace);
}, },
prepareChildrenList:function(node, children){ prepareNode:function(node, children){
// Sort children by order to solve adding order in for OriginalLayoutManager... // Sort children by order to solve adding order in for OriginalLayoutManager...
var nodesByOrder = new Hash();
var maxOrder =0;
var result = []; var result = [];
if (node.getTopicType()!=mindplot.NodeModel.CENTRAL_TOPIC_TYPE && children.length > 0) if (children.length > 0)
{ {
for (var i = 0; i < children.length; i++) for (var i = 0; i < children.length; i++)
{ {
var child = children[i]; var child = children[i];
var order = child.getOrder(); var order = child.getOrder();
if (order != null) if (!core.Utils.isDefined(order))
{ {
result[order] = child; order = maxOrder++;
} else
{
result.push(child);
} }
if(nodesByOrder.hasKey(order)){
//duplicated order. Change order to next available.
order = maxOrder++;
}else{
nodesByOrder.set(order, child);
if(order>maxOrder)
maxOrder=order;
}
result[order] = child;
} }
} }
nodesByOrder=null;
return result; return result;
}, },
_nodeResizeEvent:function(node){ _nodeResizeEvent:function(node){