X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fparticipant%2FRouteGraphConnectTool.java;h=d1ba2174143f17aec8d14e98cae838136793a6d7;hb=refs%2Fchanges%2F72%2F2072%2F1;hp=4cccea938270b6b8ac0b50baf6ac91d2b190528a;hpb=c8cce62f9952ab3f6db451d2f22d969b4e777eaa;p=simantics%2Fplatform.git
diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/RouteGraphConnectTool.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/RouteGraphConnectTool.java
index 4cccea938..d1ba21741 100644
--- a/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/RouteGraphConnectTool.java
+++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/RouteGraphConnectTool.java
@@ -85,6 +85,7 @@ import org.simantics.scenegraph.g2d.events.KeyEvent.KeyPressedEvent;
import org.simantics.scenegraph.g2d.events.MouseEvent;
import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonEvent;
import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonPressedEvent;
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonReleasedEvent;
import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent;
import org.simantics.scenegraph.g2d.events.command.CommandEvent;
import org.simantics.scenegraph.g2d.events.command.Commands;
@@ -477,6 +478,10 @@ public class RouteGraphConnectTool extends AbstractMode {
if (me instanceof MouseButtonPressedEvent)
return processMouseButtonPress((MouseButtonPressedEvent) me);
+ // #7653: Support creating connections between terminals without lifting mouse button in between.
+ if (me instanceof MouseButtonReleasedEvent)
+ return processMouseButtonRelease((MouseButtonReleasedEvent) me);
+
return false;
}
@@ -566,10 +571,8 @@ public class RouteGraphConnectTool extends AbstractMode {
protected void disconnect(Point2D mouseCanvasPos) {
setEndTerminal(mouseCanvasPos.getX(), mouseCanvasPos.getY(), null, 0xf);
}
-
- protected boolean processMouseButtonPress(MouseButtonPressedEvent e) {
- MouseButtonEvent me = e;
+ protected boolean processMouseButtonPress(MouseButtonEvent me) {
// Do nothing before the mouse has moved at least a little.
// This prevents the user from ending the connection right where
// it started.
@@ -585,9 +588,7 @@ public class RouteGraphConnectTool extends AbstractMode {
snapAdvisor.snap(mouseCanvasPos);
// Clicked on an allowed end terminal. End connection & end mode.
- if (isEndTerminalDefined()) {
- createConnection();
- remove();
+ if (tryEndConnection()) {
return true;
} else {
// Finish connection in thin air only if the
@@ -617,6 +618,28 @@ public class RouteGraphConnectTool extends AbstractMode {
return false;
}
+ private int mouseLeftReleaseCount = 0;
+
+ protected boolean processMouseButtonRelease(MouseButtonReleasedEvent me) {
+ if (me.button == MouseEvent.LEFT_BUTTON
+ && ++mouseLeftReleaseCount == 1) {
+ return tryEndConnection();
+ }
+ return false;
+ }
+
+ /**
+ * @return true
if connection was successfully ended
+ */
+ private boolean tryEndConnection() {
+ if (isEndTerminalDefined()) {
+ createConnection();
+ remove();
+ return true;
+ }
+ return false;
+ }
+
protected boolean cancelPreviousBend() {
if (!routePointsAllowed())
return false;
@@ -816,9 +839,9 @@ public class RouteGraphConnectTool extends AbstractMode {
// ------------------------------------------------------------------------
- static RouteGraphTarget pickRouteGraphConnection(IDiagram diagram, Shape pickShape, double pickDistance) {
+ static RouteGraphTarget pickRouteGraphConnection(ICanvasContext ctx, IDiagram diagram, Shape pickShape, double pickDistance) {
ArrayList elements = new ArrayList();
- PickRequest req = new PickRequest(pickShape);
+ PickRequest req = new PickRequest(pickShape).context(ctx);
DiagramUtils.pick(diagram, req, elements);
for (Iterator it = elements.iterator(); it.hasNext();) {
IElement e = it.next();