Reintroduced trimming of vault display name

This commit is contained in:
Sebastian Stenzel
2020-11-06 11:07:45 +01:00
parent 6848f1a38e
commit 9076fe5b46

View File

@@ -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