From 2f4d72c63ffecfceae1ded469ab6e3ba4f06312f Mon Sep 17 00:00:00 2001 From: crschnick Date: Wed, 24 Jul 2024 03:52:53 +0000 Subject: [PATCH] Improve display names --- .../xpipe/app/browser/BrowserWelcomeComp.java | 4 +- .../browser/session/BrowserSessionTab.java | 2 +- .../xpipe/app/comp/store/StoreEntryComp.java | 2 +- .../io/xpipe/app/ext/DataStoreProvider.java | 7 +- .../io/xpipe/app/issue/ErrorHandlerComp.java | 2 +- .../io/xpipe/app/storage/DataStorage.java | 16 +-- .../io/xpipe/app/util/DataStoreFormatter.java | 45 ------- .../java/io/xpipe/app/util/DialogHelper.java | 116 ------------------ dist/changelogs/10.2_incremental.md | 4 +- .../ext/base/action/LaunchStoreAction.java | 2 +- .../service/AbstractServiceStoreProvider.java | 5 + .../service/MappedServiceStoreProvider.java | 7 ++ 12 files changed, 26 insertions(+), 186 deletions(-) delete mode 100644 app/src/main/java/io/xpipe/app/util/DialogHelper.java diff --git a/app/src/main/java/io/xpipe/app/browser/BrowserWelcomeComp.java b/app/src/main/java/io/xpipe/app/browser/BrowserWelcomeComp.java index d24e67a55..ab9a252ce 100644 --- a/app/src/main/java/io/xpipe/app/browser/BrowserWelcomeComp.java +++ b/app/src/main/java/io/xpipe/app/browser/BrowserWelcomeComp.java @@ -147,7 +147,7 @@ public class BrowserWelcomeComp extends SimpleComp { entry.get().getProvider().getDisplayIconFileName(entry.get().getStore()); var view = PrettyImageHelper.ofFixedSize(graphic, 30, 24); return new ButtonComp( - new SimpleStringProperty(DataStorage.get().getStoreDisplayName(entry.get())), + new SimpleStringProperty(DataStorage.get().getStoreEntryDisplayName(entry.get())), view.createRegion(), () -> { ThreadHelper.runAsync(() -> { @@ -158,7 +158,7 @@ public class BrowserWelcomeComp extends SimpleComp { }); }) .minWidth(250) - .accessibleText(DataStorage.get().getStoreDisplayName(entry.get())) + .accessibleText(DataStorage.get().getStoreEntryDisplayName(entry.get())) .disable(disable) .styleClass("entry-button") .styleClass(Styles.LEFT_PILL) diff --git a/app/src/main/java/io/xpipe/app/browser/session/BrowserSessionTab.java b/app/src/main/java/io/xpipe/app/browser/session/BrowserSessionTab.java index 64414f537..09bda38fa 100644 --- a/app/src/main/java/io/xpipe/app/browser/session/BrowserSessionTab.java +++ b/app/src/main/java/io/xpipe/app/browser/session/BrowserSessionTab.java @@ -22,7 +22,7 @@ public abstract class BrowserSessionTab { public BrowserSessionTab(BrowserAbstractSessionModel browserModel, DataStoreEntryRef entry) { this.browserModel = browserModel; this.entry = entry; - this.name = DataStorage.get().getStoreDisplayName(entry.get()); + this.name = DataStorage.get().getStoreEntryDisplayName(entry.get()); this.tooltip = DataStorage.get().getStorePath(entry.getEntry()).toString(); } diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreEntryComp.java b/app/src/main/java/io/xpipe/app/comp/store/StoreEntryComp.java index e9ffa692c..1408dd769 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreEntryComp.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreEntryComp.java @@ -478,7 +478,7 @@ public abstract class StoreEntryComp extends SimpleComp { ThreadHelper.runFailableAsync(() -> { DesktopShortcuts.create( url, - getWrapper().nameProperty().getValue() + " (" + DataStorage.get().getStoreEntryDisplayName(getWrapper().getEntry()) + " (" + p.getLeafDataStoreCallSite() .getName(getWrapper().getEntry().ref()) .getValue() + ")"); diff --git a/app/src/main/java/io/xpipe/app/ext/DataStoreProvider.java b/app/src/main/java/io/xpipe/app/ext/DataStoreProvider.java index e3bca12be..0d7a5badd 100644 --- a/app/src/main/java/io/xpipe/app/ext/DataStoreProvider.java +++ b/app/src/main/java/io/xpipe/app/ext/DataStoreProvider.java @@ -10,11 +10,9 @@ import io.xpipe.app.core.AppI18n; import io.xpipe.app.core.AppImages; import io.xpipe.app.fxcomps.Comp; import io.xpipe.app.issue.ErrorEvent; -import io.xpipe.app.storage.DataStorage; import io.xpipe.app.storage.DataStoreEntry; import io.xpipe.core.store.DataStore; import io.xpipe.core.util.JacksonizedValue; - import javafx.beans.binding.Bindings; import javafx.beans.property.BooleanProperty; import javafx.beans.property.Property; @@ -73,9 +71,8 @@ public interface DataStoreProvider { return null; } - default String browserDisplayName(DataStore store) { - var e = DataStorage.get().getStoreDisplayName(store); - return e.orElse("?"); + default String browserDisplayName(DataStoreEntry entry) { + return entry.getName(); } default List getSearchableTerms(DataStore store) { diff --git a/app/src/main/java/io/xpipe/app/issue/ErrorHandlerComp.java b/app/src/main/java/io/xpipe/app/issue/ErrorHandlerComp.java index 92f08bfa2..d5054accc 100644 --- a/app/src/main/java/io/xpipe/app/issue/ErrorHandlerComp.java +++ b/app/src/main/java/io/xpipe/app/issue/ErrorHandlerComp.java @@ -205,7 +205,7 @@ public class ErrorHandlerComp extends SimpleComp { header.setGraphicTextGap(6); AppFont.setSize(header, 3); var descriptionField = new TextArea(desc); - descriptionField.setPrefRowCount(Math.min((int) desc.lines().count(), 14)); + descriptionField.setPrefRowCount(Math.max(5, Math.min((int) desc.lines().count(), 14))); descriptionField.setWrapText(true); descriptionField.setEditable(false); descriptionField.setPadding(Insets.EMPTY); diff --git a/app/src/main/java/io/xpipe/app/storage/DataStorage.java b/app/src/main/java/io/xpipe/app/storage/DataStorage.java index 55dc5b8e9..2b116e836 100644 --- a/app/src/main/java/io/xpipe/app/storage/DataStorage.java +++ b/app/src/main/java/io/xpipe/app/storage/DataStorage.java @@ -870,24 +870,16 @@ public abstract class DataStorage { .findFirst(); } - public Optional getStoreDisplayName(DataStore store) { - if (store == null) { - return Optional.empty(); - } - - return getStoreEntryIfPresent(store, true).map(dataStoreEntry -> dataStoreEntry.getName()); - } - - public String getStoreDisplayName(DataStoreEntry store) { - if (store == null) { + public String getStoreEntryDisplayName(DataStoreEntry entry) { + if (entry == null) { return "?"; } - if (!store.getValidity().isUsable()) { + if (!entry.getValidity().isUsable()) { return "?"; } - return store.getProvider().browserDisplayName(store.getStore()); + return entry.getProvider().browserDisplayName(entry); } public Optional getStoreEntryIfPresent(UUID id) { diff --git a/app/src/main/java/io/xpipe/app/util/DataStoreFormatter.java b/app/src/main/java/io/xpipe/app/util/DataStoreFormatter.java index efbaf5757..63f347d76 100644 --- a/app/src/main/java/io/xpipe/app/util/DataStoreFormatter.java +++ b/app/src/main/java/io/xpipe/app/util/DataStoreFormatter.java @@ -2,17 +2,11 @@ package io.xpipe.app.util; import io.xpipe.app.comp.store.StoreEntryWrapper; import io.xpipe.app.fxcomps.util.BindingsHelper; -import io.xpipe.app.storage.DataStorage; import io.xpipe.app.storage.DataStoreEntry; import io.xpipe.core.process.ShellDialects; import io.xpipe.core.process.ShellStoreState; -import io.xpipe.core.store.DataStore; -import io.xpipe.core.store.ShellStore; - import javafx.beans.value.ObservableValue; -import java.util.function.IntFunction; - public class DataStoreFormatter { public static String formattedOsName(String osName) { @@ -61,49 +55,10 @@ public class DataStoreFormatter { return name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase(); } - public static String formatSubHost(IntFunction func, DataStore at, int length) { - var atString = at instanceof ShellStore shellStore && !ShellStore.isLocal(shellStore) - ? DataStorage.get().getStoreDisplayName(at).orElse(null) - : null; - if (atString == null) { - return func.apply(length); - } - - var fileString = func.apply(length - atString.length() - 1); - return String.format("%s/%s", atString, fileString); - } - - public static String formatAtHost(IntFunction func, DataStore at, int length) { - var atString = at instanceof ShellStore shellStore && !ShellStore.isLocal(shellStore) - ? DataStorage.get().getStoreDisplayName(at).orElse(null) - : null; - if (atString == null) { - return func.apply(length); - } - - var fileString = func.apply(length - atString.length() - 3); - return String.format("%s @ %s", fileString, atString); - } - - public static String formatViaProxy(IntFunction func, DataStoreEntry at, int length) { - var atString = - at.getStore() instanceof ShellStore shellStore && !ShellStore.isLocal(shellStore) ? at.getName() : null; - if (atString == null) { - return func.apply(length); - } - - var fileString = func.apply(length - atString.length() - 3); - return String.format("%s > %s", atString, fileString); - } - public static String toApostropheName(DataStoreEntry input) { return toName(input, Integer.MAX_VALUE) + "'s"; } - public static String toName(DataStoreEntry input) { - return toName(input, Integer.MAX_VALUE); - } - public static String toName(DataStoreEntry input, int length) { if (input == null) { return "?"; diff --git a/app/src/main/java/io/xpipe/app/util/DialogHelper.java b/app/src/main/java/io/xpipe/app/util/DialogHelper.java deleted file mode 100644 index 48a18f4b2..000000000 --- a/app/src/main/java/io/xpipe/app/util/DialogHelper.java +++ /dev/null @@ -1,116 +0,0 @@ -package io.xpipe.app.util; - -import io.xpipe.app.storage.DataStorage; -import io.xpipe.core.dialog.Dialog; -import io.xpipe.core.dialog.QueryConverter; -import io.xpipe.core.store.*; -import io.xpipe.core.util.NewLine; -import io.xpipe.core.util.SecretValue; -import io.xpipe.core.util.StreamCharset; - -import lombok.Value; - -public class DialogHelper { - - public static Dialog addressQuery(Address address) { - var hostNameQuery = Dialog.query("Hostname", false, true, false, address.getHostname(), QueryConverter.STRING); - var portQuery = Dialog.query("Port", false, true, false, address.getPort(), QueryConverter.INTEGER); - return Dialog.chain(hostNameQuery, portQuery) - .evaluateTo(() -> new Address(hostNameQuery.getResult(), portQuery.getResult())); - } - - public static Dialog machineQuery(DataStore store) { - var storeName = DataStorage.get().getStoreDisplayName(store).orElse("localhost"); - return Dialog.query("Machine", false, true, false, storeName, QueryConverter.STRING) - .map((String name) -> { - if (name.equals("local") || name.equals("localhost")) { - return new LocalStore(); - } - - var stored = DataStorage.get().getStoreEntryIfPresent(name).map(entry -> entry.getStore()); - if (stored.isEmpty()) { - throw new IllegalArgumentException(String.format("Store not found: %s", name)); - } - - if (!(stored.get() instanceof FileSystem)) { - throw new IllegalArgumentException(String.format("Store not a machine store: %s", name)); - } - - return stored.get(); - }); - } - - public static Dialog shellQuery(String displayName, DataStore store) { - var storeName = DataStorage.get().getStoreDisplayName(store).orElse("localhost"); - return Dialog.query(displayName, false, true, false, storeName, QueryConverter.STRING) - .map((String name) -> { - if (name.equals("local") || name.equals("localhost")) { - return new LocalStore(); - } - - var stored = DataStorage.get().getStoreEntryIfPresent(name).map(entry -> entry.getStore()); - if (stored.isEmpty()) { - throw new IllegalArgumentException(String.format("Store not found: %s", name)); - } - - if (!(stored.get() instanceof ShellStore)) { - throw new IllegalArgumentException(String.format("Store not a shell store: %s", name)); - } - - return stored.get(); - }); - } - - public static Dialog charsetQuery(StreamCharset c, boolean preferQuiet) { - return Dialog.query("Charset", false, true, c != null && preferQuiet, c, QueryConverter.CHARSET); - } - - public static Dialog newLineQuery(NewLine n, boolean preferQuiet) { - return Dialog.query("Newline", false, true, n != null && preferQuiet, n, QueryConverter.NEW_LINE); - } - - public static Dialog query(String desc, T value, boolean required, QueryConverter c, boolean preferQuiet) { - return Dialog.query(desc, false, required, value != null && preferQuiet, value, c); - } - - public static Dialog booleanChoice(String desc, boolean value, boolean preferQuiet) { - return Dialog.choice(desc, val -> val.toString(), true, preferQuiet, value, Boolean.TRUE, Boolean.FALSE); - } - - public static Dialog fileQuery(String name) { - return Dialog.query("File", true, true, false, name, QueryConverter.STRING); - } - - public static Dialog userQuery(String name) { - return Dialog.query("User", false, true, false, name, QueryConverter.STRING); - } - - public static Dialog namedStoreQuery(DataStore store, Class filter) { - var name = DataStorage.get().getStoreDisplayName(store).orElse(null); - return Dialog.query("Store", false, true, false, name, QueryConverter.STRING) - .map((String newName) -> { - var found = DataStorage.get() - .getStoreEntryIfPresent(newName) - .map(entry -> entry.getStore()) - .orElseThrow(); - if (!filter.isAssignableFrom(found.getClass())) { - throw new IllegalArgumentException("Incompatible store type"); - } - return found; - }); - } - - public static Dialog passwordQuery(SecretValue password) { - return Dialog.querySecret("Password", false, true, password); - } - - public static Dialog timeoutQuery(Integer timeout) { - return Dialog.query("Timeout", false, true, false, timeout, QueryConverter.INTEGER); - } - - @Value - public static class Address { - String hostname; - Integer port; - } -} diff --git a/dist/changelogs/10.2_incremental.md b/dist/changelogs/10.2_incremental.md index 36c411678..554b587eb 100644 --- a/dist/changelogs/10.2_incremental.md +++ b/dist/changelogs/10.2_incremental.md @@ -1,7 +1,7 @@ ## File browser improvements - Add right click context menu to browser tabs -- Add ability to select tabs with function keys, e.g. F1 +- Add ability to select tabs with function keys, e.g. F1, F2, ... - Add ability to cycle between tabs with CTRL+TAB and CTRL+SHIFT+TAB - Fix some keyboard shortcuts being broken - Fix pressing enter on rename also opening file @@ -18,7 +18,7 @@ - Add support for VNC RSA-AES authentication schemes, allowing to connect to more types of VNC servers - Services can now be opened in a browser using either HTTP or HTTPs - You can now create shortcuts to automatically forward and open services in a browser -- Fix doctor containers in some cases not persisting, leaving invalid orphan connections behind on the bottom +- Fix docker containers in some cases not persisting, leaving invalid orphan connections behind on the bottom - Improve description for service groups - Publish API libraries to maven central - Show warning when launching PowerShell in constrained language mode diff --git a/ext/base/src/main/java/io/xpipe/ext/base/action/LaunchStoreAction.java b/ext/base/src/main/java/io/xpipe/ext/base/action/LaunchStoreAction.java index 450eb5a94..9ebaa088a 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/action/LaunchStoreAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/action/LaunchStoreAction.java @@ -90,7 +90,7 @@ public class LaunchStoreAction implements ActionProvider { @Override public void execute() throws Exception { - var storeName = DataStorage.get().getStoreDisplayName(entry); + var storeName = DataStorage.get().getStoreEntryDisplayName(entry); if (entry.getStore() instanceof ShellStore s) { TerminalLauncher.open(entry, storeName, null, ScriptStore.controlWithDefaultScripts(s.control())); return; diff --git a/ext/base/src/main/java/io/xpipe/ext/base/service/AbstractServiceStoreProvider.java b/ext/base/src/main/java/io/xpipe/ext/base/service/AbstractServiceStoreProvider.java index f577849d7..d0a8093be 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/service/AbstractServiceStoreProvider.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/service/AbstractServiceStoreProvider.java @@ -23,6 +23,11 @@ import java.util.List; public abstract class AbstractServiceStoreProvider implements SingletonSessionStoreProvider, DataStoreProvider { + public String browserDisplayName(DataStoreEntry entry) { + AbstractServiceStore s = entry.getStore().asNeeded(); + return DataStorage.get().getStoreEntryDisplayName(s.getHost().get()) + " - Port " + s.getRemotePort(); + } + @Override public DataStoreUsageCategory getUsageCategory() { return DataStoreUsageCategory.TUNNEL; diff --git a/ext/base/src/main/java/io/xpipe/ext/base/service/MappedServiceStoreProvider.java b/ext/base/src/main/java/io/xpipe/ext/base/service/MappedServiceStoreProvider.java index c057051b7..ea5641424 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/service/MappedServiceStoreProvider.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/service/MappedServiceStoreProvider.java @@ -1,6 +1,8 @@ package io.xpipe.ext.base.service; import io.xpipe.app.comp.store.StoreSection; +import io.xpipe.app.storage.DataStorage; +import io.xpipe.app.storage.DataStoreEntry; import javafx.beans.property.SimpleStringProperty; import javafx.beans.value.ObservableValue; @@ -8,6 +10,11 @@ import java.util.List; public class MappedServiceStoreProvider extends FixedServiceStoreProvider { + public String browserDisplayName(DataStoreEntry entry) { + MappedServiceStore s = entry.getStore().asNeeded(); + return DataStorage.get().getStoreEntryDisplayName(s.getHost().get()) + " - Port " + s.getContainerPort(); + } + @Override public List getPossibleNames() { return List.of("mappedService");