From ab2fd6f9a2fee9aaa780d286cfdc59d6f8b9ff98 Mon Sep 17 00:00:00 2001 From: crschnick Date: Thu, 7 May 2026 20:53:43 +0000 Subject: [PATCH] Rework --- .../io/xpipe/app/comp/base/ChoiceComp.java | 21 ++++++++++++++++++ .../xpipe/app/comp/base/ChoicePaneComp.java | 16 ++++++++++++++ .../io/xpipe/app/cred/KeyFileStrategy.java | 22 +++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/app/src/main/java/io/xpipe/app/comp/base/ChoiceComp.java b/app/src/main/java/io/xpipe/app/comp/base/ChoiceComp.java index daa6d3699..251799e7b 100644 --- a/app/src/main/java/io/xpipe/app/comp/base/ChoiceComp.java +++ b/app/src/main/java/io/xpipe/app/comp/base/ChoiceComp.java @@ -50,6 +50,27 @@ public class ChoiceComp extends RegionBuilder> { public ComboBox createSimple() { var cb = MenuHelper.createComboBox(); + cb.setConverter(new StringConverter<>() { + @Override + public String toString(T object) { + if (object == null) { + return AppI18n.get("none"); + } + + var found = range.getValue().get(object); + if (found == null) { + return ""; + } + + return found.getValue(); + } + + @Override + public T fromString(String string) { + throw new UnsupportedOperationException(); + } + }); + // Reset converter on language change to force an update // This does not work properly in older JFX versions, see JDK-8384006 var ref = new WeakReference<>(cb); diff --git a/app/src/main/java/io/xpipe/app/comp/base/ChoicePaneComp.java b/app/src/main/java/io/xpipe/app/comp/base/ChoicePaneComp.java index ce3274211..4454e0b43 100644 --- a/app/src/main/java/io/xpipe/app/comp/base/ChoicePaneComp.java +++ b/app/src/main/java/io/xpipe/app/comp/base/ChoicePaneComp.java @@ -49,6 +49,22 @@ public class ChoicePaneComp extends RegionBuilder { }); cb.getSelectionModel().select(selected.getValue()); + cb.setConverter(new StringConverter<>() { + @Override + public String toString(Entry object) { + if (object == null || object.name() == null) { + return ""; + } + + return object.name().getValue(); + } + + @Override + public Entry fromString(String string) { + throw new UnsupportedOperationException(); + } + }); + // Reset converter on language change to force an update // This does not work properly in older JFX versions, see JDK-8384006 var ref = new WeakReference<>(cb); diff --git a/app/src/main/java/io/xpipe/app/cred/KeyFileStrategy.java b/app/src/main/java/io/xpipe/app/cred/KeyFileStrategy.java index 6428d84d5..a4e1fe8a5 100644 --- a/app/src/main/java/io/xpipe/app/cred/KeyFileStrategy.java +++ b/app/src/main/java/io/xpipe/app/cred/KeyFileStrategy.java @@ -4,6 +4,7 @@ import io.xpipe.app.comp.base.*; import io.xpipe.app.core.AppI18n; import io.xpipe.app.core.AppSystemInfo; import io.xpipe.app.ext.ProcessControlProvider; +import io.xpipe.app.ext.ShellStore; import io.xpipe.app.ext.ValidationException; import io.xpipe.app.issue.ErrorEventFactory; import io.xpipe.app.platform.ClipboardHelper; @@ -140,6 +141,27 @@ public class KeyFileStrategy implements SshIdentityStrategy { var publicKeyBox = new InputGroupComp(List.of(publicKeyField, copyButton, generateButton)); publicKeyBox.setMainReference(publicKeyField); + keyPath.addListener((observable, oldValue, newValue) -> { + if (newValue == null) { + return; + } + + ThreadHelper.runFailableAsync(() -> { + var pubFile = SshIdentityStrategy.getPublicKeyPath(newValue); + var fs = + config.getFileSystem() != null && config.getFileSystem().getValue() != null + ? config.getFileSystem().getValue().getStore() + : (ShellStore) DataStorage.get().local().getStore(); + var ex = fs.getOrStartSession().view().fileExists(pubFile); + if (ex) { + var contents = fs.getOrStartSession().view().readTextFile(pubFile).strip(); + Platform.runLater(() -> { + publicKey.set(contents); + }); + } + }); + }); + return new OptionsBuilder() .name("location") .description("locationDescription")