mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 22:27:55 +01:00
-Fix problem on element undo...
This commit is contained in:
parent
80940b8529
commit
3a0c79a2a8
@ -30,16 +30,21 @@ mindplot.DesignerActionRunner = new Class({
|
|||||||
command.execute(this._context);
|
command.execute(this._context);
|
||||||
this._undoManager.enqueue(command);
|
this._undoManager.enqueue(command);
|
||||||
this.fireChangeEvent();
|
this.fireChangeEvent();
|
||||||
|
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.DoLayout);
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
undo: function() {
|
undo: function() {
|
||||||
this._undoManager.execUndo(this._context);
|
this._undoManager.execUndo(this._context);
|
||||||
this.fireChangeEvent();
|
this.fireChangeEvent();
|
||||||
|
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.DoLayout);
|
||||||
},
|
},
|
||||||
|
|
||||||
redo: function() {
|
redo: function() {
|
||||||
this._undoManager.execRedo(this._context);
|
this._undoManager.execRedo(this._context);
|
||||||
this.fireChangeEvent();
|
this.fireChangeEvent();
|
||||||
|
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.DoLayout);
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
fireChangeEvent : function () {
|
fireChangeEvent : function () {
|
||||||
|
@ -1,232 +1,234 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright [2011] [wisemapping]
|
* Copyright [2011] [wisemapping]
|
||||||
*
|
*
|
||||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||||
* "powered by wisemapping" text requirement on every single page;
|
* "powered by wisemapping" text requirement on every single page;
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the license at
|
* You may obtain a copy of the license at
|
||||||
*
|
*
|
||||||
* http://www.wisemapping.org/license
|
* http://www.wisemapping.org/license
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
mindplot.DragTopic = new Class({
|
mindplot.DragTopic = new Class({
|
||||||
initialize:function(dragShape, draggedNode, layoutManger) {
|
initialize:function(dragShape, draggedNode, layoutManger) {
|
||||||
$assert(dragShape, 'Rect can not be null.');
|
$assert(dragShape, 'Rect can not be null.');
|
||||||
$assert(draggedNode, 'draggedNode can not be null.');
|
$assert(draggedNode, 'draggedNode can not be null.');
|
||||||
$assert(layoutManger, 'layoutManger can not be null.');
|
$assert(layoutManger, 'layoutManger can not be null.');
|
||||||
|
|
||||||
this._elem2d = dragShape;
|
this._elem2d = dragShape;
|
||||||
this._order = null;
|
this._order = null;
|
||||||
this._draggedNode = draggedNode;
|
this._draggedNode = draggedNode;
|
||||||
this._layoutManager = layoutManger;
|
this._layoutManager = layoutManger;
|
||||||
this._position = new core.Point();
|
this._position = new core.Point();
|
||||||
this._isInWorkspace = false;
|
this._isInWorkspace = false;
|
||||||
this._isFreeLayoutEnabled = false;
|
this._isFreeLayoutEnabled = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
setOrder : function(order) {
|
setOrder : function(order) {
|
||||||
this._order = order;
|
this._order = order;
|
||||||
},
|
},
|
||||||
|
|
||||||
setPosition : function(x, y) {
|
setPosition : function(x, y) {
|
||||||
// Update drag shadow position ....
|
// Update drag shadow position ....
|
||||||
var position = {x:x,y:y};
|
var position = {x:x,y:y};
|
||||||
if (this.isFreeLayoutOn() && this.isConnected()) {
|
if (this.isFreeLayoutOn() && this.isConnected()) {
|
||||||
var _layoutManager = this._layoutManager;
|
var _layoutManager = this._layoutManager;
|
||||||
var par = this.getConnectedToTopic();
|
var par = this.getConnectedToTopic();
|
||||||
position = _layoutManager.predict(par.getId(), this._draggedNode.getId(), position, true).position;
|
position = _layoutManager.predict(par.getId(), this._draggedNode.getId(), position, true).position;
|
||||||
}
|
}
|
||||||
this._position.setValue(position.x, position.y);
|
this._position.setValue(position.x, position.y);
|
||||||
|
|
||||||
// Elements are positioned in the center.
|
// Elements are positioned in the center.
|
||||||
// All topic element must be positioned based on the innerShape.
|
// All topic element must be positioned based on the innerShape.
|
||||||
var draggedNode = this._draggedNode;
|
var draggedNode = this._draggedNode;
|
||||||
var size = draggedNode.getSize();
|
var size = draggedNode.getSize();
|
||||||
var cx = Math.ceil(position.x - (size.width / 2));
|
var cx = Math.ceil(position.x - (size.width / 2));
|
||||||
var cy = Math.ceil(position.y - (size.height / 2));
|
var cy = Math.ceil(position.y - (size.height / 2));
|
||||||
this._elem2d.setPosition(cx, cy);
|
this._elem2d.setPosition(cx, cy);
|
||||||
|
|
||||||
// In case is not free, pivot must be draw ...
|
// In case is not free, pivot must be draw ...
|
||||||
if (this.isConnected() && !this.isFreeLayoutOn()) {
|
if (this.isConnected() && !this.isFreeLayoutOn()) {
|
||||||
var parent = this.getConnectedToTopic();
|
var parent = this.getConnectedToTopic();
|
||||||
var predict = this._layoutManager.predict(parent.getId(), this._draggedNode.getId(), this.getPosition());
|
var predict = this._layoutManager.predict(parent.getId(), this._draggedNode.getId(), this.getPosition());
|
||||||
if (this._order != predict.order) {
|
if (this._order != predict.order) {
|
||||||
var dragPivot = this._getDragPivot();
|
var dragPivot = this._getDragPivot();
|
||||||
var pivotPosition = predict.position;
|
var pivotPosition = predict.position;
|
||||||
dragPivot.connectTo(parent, pivotPosition);
|
dragPivot.connectTo(parent, pivotPosition);
|
||||||
this.setOrder(predict.order);
|
this.setOrder(predict.order);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
updateFreeLayout: function(event) {
|
updateFreeLayout: function(event) {
|
||||||
var isFreeEnabled = (event.meta && Browser.Platform.mac) || (event.control && !Browser.Platform.mac);
|
var isFreeEnabled = (event.meta && Browser.Platform.mac) || (event.control && !Browser.Platform.mac);
|
||||||
if (this.isFreeLayoutOn() != isFreeEnabled) {
|
if (this.isFreeLayoutOn() != isFreeEnabled) {
|
||||||
var dragPivot = this._getDragPivot();
|
var dragPivot = this._getDragPivot();
|
||||||
dragPivot.setVisibility(!isFreeEnabled);
|
dragPivot.setVisibility(!isFreeEnabled);
|
||||||
this._isFreeLayoutEnabled = isFreeEnabled;
|
this._isFreeLayoutEnabled = isFreeEnabled;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
setVisibility:function(value) {
|
setVisibility:function(value) {
|
||||||
var dragPivot = this._getDragPivot();
|
var dragPivot = this._getDragPivot();
|
||||||
dragPivot.setVisibility(value);
|
dragPivot.setVisibility(value);
|
||||||
},
|
},
|
||||||
|
|
||||||
isVisible:function() {
|
isVisible:function() {
|
||||||
var dragPivot = this._getDragPivot();
|
var dragPivot = this._getDragPivot();
|
||||||
return dragPivot.isVisible();
|
return dragPivot.isVisible();
|
||||||
},
|
},
|
||||||
|
|
||||||
getInnerShape : function() {
|
getInnerShape : function() {
|
||||||
return this._elem2d;
|
return this._elem2d;
|
||||||
},
|
},
|
||||||
|
|
||||||
disconnect : function(workspace) {
|
disconnect : function(workspace) {
|
||||||
// Clear connection line ...
|
// Clear connection line ...
|
||||||
var dragPivot = this._getDragPivot();
|
var dragPivot = this._getDragPivot();
|
||||||
dragPivot.disconnect(workspace);
|
dragPivot.disconnect(workspace);
|
||||||
},
|
},
|
||||||
|
|
||||||
canBeConnectedTo : function(targetTopic) {
|
canBeConnectedTo : function(targetTopic) {
|
||||||
$assert(targetTopic, 'parent can not be null');
|
$assert(targetTopic, 'parent can not be null');
|
||||||
|
|
||||||
var result = true;
|
var result = true;
|
||||||
if (!targetTopic.areChildrenShrunken() && !targetTopic.isCollapsed()) {
|
if (!targetTopic.areChildrenShrunken() && !targetTopic.isCollapsed()) {
|
||||||
// Dragged node can not be connected to himself.
|
// Dragged node can not be connected to himself.
|
||||||
if (targetTopic == this._draggedNode) {
|
if (targetTopic == this._draggedNode) {
|
||||||
result = false;
|
result = false;
|
||||||
} else {
|
} else {
|
||||||
var draggedNode = this.getDraggedTopic();
|
var draggedNode = this.getDraggedTopic();
|
||||||
var topicPosition = this.getPosition();
|
var topicPosition = this.getPosition();
|
||||||
|
|
||||||
var targetTopicModel = targetTopic.getModel();
|
var targetTopicModel = targetTopic.getModel();
|
||||||
var childTopicModel = draggedNode.getModel();
|
var childTopicModel = draggedNode.getModel();
|
||||||
|
|
||||||
result = targetTopicModel.canBeConnected(childTopicModel, topicPosition, 18, targetTopic.getSize());
|
result = targetTopicModel.canBeConnected(childTopicModel, topicPosition, 18, targetTopic.getSize());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
connectTo : function(parent) {
|
connectTo : function(parent) {
|
||||||
$assert(parent, 'Parent connection node can not be null.');
|
$assert(parent, 'Parent connection node can not be null.');
|
||||||
|
|
||||||
// Where it should be connected ?
|
// Where it should be connected ?
|
||||||
var predict = designer._eventBussDispatcher._layoutManager.predict(parent.getId(), this._draggedNode.getId(), this.getPosition());
|
var predict = designer._eventBussDispatcher._layoutManager.predict(parent.getId(), this._draggedNode.getId(), this.getPosition());
|
||||||
|
|
||||||
// Connect pivot ...
|
// Connect pivot ...
|
||||||
var dragPivot = this._getDragPivot();
|
var dragPivot = this._getDragPivot();
|
||||||
var position = predict.position;
|
var position = predict.position;
|
||||||
dragPivot.connectTo(parent, position);
|
dragPivot.connectTo(parent, position);
|
||||||
dragPivot.setVisibility(true);
|
dragPivot.setVisibility(true);
|
||||||
|
|
||||||
this.setOrder(predict.order);
|
this.setOrder(predict.order);
|
||||||
},
|
},
|
||||||
|
|
||||||
getDraggedTopic : function() {
|
getDraggedTopic : function() {
|
||||||
return this._draggedNode;
|
return this._draggedNode;
|
||||||
},
|
},
|
||||||
|
|
||||||
removeFromWorkspace : function(workspace) {
|
removeFromWorkspace : function(workspace) {
|
||||||
// Remove drag shadow.
|
// Remove drag shadow.
|
||||||
workspace.removeChild(this._elem2d);
|
workspace.removeChild(this._elem2d);
|
||||||
this._isInWorkspace = false;
|
this._isInWorkspace = false;
|
||||||
|
|
||||||
// Remove pivot shape. To improve performace it will not be removed. Only the visibility will be changed.
|
// Remove pivot shape. To improve performace it will not be removed. Only the visibility will be changed.
|
||||||
var dragPivot = this._getDragPivot();
|
var dragPivot = this._getDragPivot();
|
||||||
dragPivot.setVisibility(false);
|
dragPivot.setVisibility(false);
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
isInWorkspace: function() {
|
isInWorkspace: function() {
|
||||||
return this._isInWorkspace;
|
return this._isInWorkspace;
|
||||||
},
|
},
|
||||||
|
|
||||||
addToWorkspace : function(workspace) {
|
addToWorkspace : function(workspace) {
|
||||||
workspace.appendChild(this._elem2d);
|
workspace.appendChild(this._elem2d);
|
||||||
var dragPivot = this._getDragPivot();
|
var dragPivot = this._getDragPivot();
|
||||||
dragPivot.addToWorkspace(workspace);
|
dragPivot.addToWorkspace(workspace);
|
||||||
this._isInWorkspace = true;
|
this._isInWorkspace = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
_getDragPivot : function() {
|
_getDragPivot : function() {
|
||||||
return mindplot.DragTopic.__getDragPivot();
|
return mindplot.DragTopic.__getDragPivot();
|
||||||
},
|
},
|
||||||
|
|
||||||
getPosition:function() {
|
getPosition:function() {
|
||||||
return this._position;
|
return this._position;
|
||||||
},
|
},
|
||||||
|
|
||||||
isDragTopic : function() {
|
isDragTopic : function() {
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
applyChanges : function(workspace) {
|
applyChanges : function(workspace) {
|
||||||
$assert(workspace, 'workspace can not be null');
|
$assert(workspace, 'workspace can not be null');
|
||||||
|
|
||||||
|
|
||||||
var actionDispatcher = mindplot.ActionDispatcher.getInstance();
|
var actionDispatcher = mindplot.ActionDispatcher.getInstance();
|
||||||
var draggedTopic = this.getDraggedTopic();
|
var draggedTopic = this.getDraggedTopic();
|
||||||
var topicId = draggedTopic.getId();
|
var topicId = draggedTopic.getId();
|
||||||
var position = this.getPosition();
|
var position = this.getPosition();
|
||||||
|
|
||||||
if (!this.isFreeLayoutOn()) {
|
if (!this.isFreeLayoutOn()) {
|
||||||
var order = null;
|
var order = null;
|
||||||
var parent = null;
|
var parent = null;
|
||||||
var isDragConnected = this.isConnected();
|
var isDragConnected = this.isConnected();
|
||||||
if (isDragConnected) {
|
if (isDragConnected) {
|
||||||
var targetTopic = this.getConnectedToTopic();
|
var targetTopic = this.getConnectedToTopic();
|
||||||
order = this._order;
|
order = this._order;
|
||||||
parent = targetTopic;
|
parent = targetTopic;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the node is not connected, position based on the original drag topic position.
|
// If the node is not connected, position based on the original drag topic position.
|
||||||
actionDispatcher.dragTopic(topicId, position, order, parent);
|
actionDispatcher.dragTopic(topicId, position, order, parent);
|
||||||
} else {
|
} else {
|
||||||
actionDispatcher.moveTopic(topicId, position);
|
actionDispatcher.moveTopic(topicId, position);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getConnectedToTopic : function() {
|
getConnectedToTopic : function() {
|
||||||
var dragPivot = this._getDragPivot();
|
var dragPivot = this._getDragPivot();
|
||||||
return dragPivot.getTargetTopic();
|
return dragPivot.getTargetTopic();
|
||||||
},
|
},
|
||||||
|
|
||||||
isConnected : function() {
|
isConnected : function() {
|
||||||
return this.getConnectedToTopic() != null;
|
return this.getConnectedToTopic() != null;
|
||||||
},
|
},
|
||||||
|
|
||||||
isFreeLayoutOn: function() {
|
isFreeLayoutOn: function() {
|
||||||
return this._isFreeLayoutEnabled;
|
// return this._isFreeLayoutEnabled;
|
||||||
}
|
// Disable free layout ...
|
||||||
|
return false;
|
||||||
});
|
}
|
||||||
|
|
||||||
mindplot.DragTopic.PIVOT_SIZE = {width:50,height:6};
|
});
|
||||||
|
|
||||||
mindplot.DragTopic.init = function(workspace) {
|
mindplot.DragTopic.PIVOT_SIZE = {width:50,height:6};
|
||||||
|
|
||||||
$assert(workspace, "workspace can not be null");
|
mindplot.DragTopic.init = function(workspace) {
|
||||||
var pivot = mindplot.DragTopic.__getDragPivot();
|
|
||||||
workspace.appendChild(pivot);
|
$assert(workspace, "workspace can not be null");
|
||||||
};
|
var pivot = mindplot.DragTopic.__getDragPivot();
|
||||||
|
workspace.appendChild(pivot);
|
||||||
mindplot.DragTopic.__getDragPivot = function() {
|
};
|
||||||
var result = mindplot.DragTopic._dragPivot;
|
|
||||||
if (!$defined(result)) {
|
mindplot.DragTopic.__getDragPivot = function() {
|
||||||
result = new mindplot.DragPivot();
|
var result = mindplot.DragTopic._dragPivot;
|
||||||
mindplot.DragTopic._dragPivot = result;
|
if (!$defined(result)) {
|
||||||
}
|
result = new mindplot.DragPivot();
|
||||||
return result;
|
mindplot.DragTopic._dragPivot = result;
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -231,7 +231,6 @@ mindplot.StandaloneActionDispatcher = new Class({
|
|||||||
|
|
||||||
execute:function (command) {
|
execute:function (command) {
|
||||||
this._actionRunner.execute(command);
|
this._actionRunner.execute(command);
|
||||||
mindplot.EventBus.instance.fireEvent(mindplot.EventBus.events.DoLayout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -84,11 +84,13 @@ mindplot.commands.DeleteCommand = new Class({
|
|||||||
var parentTopic = parent[index];
|
var parentTopic = parent[index];
|
||||||
if (parentTopic != null) {
|
if (parentTopic != null) {
|
||||||
commandContext.connect(topic, parentTopic);
|
commandContext.connect(topic, parentTopic);
|
||||||
|
topic.setOnFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
this._deletedRelModel.forEach(function (model) {
|
this._deletedRelModel.forEach(function (model) {
|
||||||
commandContext.addRelationship(model);
|
commandContext.addRelationship(model);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
Loading…
Reference in New Issue
Block a user