Keyboard actions for adding is working with the new layout...

This commit is contained in:
Paulo Veiga 2012-01-11 21:12:22 -03:00
parent d9cdcc5160
commit 51bc3e563a
8 changed files with 110 additions and 166 deletions

View File

@ -53,31 +53,6 @@ mindplot.CentralTopic = new Class({
return false; return false;
}, },
createChildModel : function(prepositionate) {
// Create a new node ...
var model = this.getModel();
var mindmap = model.getMindmap();
var childModel = mindmap.createNode(mindplot.model.INodeModel.MAIN_TOPIC_TYPE);
if (prepositionate) {
if (!$defined(this.___siblingDirection)) {
this.___siblingDirection = 1;
}
// Position following taking into account this internal flag ...
if (this.___siblingDirection == 1) {
childModel.setPosition(150, 0);
} else {
childModel.setPosition(-150, 0);
}
this.___siblingDirection = -this.___siblingDirection;
}
// Create a new node ...
childModel.setOrder(0);
return childModel;
},
_defaultShapeType : function() { _defaultShapeType : function() {
return mindplot.model.INodeModel.SHAPE_TYPE_ROUNDED_RECT; return mindplot.model.INodeModel.SHAPE_TYPE_ROUNDED_RECT;

View File

@ -43,21 +43,20 @@ mindplot.Designer = new Class({
this._workspace = new mindplot.Workspace(screenManager, this._model.getZoom()); this._workspace = new mindplot.Workspace(screenManager, this._model.getZoom());
this._readOnly = profile.readOnly ? true : false; this._readOnly = profile.readOnly ? true : false;
// Register events // Register events
if (!profile.readOnly) { if (!profile.readOnly) {
this._registerEvents(); this._registerEvents();
// Init drag related classes ...
this._dragTopicPositioner = new mindplot.DragTopicPositioner(this.getModel(), this._workspace);
this._dragger = this._buildDragManager(this._workspace);
mindplot.DragTopic.init(this._workspace);
} }
this._relPivot = new mindplot.RelationshipPivot(this._workspace, this); this._relPivot = new mindplot.RelationshipPivot(this._workspace, this);
// Init layout manager ... // Init layout manager ...
this._eventBussDispatcher = new mindplot.nlayout.EventBusDispatcher(this.getModel()); this._eventBussDispatcher = new mindplot.nlayout.EventBusDispatcher(this.getModel());
// @todo: To be removed ...
this._layoutManager = new mindplot.layout.OriginalLayoutManager(this);
}, },
_registerEvents : function() { _registerEvents : function() {
@ -123,6 +122,51 @@ mindplot.Designer = new Class({
}, },
_buildDragManager: function(workspace) {
// Init dragger manager.
var dragger = new mindplot.DragManager(workspace);
var topics = this.getModel().getTopics();
var dragTopicPositioner = this._dragTopicPositioner;
dragger.addEvent('startdragging', function(event, node) {
// Enable all mouse events.
for (var i = 0; i < topics.length; i++) {
topics[i].setMouseEventsEnabled(false);
}
});
dragger.addEvent('dragging', function(event, dragTopic) {
// Update the state and connections of the topic ...
dragTopicPositioner.positionateDragTopic(dragTopic);
});
dragger.addEvent('enddragging', function(event, dragTopic) {
// Enable all mouse events.
for (var i = 0; i < topics.length; i++) {
topics[i].setMouseEventsEnabled(true);
}
// Topic must be positioned in the real board postion.
if (dragTopic._isInTheWorkspace) {
var draggedTopic = dragTopic.getDraggedTopic();
// Hide topic during draw ...
draggedTopic.setBranchVisibility(false);
var parentNode = draggedTopic.getParent();
dragTopic.updateDraggedTopic(workspace);
// Make all node visible ...
draggedTopic.setVisibility(true);
if (parentNode != null) {
parentNode.setBranchVisibility(true);
}
}
});
return dragger;
},
setViewPort : function(size) { setViewPort : function(size) {
this._workspace.setViewPort(size); this._workspace.setViewPort(size);
var model = this.getModel(); var model = this.getModel();
@ -134,20 +178,24 @@ mindplot.Designer = new Class({
// Create node graph ... // Create node graph ...
var topic = mindplot.NodeGraph.create(model); var topic = mindplot.NodeGraph.create(model);
this._layoutManager.addHelpers(topic);
// Append it to the workspace ... // Append it to the workspace ...
this.getModel().addTopic(topic); this.getModel().addTopic(topic);
// Add Topic events ... // Add Topic events ...
if (!this._readOnly) { if (!this._readOnly) {
// Add drag behaviour ...
this._layoutManager.registerListenersOnNode(topic);
// If a node had gained focus, clean the rest of the nodes ... // If a node had gained focus, clean the rest of the nodes ...
topic.addEvent('mousedown', function(event) { topic.addEvent('mousedown', function(event) {
this.onObjectFocusEvent(topic, event); this.onObjectFocusEvent(topic, event);
}.bind(this)); }.bind(this));
// Register node listeners ...
if (topic.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
// Central Topic doesn't support to be dragged
var dragger = this._dragger;
dragger.add(topic);
}
} }
// Connect Topic ... // Connect Topic ...
@ -282,7 +330,7 @@ mindplot.Designer = new Class({
// Add new node ... // Add new node ...
var parentTopic = nodes[0]; var parentTopic = nodes[0];
var parentTopicId = parentTopic.getId(); var parentTopicId = parentTopic.getId();
var childModel = parentTopic.createChildModel(this._layoutManager.needsPrepositioning()); var childModel = parentTopic.createChildModel();
// Execute event ... // Execute event ...
this._actionDispatcher.addTopic(childModel, parentTopicId, true); this._actionDispatcher.addTopic(childModel, parentTopicId, true);
@ -310,7 +358,7 @@ mindplot.Designer = new Class({
} else { } else {
var parentTopic = topic.getOutgoingConnectedTopic(); var parentTopic = topic.getOutgoingConnectedTopic();
var siblingModel = topic.createSiblingModel(this._layoutManager.needsPrepositioning()); var siblingModel = topic.createSiblingModel();
var parentTopicId = parentTopic.getId(); var parentTopicId = parentTopic.getId();
this._actionDispatcher.addTopic(siblingModel, parentTopicId, true); this._actionDispatcher.addTopic(siblingModel, parentTopicId, true);
@ -401,8 +449,7 @@ mindplot.Designer = new Class({
if (isVisible) if (isVisible)
nodeGraph.setVisibility(isVisible); nodeGraph.setVisibility(isVisible);
var children = nodeModel.getChildren().slice(); var children = nodeModel.getChildren();
children = this._layoutManager.prepareNode(nodeGraph, children);
var workspace = this._workspace; var workspace = this._workspace;
workspace.appendChild(nodeGraph); workspace.appendChild(nodeGraph);

View File

@ -17,11 +17,13 @@
*/ */
mindplot.DragTopicPositioner = new Class({ mindplot.DragTopicPositioner = new Class({
initialize:function(layoutManager) { initialize:function(designerModel, workspace) {
$assert(layoutManager, 'layoutManager can not be null'); $assert(designerModel, 'designerModel can not be null');
this._layoutManager = layoutManager; $assert(workspace, 'workspace can not be null');
this._topics = layoutManager.getDesigner().getModel().getTopics();
this._workspace = layoutManager.getDesigner().getWorkSpace(); // this._layoutManager = layoutManager;
this._designerModel = designerModel;
this._workspace = workspace;
}, },
positionateDragTopic : function(dragTopic) { positionateDragTopic : function(dragTopic) {
@ -71,8 +73,7 @@ mindplot.DragTopicPositioner = new Class({
// Finally, connect nodes ... // Finally, connect nodes ...
if (!dragTopic.isConnected()) { if (!dragTopic.isConnected()) {
var centalTopic = topics[0]; var centalTopic = topics[0];
if ($defined(mainTopicToMainTopicConnection)) if ($defined(mainTopicToMainTopicConnection)) {
{
dragTopic.connectTo(mainTopicToMainTopicConnection); dragTopic.connectTo(mainTopicToMainTopicConnection);
} else if (Math.abs(dragTopic.getPosition().x - centalTopic.getPosition().x) <= mindplot.DragTopicPositioner.CENTRAL_TO_MAINTOPIC_MAX_HORIZONTAL_DISTANCE) { } else if (Math.abs(dragTopic.getPosition().x - centalTopic.getPosition().x) <= mindplot.DragTopicPositioner.CENTRAL_TO_MAINTOPIC_MAX_HORIZONTAL_DISTANCE) {
dragTopic.connectTo(centalTopic); dragTopic.connectTo(centalTopic);

View File

@ -24,49 +24,6 @@ mindplot.MainTopic = new Class({
INNER_RECT_ATTRIBUTES : {stroke:'0.5 solid #009900'}, INNER_RECT_ATTRIBUTES : {stroke:'0.5 solid #009900'},
createSiblingModel : function(positionate) {
var result = null;
var parentTopic = this.getOutgoingConnectedTopic();
if (parentTopic != null) {
// Create a new node ...
var model = this.getModel();
var mindmap = model.getMindmap();
result = mindmap.createNode(mindplot.model.INodeModel.MAIN_TOPIC_TYPE);
// Positionate following taking into account the sibling position.
if (positionate && parentTopic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
var pos = this.getPosition();
result.setPosition(pos.x, pos.y);
}
// Create a new node ...
var order = this.getOrder() + 1;
result.setOrder(order);
}
return result;
},
createChildModel : function(prepositionate) {
// Create a new node ...
var model = this.getModel();
var mindmap = model.getMindmap();
var childModel = mindmap.createNode(mindplot.model.INodeModel.MAIN_TOPIC_TYPE);
// Get the hights model order position ...
var children = this._getChildren();
var order = -1;
for (var i = 0; i < children.length; i++) {
var child = children[i];
if (child.getOrder() > order) {
order = child.getOrder();
}
}
// Create a new node ...
childModel.setOrder(order + 1);
return childModel;
},
_buildDragShape : function() { _buildDragShape : function() {
var innerShape = this.buildShape(this.INNER_RECT_ATTRIBUTES); var innerShape = this.buildShape(this.INNER_RECT_ATTRIBUTES);
var size = this.getSize(); var size = this.getSize();
@ -113,9 +70,6 @@ mindplot.MainTopic = new Class({
this._setShapeType(shapeType, false); this._setShapeType(shapeType, false);
} }
} }
this._helpers.forEach(function(helper) {
helper.moveToFront();
});
}, },
disconnect : function(workspace) { disconnect : function(workspace) {
@ -274,9 +228,25 @@ mindplot.MainTopic = new Class({
_defaultBorderColor : function() { _defaultBorderColor : function() {
return '#023BB9'; return '#023BB9';
}, },
addSibling : function() {
var order = this.getOrder(); // @todo: Removed !!!
createSiblingModel : function() {
var result = null;
var parentTopic = this.getOutgoingConnectedTopic();
if (parentTopic != null) {
// Create a new node ...
var model = this.getModel();
var mindmap = model.getMindmap();
result = mindmap.createNode(mindplot.model.INodeModel.MAIN_TOPIC_TYPE);
// Create a new node ...
var order = this.getOrder() + 1;
result.setOrder(order);
result.setPosition(10,10);
}
return result;
} }
}); });
mindplot.MainTopic.DEFAULT_MAIN_TOPIC_HEIGHT = 18; mindplot.MainTopic.DEFAULT_MAIN_TOPIC_HEIGHT = 18;

View File

@ -27,7 +27,6 @@ mindplot.Topic = new Class({
this._parent = null; this._parent = null;
this._relationships = []; this._relationships = [];
this._isInWorkspace = false; this._isInWorkspace = false;
this._helpers = [];
this._buildShape(); this._buildShape();
// Position a topic .... // Position a topic ....
@ -144,12 +143,6 @@ mindplot.Topic = new Class({
if ($defined(connector)) { if ($defined(connector)) {
connector.moveToFront(); connector.moveToFront();
} }
//Move helpers to front
this._helpers.forEach(function(helper) {
helper.moveToFront();
});
} }
}, },
@ -1257,11 +1250,28 @@ mindplot.Topic = new Class({
} }
}, },
addHelper : function(helper) { // @Todo: this don't seems to be a nice way... Order should be infered automatically ...
helper.addToGroup(this.get2DElement()); createChildModel : function() {
this._helpers.push(helper); // Create a new node ...
} var model = this.getModel();
var mindmap = model.getMindmap();
var childModel = mindmap.createNode(mindplot.model.INodeModel.MAIN_TOPIC_TYPE);
// Get the hights model order position ...
var children = this._getChildren();
var order = -1;
for (var i = 0; i < children.length; i++) {
var child = children[i];
if (child.getOrder() > order) {
order = child.getOrder();
}
}
// Create a new node ...
childModel.setOrder(order + 1);
childModel.setPosition(10, 10);
return childModel;
}
}); });

View File

@ -23,14 +23,7 @@ mindplot.layout.OriginalLayoutManager = new Class({
}, },
initialize:function(designer, options) { initialize:function(designer, options) {
this.parent(designer, options); this.parent(designer, options);
this._dragTopicPositioner = new mindplot.DragTopicPositioner(this);
// Init drag manager.
var workSpace = this.getDesigner().getWorkSpace();
this._dragger = this._buildDragManager(workSpace);
// Add shapes to speed up the loading process ...
mindplot.DragTopic.init(workSpace);
}, },
prepareNode:function(node, children) { prepareNode:function(node, children) {
@ -77,60 +70,7 @@ mindplot.layout.OriginalLayoutManager = new Class({
return this._dragTopicPositioner; return this._dragTopicPositioner;
}, },
_buildDragManager: function(workspace) {
// Init dragger manager.
var dragger = new mindplot.DragManager(workspace);
var topics = this.getDesigner().getModel().getTopics();
var dragTopicPositioner = this.getDragTopicPositioner();
dragger.addEvent('startdragging', function(event, node) {
// Enable all mouse events.
for (var i = 0; i < topics.length; i++) {
topics[i].setMouseEventsEnabled(false);
}
});
dragger.addEvent('dragging', function(event, dragTopic) {
// Update the state and connections of the topic ...
dragTopicPositioner.positionateDragTopic(dragTopic);
});
dragger.addEvent('enddragging', function(event, dragTopic) {
// Enable all mouse events.
for (var i = 0; i < topics.length; i++) {
topics[i].setMouseEventsEnabled(true);
}
// Topic must be positioned in the real board postion.
if (dragTopic._isInTheWorkspace) {
var draggedTopic = dragTopic.getDraggedTopic();
// Hide topic during draw ...
draggedTopic.setBranchVisibility(false);
var parentNode = draggedTopic.getParent();
dragTopic.updateDraggedTopic(workspace);
// Make all node visible ...
draggedTopic.setVisibility(true);
if (parentNode != null) {
parentNode.setBranchVisibility(true);
}
}
});
return dragger;
},
registerListenersOnNode : function(topic) {
// Register node listeners ...
if (topic.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
// Central Topic doesn't support to be dragged
var dragger = this._dragger;
dragger.add(topic);
}
},
_createMainTopicBoard:function(node) { _createMainTopicBoard:function(node) {
return new mindplot.layout.boards.original.MainTopicBoard(node, this); return new mindplot.layout.boards.original.MainTopicBoard(node, this);

View File

@ -55,6 +55,8 @@ mindplot.model.INodeModel = new Class({
}, },
setPosition : function(x, y) { setPosition : function(x, y) {
$assert(!isNaN(parseInt(x)), "x position is not valid:" + x);
$assert(!isNaN(parseInt(y)), "x position is not valid:" + y);
this.putProperty('position', '{x:' + parseInt(x) + ',y:' + parseInt(y) + '}'); this.putProperty('position', '{x:' + parseInt(x) + ',y:' + parseInt(y) + '}');
}, },

View File

@ -367,7 +367,6 @@ mindplot.widget.Menu = new Class({
var disable = false; var disable = false;
if (button.isTopicAction() && button.isRelAction()) { if (button.isTopicAction() && button.isRelAction()) {
disable = rels.length == 0 && topics.length == 0; disable = rels.length == 0 && topics.length == 0;
console.log(disable);
} else if (!button.isTopicAction() && !button.isRelAction()) { } else if (!button.isTopicAction() && !button.isRelAction()) {
disable = false; disable = false;
} }