فهرست منبع

Reintroduced trimming of vault display name

Sebastian Stenzel 4 سال پیش
والد
کامیت
9076fe5b46
1فایلهای تغییر یافته به همراه10 افزوده شده و 1 حذف شده
  1. 10 1
      main/ui/src/main/java/org/cryptomator/ui/vaultoptions/GeneralVaultOptionsController.java

+ 10 - 1
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