From 7e60e5606cc77e158896b67b054dcdc46ba7d884 Mon Sep 17 00:00:00 2001 From: Tobias Hagemann Date: Tue, 12 Feb 2019 01:56:35 +0100 Subject: [PATCH] Updated custom mount point layout --- .../ui/controllers/UnlockController.java | 32 ++++++++++++++----- main/ui/src/main/resources/fxml/unlock.fxml | 10 +++--- .../ui/src/main/resources/localization/en.txt | 5 ++- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java b/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java index c2c50bdc5..ad9d8d827 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controllers/UnlockController.java @@ -26,7 +26,6 @@ import javafx.scene.control.Label; import javafx.scene.control.ProgressIndicator; import javafx.scene.control.TextField; import javafx.scene.input.KeyEvent; -import javafx.scene.input.MouseEvent; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.text.Text; @@ -40,7 +39,6 @@ import org.cryptomator.common.settings.VaultSettings; import org.cryptomator.common.settings.VolumeImpl; import org.cryptomator.cryptolib.api.InvalidPassphraseException; import org.cryptomator.cryptolib.api.UnsupportedVaultFormatException; -import org.cryptomator.frontend.webdav.ServerLifecycleException; import org.cryptomator.keychain.KeychainAccess; import org.cryptomator.ui.controls.SecPasswordField; import org.cryptomator.ui.l10n.Localization; @@ -58,6 +56,8 @@ import javax.inject.Named; import java.io.File; import java.nio.file.DirectoryNotEmptyException; import java.nio.file.NotDirectoryException; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Arrays; import java.util.Comparator; import java.util.Objects; @@ -130,7 +130,7 @@ public class UnlockController implements ViewController { private HBox customMountPoint; @FXML - private Label customMountPointField; + private Label customMountPointLabel; @FXML private ProgressIndicator progressIndicator; @@ -246,7 +246,11 @@ public class UnlockController implements ViewController { useReadOnlyMode.setSelected(vaultSettings.usesReadOnlyMode().get()); if (!settings.preferredVolumeImpl().get().equals(VolumeImpl.WEBDAV)) { useCustomMountPoint.setSelected(vaultSettings.usesIndividualMountPath().get()); - customMountPointField.textProperty().setValue(vaultSettings.individualMountPath().getValueSafe()); + if (vaultSettings.individualMountPath().get() == null) { + customMountPointLabel.textProperty().setValue(localization.getString("unlock.label.chooseMountPath")); + } else { + customMountPointLabel.textProperty().setValue(displayablePath(vaultSettings.individualMountPath().getValueSafe())); + } } vaultSubs = vaultSubs.and(EasyBind.subscribe(unlockAfterStartup.selectedProperty(), vaultSettings.unlockAfterStartup()::set)); @@ -255,6 +259,18 @@ public class UnlockController implements ViewController { vaultSubs = vaultSubs.and(EasyBind.subscribe(useReadOnlyMode.selectedProperty(), vaultSettings.usesReadOnlyMode()::set)); } + private String displayablePath(String path) { + Path homeDir = Paths.get(SystemUtils.USER_HOME); + Path p = Paths.get(path); + if (p.startsWith(homeDir)) { + Path relativePath = homeDir.relativize(p); + String homePrefix = SystemUtils.IS_OS_WINDOWS ? "~\\" : "~/"; + return homePrefix + relativePath.toString(); + } else { + return p.toString(); + } + } + // **************************************** // Downloads link // **************************************** @@ -298,7 +314,7 @@ public class UnlockController implements ViewController { DirectoryChooser dirChooser = new DirectoryChooser(); File file = dirChooser.showDialog(mainWindow); if (file != null) { - customMountPointField.setText(file.toString()); + customMountPointLabel.setText(displayablePath(file.toString())); vault.setCustomMountPath(file.toString()); } } @@ -476,9 +492,9 @@ public class UnlockController implements ViewController { /* state */ public enum State { - UNLOCKING(null), - INITIALIZED("unlock.successLabel.vaultCreated"), - PASSWORD_CHANGED("unlock.successLabel.passwordChanged"), + UNLOCKING(null), // + INITIALIZED("unlock.successLabel.vaultCreated"), // + PASSWORD_CHANGED("unlock.successLabel.passwordChanged"), // UPGRADED("unlock.successLabel.upgraded"); private Optional successMessage; diff --git a/main/ui/src/main/resources/fxml/unlock.fxml b/main/ui/src/main/resources/fxml/unlock.fxml index 428a696f6..6439514ad 100644 --- a/main/ui/src/main/resources/fxml/unlock.fxml +++ b/main/ui/src/main/resources/fxml/unlock.fxml @@ -90,10 +90,12 @@ - -