Browse files

Added moveLinePointCommand.

  • Loading branch information...
1 parent ec6bef8 commit 54362c21e7ca43b7e16753e634fc5690a64a9992 @romario333 committed Apr 1, 2012
Showing with 60 additions and 23 deletions.
  1. +45 −1 src/presenter/commands.js
  2. +15 −22 src/presenter/diagramPresenter.js
View
46 src/presenter/commands.js
@@ -1,6 +1,8 @@
var WIKIDIA = WIKIDIA || {};
WIKIDIA.presenter = WIKIDIA.presenter || {};
+// TODO: it would be probably better not to store whole items in originalData
+
WIKIDIA.presenter.moveCommand = function (items) {
"use strict";
@@ -203,6 +205,7 @@ WIKIDIA.presenter.createLineCommand = function (diagram, node, x1, y1) {
that.connectTo(node);
}
+ // TODO: I should be able to undo connection
that.connectTo = function (item) {
console.log("Connecting line to node {nodeId}.".supplant({nodeId: item.oid}));
line.addConnection(item);
@@ -237,4 +240,45 @@ WIKIDIA.presenter.createLineCommand = function (diagram, node, x1, y1) {
return that;
};
-// TODO: moveLinePointCommand
+WIKIDIA.presenter.moveLinePointCommand = function (line, whichPoint) {
+ "use strict";
+
+ var that = {},
+ originalLine;
+
+ originalLine = line.copyShallow();
+
+ that.dx = 0;
+ that.dy = 0;
+
+ that.connectTo = function (item) {
+ console.log("Connecting line to node {nodeId}.".supplant({nodeId: item.oid}));
+ line.addConnection(item);
+ };
+
+ that.preview = function () {
+ that.execute();
+ };
+
+ that.cancelPreview = function () {
+ that.undo();
+ };
+
+ that.execute = function () {
+ line.changeEventsEnabled = false;
+ line["x" + whichPoint] = originalLine["x" + whichPoint] + that.dx;
+ line["y" + whichPoint] = originalLine["y" + whichPoint] + that.dy;
+ line.changeEventsEnabled = true;
+ line.fireChange();
+ };
+
+ that.undo = function () {
+ line.changeEventsEnabled = false;
+ line["x" + whichPoint] = originalLine["x" + whichPoint];
+ line["y" + whichPoint] = originalLine["y" + whichPoint];
+ line.changeEventsEnabled = true;
+ line.fireChange();
+ };
+
+ return that;
+};
View
37 src/presenter/diagramPresenter.js
@@ -169,7 +169,6 @@ WIKIDIA.presenter.diagramPresenter = function (diagramView, diagram, viewFactory
item.view = lineView;
item.isSelected = false;
- // TODO: je fakt vyhodny mit nodes i lines v jedny items kolekci? davam to tam jen kvuli hunch
items.push(item);
line.change(onLineChange);
@@ -265,8 +264,6 @@ WIKIDIA.presenter.diagramPresenter = function (diagramView, diagram, viewFactory
}
- var dragStartX, dragStartY;
-
function onNodeDragStart(nodeView) {
commandInProgress = WIKIDIA.presenter.moveCommand(selection.items());
}
@@ -338,6 +335,7 @@ WIKIDIA.presenter.diagramPresenter = function (diagramView, diagram, viewFactory
function onNodeConnectPointDragEnd(nodeView, dx, dy) {
commandInProgress.cancelPreview();
commandExecutor.execute(commandInProgress);
+ commandInProgress = null;
isCreatingLineFromNode = false;
}
@@ -358,41 +356,36 @@ WIKIDIA.presenter.diagramPresenter = function (diagramView, diagram, viewFactory
renderer.showNearbyConnectionPoint(node.data, nodeView, x, y, GRID_STEP);
}
- var whichEndOfLine; // TODO: to the top
-
function onLineConnectPointDragStart(lineView, connectPointX, connectPointY) {
- // TODO: dragStartX uz nic moc nazev ted kdyz to pouzivam i tady
- dragStartX = connectPointX;
- dragStartY = connectPointY;
-
lineView.hideConnectionPoints();
- var line = items.itemForView(lineView);
+ var whichPoint;
+ var line = items.itemForView(lineView).data;
if (line.x1 === connectPointX && line.x2 === connectPointY) {
- whichEndOfLine = "1";
+ whichPoint = "1";
} else {
- whichEndOfLine = "2";
+ whichPoint = "2";
}
- line.changeEventsEnabled = false;
+ commandInProgress = WIKIDIA.presenter.moveLinePointCommand(line, whichPoint);
}
function onLineConnectPointDragMove(lineView, dx, dy) {
- var line = items.itemForView(lineView).data;
- var snapped = snapToGrid({x: dragStartX + dx, y: dragStartY + dy});
- console.log("in = [{x}, {y}], snapped = [{sx}, {sy}]".supplant({x: dragStartX + dx, y: dragStartY + dy, sx: snapped.x, sy: snapped.y}));
- console.dir(line);
- line["x" + whichEndOfLine] = snapped.x;
- line["y" + whichEndOfLine] = snapped.y;
- line.fireChange();
+ var snapped = snapToGrid({x: dx, y: dy});
+ commandInProgress.dx = snapped.x;
+ commandInProgress.dy = snapped.y;
+ commandInProgress.preview();
}
function onLineConnectPointMouseUp(lineView, connectPointX, connectPointY) {
+ var line = items.itemForView(lineView).data;
+ commandInProgress.connectTo(line);
}
function onLineConnectPointDragEnd(lineView, dx, dy) {
- var line = items.itemForView(lineView);
- line.changeEventsEnabled = true;
+ commandInProgress.cancelPreview();
+ commandExecutor.execute(commandInProgress);
+ commandInProgress = null;
}
function onLineMouseEnter(lineView) {

0 comments on commit 54362c2

Please sign in to comment.