]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/participant/ConnectTool2.java
Simplified diagram connection creation
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / participant / ConnectTool2.java
index b77a2894714b72512c5925ea7b6379fc6e17c382..7d3a5a4005078f314f96d49b931978eabb5ad4c5 100644 (file)
@@ -90,6 +90,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;
@@ -520,6 +521,10 @@ public class ConnectTool2 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;
     }
 
@@ -662,15 +667,7 @@ public class ConnectTool2 extends AbstractMode {
             if (snapAdvisor != null)
                 snapAdvisor.snap(mouseCanvasPos);
 
-            if (isEndTerminalDefined() && connectionJudgment != null) {
-                // Clicked on an allowed end terminal. End connection & end mode.
-                createConnection();
-                remove();
-                return true;
-            } else if (lastRouteGraphTarget != null && attachToConnectionJudgement != null) {
-                lastRouteGraphTarget.getNode().showBranchPoint(null);
-                attachToConnection();
-                remove();
+            if (tryEndConnection()) {
                 return true;
             } else {
                 // Finish connection in thin air only if the
@@ -710,6 +707,33 @@ public class ConnectTool2 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 <code>true</code> if connection was successfully ended
+     */
+    private boolean tryEndConnection() {
+        if (isEndTerminalDefined() && connectionJudgment != null) {
+            createConnection();
+            remove();
+            return true;
+        } else if (lastRouteGraphTarget != null && attachToConnectionJudgement != null) {
+            lastRouteGraphTarget.getNode().showBranchPoint(null);
+            attachToConnection();
+            remove();
+            return true;
+        }
+        return false;
+    }
+
     private void attachToConnection() {
         ConnectionJudgement judgment = this.attachToConnectionJudgement;
         if (judgment == null) {