From 9076fe5b4652fbcbf2f591bb8639f70f5965db91 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Fri, 6 Nov 2020 11:07:45 +0100 Subject: [PATCH] Reintroduced trimming of vault display name --- .../vaultoptions/GeneralVaultOptionsController.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/main/ui/src/main/java/org/cryptomator/ui/vaultoptions/GeneralVaultOptionsController.java b/main/ui/src/main/java/org/cryptomator/ui/vaultoptions/GeneralVaultOptionsController.java index 562660f9b..abf233c2b 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/vaultoptions/GeneralVaultOptionsController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/vaultoptions/GeneralVaultOptionsController.java @@ -5,6 +5,7 @@ import org.cryptomator.common.vaults.Vault; import org.cryptomator.ui.common.FxController; import javax.inject.Inject; +import javafx.beans.Observable; import javafx.fxml.FXML; import javafx.scene.control.CheckBox; import javafx.scene.control.ChoiceBox; @@ -36,7 +37,8 @@ public class GeneralVaultOptionsController implements FxController { @FXML public void initialize() { - vaultName.textProperty().bindBidirectional(vault.getVaultSettings().displayName()); + vaultName.textProperty().set(vault.getVaultSettings().displayName().get()); + vaultName.focusedProperty().addListener(this::checkTrimAndTuncateVaultName); vaultName.setTextFormatter(new TextFormatter<>(this::checkVaultNameLength)); unlockOnStartupCheckbox.selectedProperty().bindBidirectional(vault.getVaultSettings().unlockAfterStartup()); actionAfterUnlockChoiceBox.getItems().addAll(WhenUnlocked.values()); @@ -44,6 +46,13 @@ public class GeneralVaultOptionsController implements FxController { actionAfterUnlockChoiceBox.setConverter(new WhenUnlockedConverter(resourceBundle)); } + private void checkTrimAndTuncateVaultName(Observable observable, Boolean wasFocussed, Boolean isFocussed) { + if (!isFocussed) { + var trimmed = vaultName.getText().trim(); + vault.getVaultSettings().displayName().set(trimmed); + } + } + private TextFormatter.Change checkVaultNameLength(TextFormatter.Change change) { if (change.isContentChange() && change.getControlNewText().length() > VAULTNAME_TRUNCATE_THRESHOLD) { return null; // reject any change that would lead to a text exceeding threshold