From b2efb8ddfabb6027e84d87e5cee775320000965d Mon Sep 17 00:00:00 2001 From: crschnick Date: Tue, 11 Mar 2025 04:28:51 +0000 Subject: [PATCH] Add clear functionality for choice comps --- .../xpipe/app/comp/store/StoreChoiceComp.java | 9 +++++ .../xpipe/app/resources/style/choice-comp.css | 12 ++++++ .../ext/base/identity/IdentitySelectComp.java | 40 ++++++++++++++++--- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreChoiceComp.java b/app/src/main/java/io/xpipe/app/comp/store/StoreChoiceComp.java index 8859550ed..334069651 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreChoiceComp.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreChoiceComp.java @@ -24,6 +24,7 @@ import javafx.beans.property.SimpleStringProperty; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.control.MenuButton; +import javafx.scene.input.MouseButton; import javafx.scene.layout.Region; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; @@ -224,6 +225,14 @@ public class StoreChoiceComp extends SimpleComp { } event.consume(); }); + struc.get().setOnMouseClicked(event -> { + if (event.getButton() != MouseButton.SECONDARY) { + return; + } + + selected.setValue(mode == Mode.PROXY ? DataStorage.get().local().ref() : null); + event.consume(); + }); }) .styleClass("choice-comp"); diff --git a/app/src/main/resources/io/xpipe/app/resources/style/choice-comp.css b/app/src/main/resources/io/xpipe/app/resources/style/choice-comp.css index 2dbd5fffb..1db88bf79 100644 --- a/app/src/main/resources/io/xpipe/app/resources/style/choice-comp.css +++ b/app/src/main/resources/io/xpipe/app/resources/style/choice-comp.css @@ -2,6 +2,18 @@ -fx-focus-color: transparent; } +.combo-box-base:hover .arrow-button:hover .arrow { + -fx-background-color: -color-accent-fg; +} + +.identity-select-comp .clear-button:hover .ikonli-font-icon { + -fx-icon-color: -color-accent-fg; +} + +.identity-select-comp .clear-button { + -fx-background-color: transparent; +} + .combo-box-popup .list-cell:hover, .combo-box-popup .list-cell:focused { -fx-background-color: -color-context-menu; } diff --git a/ext/base/src/main/java/io/xpipe/ext/base/identity/IdentitySelectComp.java b/ext/base/src/main/java/io/xpipe/ext/base/identity/IdentitySelectComp.java index fac9be4b2..153e77442 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/identity/IdentitySelectComp.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/identity/IdentitySelectComp.java @@ -3,12 +3,11 @@ package io.xpipe.ext.base.identity; import io.xpipe.app.comp.Comp; import io.xpipe.app.comp.CompStructure; import io.xpipe.app.comp.SimpleCompStructure; -import io.xpipe.app.comp.base.ButtonComp; -import io.xpipe.app.comp.base.ComboTextFieldComp; -import io.xpipe.app.comp.base.HorizontalComp; +import io.xpipe.app.comp.base.*; import io.xpipe.app.comp.store.StoreCreationComp; import io.xpipe.app.comp.store.StoreEntryWrapper; import io.xpipe.app.comp.store.StoreViewState; +import io.xpipe.app.core.AppFontSizes; import io.xpipe.app.core.AppI18n; import io.xpipe.app.ext.DataStoreCreationCategory; import io.xpipe.app.storage.DataStorage; @@ -29,12 +28,16 @@ import javafx.collections.ListChangeListener; import javafx.scene.control.ListCell; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyEvent; +import javafx.scene.layout.AnchorPane; import javafx.scene.layout.HBox; import atlantafx.base.theme.Styles; +import javafx.scene.layout.Region; +import javafx.scene.layout.StackPane; import java.util.ArrayList; import java.util.LinkedHashMap; +import java.util.List; public class IdentitySelectComp extends Comp> { @@ -201,6 +204,8 @@ public class IdentitySelectComp extends Comp> { var s = formatName(newValue.get()); prop.setValue(s); }); + } else { + prop.setValue(null); } }); @@ -218,7 +223,6 @@ public class IdentitySelectComp extends Comp> { }; }); combo.apply(struc -> struc.get().setEditable(allowUserInput)); - combo.hgrow(); combo.styleClass(Styles.LEFT_PILL); combo.grow(false, true); combo.apply(struc -> { @@ -258,6 +262,32 @@ public class IdentitySelectComp extends Comp> { }); }); - return combo; + var clearButton = new IconButtonComp("mdi2c-close", () -> { + selectedReference.setValue(null); + inPlaceUser.setValue(null); + }); + clearButton.styleClass(Styles.FLAT); + clearButton.hide(selectedReference.isNull()); + clearButton.apply(struc -> { + struc.get().setOpacity(0.7); + struc.get().getStyleClass().add("clear-button"); + AppFontSizes.xs(struc.get()); + AnchorPane.setRightAnchor(struc.get(), 30.0); + AnchorPane.setTopAnchor(struc.get(), 3.0); + AnchorPane.setBottomAnchor(struc.get(), 3.0); + }); + + var stack = new AnchorComp(List.of(combo, clearButton)); + stack.styleClass("identity-select-comp"); + stack.hgrow(); + stack.apply(struc -> { + var comboRegion = (Region) struc.get().getChildren().getFirst(); + struc.get().prefWidthProperty().bind(comboRegion.prefWidthProperty()); + struc.get().prefHeightProperty().bind(comboRegion.prefHeightProperty()); + AnchorPane.setLeftAnchor(comboRegion, 0.0); + AnchorPane.setRightAnchor(comboRegion, 0.0); + }); + + return stack; } }