diff --git a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java index 9eace8fd6..bc5762848 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java +++ b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java @@ -76,10 +76,17 @@ public abstract class AddVaultModule { @Provides @FxmlScene(FxmlFile.ADDVAULT_NEW_NAME) @AddVaultWizardScoped - static Scene provideCreateNewVaultScene(@AddVaultWizard FXMLLoaderFactory fxmlLoaders) { + static Scene provideCreateNewVaultNameScene(@AddVaultWizard FXMLLoaderFactory fxmlLoaders) { return fxmlLoaders.createScene("/fxml/addvault_new_name.fxml"); - } + + @Provides + @FxmlScene(FxmlFile.ADDVAULT_NEW_LOCATION) + @AddVaultWizardScoped + static Scene provideCreateNewVaultLocationScene(@AddVaultWizard FXMLLoaderFactory fxmlLoaders) { + return fxmlLoaders.createScene("/fxml/addvault_new_location.fxml"); + } + // ------------------ @Binds @@ -97,5 +104,9 @@ public abstract class AddVaultModule { @FxControllerKey(CreateNewVaultNameController.class) abstract FxController bindCreateNewVaultNameController(CreateNewVaultNameController controller); + @Binds + @IntoMap + @FxControllerKey(CreateNewVaultLocationController.class) + abstract FxController bindCreateNewVaultLocationController(CreateNewVaultLocationController controller); } diff --git a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultLocationController.java b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultLocationController.java new file mode 100644 index 000000000..2309706c3 --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultLocationController.java @@ -0,0 +1,122 @@ +package org.cryptomator.ui.addvaultwizard; + +import dagger.Lazy; +import javafx.beans.binding.BooleanBinding; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.StringProperty; +import javafx.fxml.FXML; +import javafx.scene.Scene; +import javafx.stage.DirectoryChooser; +import javafx.stage.Stage; +import org.cryptomator.ui.common.FxController; +import org.cryptomator.ui.common.FxmlFile; +import org.cryptomator.ui.common.FxmlScene; + +import javax.inject.Inject; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ResourceBundle; + +/** + * TODO: Add trim() filter to vaultName + */ +@AddVaultWizardScoped +public class CreateNewVaultLocationController implements FxController { + + private final Stage window; + private final Lazy previousScene; + private final ObjectProperty vaultPath; + private final BooleanBinding vaultPathIsNull; + private final StringProperty vaultName; + private final ResourceBundle resourceBundle; + + //TODO: add parameter for next window + @Inject + CreateNewVaultLocationController(@AddVaultWizard Stage window, @FxmlScene(FxmlFile.ADDVAULT_NEW_NAME) Lazy previousScene, ObjectProperty vaultPath, StringProperty vaultName, ResourceBundle resourceBundle) { + this.window = window; + this.previousScene = previousScene; + this.vaultPath = vaultPath; + this.vaultName = vaultName; + this.resourceBundle = resourceBundle; + this.vaultPathIsNull = vaultPath.isNull(); + } + + @FXML + public void back() { + window.setScene(previousScene.get()); + } + + @FXML + public void next() { + //TODO: what if there exists already a vault? + if (hasFullAccessToLocation()) { + window.close(); + } else { + //TODO error handling + } + } + + private boolean hasFullAccessToLocation() { + try { + Path tmp = Files.createFile(vaultPath.get().resolve("tmp")); + Files.delete(tmp); + return true; + } catch (IOException e) { + return false; + } + } + + @FXML + public void chooseDirectory() { + DirectoryChooser directoryChooser = new DirectoryChooser(); + directoryChooser.setTitle(resourceBundle.getString("addvaultwizard.new.directoryPickerTitle")); + setInitialDirectory(directoryChooser); + final File file = directoryChooser.showDialog(window); + if (file != null) { + vaultPath.setValue(file.toPath().toAbsolutePath()); + } + } + + private void setInitialDirectory(DirectoryChooser chooser) { + File userHome; + try { + userHome = new File(System.getProperty("user.home")); + } catch (Exception e) { + userHome = null; + } + if (userHome != null) { + chooser.setInitialDirectory(userHome); + } + + } + + /* Getter/Setter */ + + public String getVaultName() { + return vaultName.get(); + } + + public StringProperty vaultNameProperty() { + return vaultName; + } + + public Path getVaultPath() { + return vaultPath.get(); + } + + public ObjectProperty vaultPathProperty() { + return vaultPath; + } + + public boolean isVaultPathIsNull() { + return vaultPathIsNull.get(); + } + + public BooleanBinding vaultPathIsNullProperty() { + return vaultPathIsNull; + } + + +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultNameController.java b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultNameController.java index bdc0c4341..97a0846fd 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultNameController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultNameController.java @@ -26,13 +26,15 @@ public class CreateNewVaultNameController implements FxController { public TextField textField; private final Stage window; private final Lazy welcomeScene; + private final Lazy nextScene; private final StringProperty vaultName; private final ResourceBundle resourceBundle; @Inject - CreateNewVaultNameController(@AddVaultWizard Stage window, @FxmlScene(FxmlFile.ADDVAULT_WELCOME) Lazy welcomeScene, StringProperty vaultName, ResourceBundle resourceBundle) { + CreateNewVaultNameController(@AddVaultWizard Stage window, @FxmlScene(FxmlFile.ADDVAULT_WELCOME) Lazy welcomeScene, @FxmlScene(FxmlFile.ADDVAULT_NEW_LOCATION) Lazy nextScene, StringProperty vaultName, ResourceBundle resourceBundle) { this.window = window; this.welcomeScene = welcomeScene; + this.nextScene = nextScene; this.vaultName = vaultName; this.resourceBundle = resourceBundle; } @@ -50,7 +52,7 @@ public class CreateNewVaultNameController implements FxController { @FXML public void next() { if (nameIsValid()) { - window.close(); + window.setScene(nextScene.get()); } else { //TODO } diff --git a/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java b/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java index f0cf3e306..2ad3a1672 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java +++ b/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java @@ -5,10 +5,9 @@ public enum FxmlFile { ADDVAULT_WELCOME("/fxml/addvault_welcome.fxml"), // ADDVAULT_EXISTING("/fxml/addvault_existing.fxml"), // ADDVAULT_NEW_NAME("/fxml/addvault_new_name.fxml"), // - PREFERENCES("/fxml/preferences.fxml"), // + ADDVAULT_NEW_LOCATION("/fxml/addvault_new_location.fxml"), PREFERENCES("/fxml/preferences.fxml"), // UNLOCK("/fxml/unlock2.fxml"), // TODO rename - UNLOCK_SUCCESS("/fxml/unlock_success.fxml"), - ; + UNLOCK_SUCCESS("/fxml/unlock_success.fxml"); private final String filename; diff --git a/main/ui/src/main/resources/fxml/addvault_new_location.fxml b/main/ui/src/main/resources/fxml/addvault_new_location.fxml new file mode 100644 index 000000000..10e91afc7 --- /dev/null +++ b/main/ui/src/main/resources/fxml/addvault_new_location.fxml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + +