Improve double click handling for connections

This commit is contained in:
crschnick
2024-12-12 16:53:07 +00:00
parent db5f30cfff
commit e1941f83da
2 changed files with 40 additions and 2 deletions
@@ -87,6 +87,8 @@ public abstract class StoreEntryComp extends SimpleComp {
@Override
protected final Region createSimple() {
var r = createContent();
var buttonBar = r.lookup(".button-bar");
var iconChooser = r.lookup(".icon");
var button = new Button();
button.setGraphic(r);
@@ -103,7 +105,8 @@ public abstract class StoreEntryComp extends SimpleComp {
});
});
button.addEventFilter(MouseEvent.MOUSE_CLICKED, event -> {
if (AppPrefs.get().requireDoubleClickForConnections().get()) {
var notOnButton = NodeHelper.isParent(iconChooser, event.getTarget()) || NodeHelper.isParent(buttonBar, event.getTarget());
if (AppPrefs.get().requireDoubleClickForConnections().get() && !notOnButton) {
if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() != 2) {
event.consume();
}
@@ -114,7 +117,8 @@ public abstract class StoreEntryComp extends SimpleComp {
}
});
button.addEventFilter(MouseEvent.MOUSE_PRESSED, event -> {
if (AppPrefs.get().requireDoubleClickForConnections().get()) {
var notOnButton = NodeHelper.isParent(iconChooser, event.getTarget()) || NodeHelper.isParent(buttonBar, event.getTarget());
if (AppPrefs.get().requireDoubleClickForConnections().get() && !notOnButton) {
if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() != 2) {
event.consume();
}
@@ -0,0 +1,34 @@
package io.xpipe.app.util;
import javafx.scene.Node;
import javafx.scene.Parent;
import java.util.Set;
public class NodeHelper {
public static boolean isParent(Set<Node> parent, Object child) {
return parent.stream().anyMatch(node -> isParent(node, child));
}
public static boolean isParent(Node parent, Object child) {
if (child == null) {
return false;
}
if (!(child instanceof Node n)) {
return false;
}
var c = n.getParent();
while (c != null) {
if (c == parent) {
return true;
}
c = c.getParent();
}
return false;
}
}