mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-09-23 00:45:35 +00:00
Improve double click handling for connections
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user