mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-17 10:11:27 +00:00
adding first createNewVault dialogue
This commit is contained in:
@@ -6,6 +6,8 @@ import dagger.Provides;
|
||||
import dagger.multibindings.IntoMap;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
@@ -51,6 +53,12 @@ public abstract class AddVaultModule {
|
||||
return new SimpleObjectProperty<>();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@AddVaultWizardScoped
|
||||
static StringProperty provideVaultName() {
|
||||
return new SimpleStringProperty("");
|
||||
}
|
||||
|
||||
@Provides
|
||||
@FxmlScene(FxmlFile.ADDVAULT_WELCOME)
|
||||
@AddVaultWizardScoped
|
||||
@@ -65,6 +73,13 @@ public abstract class AddVaultModule {
|
||||
return fxmlLoaders.createScene("/fxml/addvault_existing.fxml");
|
||||
}
|
||||
|
||||
@Provides
|
||||
@FxmlScene(FxmlFile.ADDVAULT_NEW)
|
||||
@AddVaultWizardScoped
|
||||
static Scene provideCreateNewVaultScene(@AddVaultWizard FXMLLoaderFactory fxmlLoaders) {
|
||||
return fxmlLoaders.createScene("/fxml/addvault_new.fxml");
|
||||
|
||||
}
|
||||
// ------------------
|
||||
|
||||
@Binds
|
||||
@@ -77,5 +92,10 @@ public abstract class AddVaultModule {
|
||||
@FxControllerKey(ChooseExistingVaultController.class)
|
||||
abstract FxController bindChooseExistingVaultController(ChooseExistingVaultController controller);
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@FxControllerKey(CreateNewVaultController.class)
|
||||
abstract FxController bindCreateNewVaultController(CreateNewVaultController controller);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
@AddVaultWizardScoped
|
||||
public class AddVaultWelcomeController implements FxController {
|
||||
@@ -18,16 +17,18 @@ public class AddVaultWelcomeController implements FxController {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AddVaultWelcomeController.class);
|
||||
private final Stage window;
|
||||
private final Lazy<Scene> chooseExistingVaultScene;
|
||||
private final Lazy<Scene> createNewVaultScene;
|
||||
|
||||
@Inject
|
||||
AddVaultWelcomeController(@AddVaultWizard Stage window, @FxmlScene(FxmlFile.ADDVAULT_EXISTING) Lazy<Scene> chooseExistingVaultScene) {
|
||||
AddVaultWelcomeController(@AddVaultWizard Stage window, @FxmlScene(FxmlFile.ADDVAULT_EXISTING) Lazy<Scene> chooseExistingVaultScene, @FxmlScene(FxmlFile.ADDVAULT_NEW) Lazy<Scene> createNewVaultScene) {
|
||||
this.window = window;
|
||||
this.chooseExistingVaultScene = chooseExistingVaultScene;
|
||||
this.createNewVaultScene = createNewVaultScene;
|
||||
}
|
||||
|
||||
public void createNewVault() {
|
||||
LOG.debug("AddVaultWelcomeController.createNewVault()");
|
||||
// fxmlLoaders.setScene("/fxml/addvault_new.fxml", window);
|
||||
window.setScene(createNewVaultScene.get());
|
||||
}
|
||||
|
||||
public void chooseExistingVault() {
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package org.cryptomator.ui.addvaultwizard;
|
||||
|
||||
import dagger.Lazy;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.TextField;
|
||||
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.IOException;
|
||||
import java.nio.file.FileAlreadyExistsException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* TODO: Add trim() filter to vaultName
|
||||
*/
|
||||
@AddVaultWizardScoped
|
||||
public class CreateNewVaultController implements FxController {
|
||||
|
||||
public TextField textField;
|
||||
private final Stage window;
|
||||
private final Lazy<Scene> welcomeScene;
|
||||
private final StringProperty vaultName;
|
||||
private final ResourceBundle resourceBundle;
|
||||
|
||||
@Inject
|
||||
CreateNewVaultController(@AddVaultWizard Stage window, @FxmlScene(FxmlFile.ADDVAULT_WELCOME) Lazy<Scene> welcomeScene, StringProperty vaultName, ResourceBundle resourceBundle) {
|
||||
this.window = window;
|
||||
this.welcomeScene = welcomeScene;
|
||||
this.vaultName = vaultName;
|
||||
this.resourceBundle = resourceBundle;
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
vaultName.bind(textField.textProperty());
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void back() {
|
||||
window.setScene(welcomeScene.get());
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void next() {
|
||||
if (nameIsValid()) {
|
||||
window.close();
|
||||
} else {
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if {@link CreateNewVaultController#vaultName}is a valid directory name in the OS by creating and deleting a directory with the giving name in the temporary section of the OS
|
||||
* TODO: Logging
|
||||
*
|
||||
* @return true, if a directory with the name already exists or can be created
|
||||
*/
|
||||
private boolean nameIsValid() {
|
||||
try {
|
||||
Path tmp = Files.createTempDirectory(vaultName.get());
|
||||
Files.deleteIfExists(tmp.toAbsolutePath());
|
||||
return true;
|
||||
} catch (FileAlreadyExistsException e) {
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* Getter/Setter */
|
||||
|
||||
public String getVaultName() {
|
||||
return vaultName.get();
|
||||
}
|
||||
|
||||
public StringProperty vaultNameProperty() {
|
||||
return vaultName;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ public enum FxmlFile {
|
||||
MAIN_WINDOW("/fxml/main_window.fxml"), //
|
||||
ADDVAULT_WELCOME("/fxml/addvault_welcome.fxml"), //
|
||||
ADDVAULT_EXISTING("/fxml/addvault_existing.fxml"), //
|
||||
ADDVAULT_NEW("/fxml/addvault_new.fxml"), //
|
||||
PREFERENCES("/fxml/preferences.fxml"), //
|
||||
UNLOCK("/fxml/unlock2.fxml"), // TODO rename
|
||||
UNLOCK_SUCCESS("/fxml/unlock_success.fxml"),
|
||||
|
||||
31
main/ui/src/main/resources/fxml/addvault_new.fxml
Normal file
31
main/ui/src/main/resources/fxml/addvault_new.fxml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.ButtonBar?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.layout.Region?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<VBox xmlns="http://javafx.com/javafx"
|
||||
xmlns:fx="http://javafx.com/fxml"
|
||||
fx:controller="org.cryptomator.ui.addvaultwizard.CreateNewVaultController"
|
||||
prefHeight="400.0" prefWidth="600.0"
|
||||
alignment="CENTER">
|
||||
<padding>
|
||||
<Insets top="12" right="12" bottom="12" left="12"/>
|
||||
</padding>
|
||||
<children>
|
||||
<Region VBox.vgrow="ALWAYS"/>
|
||||
<Label text="%addvaultwizard.new.insertName"/>
|
||||
<TextField fx:id="textField" promptText="TODO vaultname to be" HBox.hgrow="ALWAYS"/>
|
||||
<Region VBox.vgrow="ALWAYS"/>
|
||||
<ButtonBar buttonMinWidth="120" buttonOrder="B+X">
|
||||
<buttons>
|
||||
<Button text="TODO Back" ButtonBar.buttonData="BACK_PREVIOUS" onAction="#back"/>
|
||||
<Button text="TODO Next" ButtonBar.buttonData="NEXT_FORWARD" onAction="#next" defaultButton="true" disable="${controller.vaultName.empty}"/>
|
||||
</buttons>
|
||||
</ButtonBar>
|
||||
</children>
|
||||
</VBox>
|
||||
@@ -1,5 +1,6 @@
|
||||
addvaultwizard.existing.instruction=Please choose the masterkey.cryptomator file of your existing vault. The directory contain it will be displayed.
|
||||
addvaultwizard.existing.filePickerTitle=Open Masterkey File
|
||||
addvaultwizard.new.insertName=Please enter a name for the vault.
|
||||
main.closeBtn.tooltip=Close
|
||||
main.settingsBtn.tooltip=Settings
|
||||
preferences.title=Preferences
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
addvaultwizard.existing.instruction=Please choose the masterkey.cryptomator file of your existing vault. The directory contain it will be displayed.
|
||||
addvaultwizard.existing.filePickerTitle=Open Masterkey File
|
||||
addvaultwizard.new.insertName=Please enter a name for the vault.
|
||||
main.closeBtn.tooltip=Close
|
||||
main.settingsBtn.tooltip=Settings
|
||||
preferences.autoUpdateCheck=Check for updates automatically
|
||||
|
||||
Reference in New Issue
Block a user