mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-21 04:01:27 +00:00
refactoring ChooseExistingVaultControllor to use a scoped ObjectProperty for the vault path
This commit is contained in:
@@ -4,6 +4,8 @@ import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import dagger.multibindings.IntoMap;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.StageStyle;
|
||||
@@ -18,6 +20,7 @@ import org.cryptomator.ui.mainwindow.VaultListController;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Provider;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
|
||||
@Module
|
||||
@@ -43,6 +46,12 @@ public abstract class AddVaultModule {
|
||||
return stage;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@AddVaultWizardScoped
|
||||
static ObjectProperty<Path> provideVaultPath(){
|
||||
return new SimpleObjectProperty<>();
|
||||
}
|
||||
|
||||
// ------------------
|
||||
|
||||
@Binds
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.cryptomator.ui.addvaultwizard;
|
||||
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.stage.FileChooser;
|
||||
import javafx.stage.Stage;
|
||||
import org.cryptomator.ui.common.FXMLLoaderFactory;
|
||||
@@ -9,19 +9,20 @@ import org.cryptomator.ui.common.FxController;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
|
||||
@AddVaultWizardScoped
|
||||
public class ChooseExistingVaultController implements FxController {
|
||||
|
||||
private final FXMLLoaderFactory fxmlLoaders;
|
||||
private final Stage window;
|
||||
|
||||
public TextField textField;
|
||||
private final FXMLLoaderFactory fxmlLoaders;
|
||||
private final ObjectProperty<Path> vaultPath;
|
||||
|
||||
@Inject
|
||||
ChooseExistingVaultController(@AddVaultWizard Stage window, @AddVaultWizard FXMLLoaderFactory fxmlLoaders) {
|
||||
ChooseExistingVaultController(@AddVaultWizard Stage window, @AddVaultWizard FXMLLoaderFactory fxmlLoaders, ObjectProperty<Path> vaultPath) {
|
||||
this.window = window;
|
||||
this.fxmlLoaders = fxmlLoaders;
|
||||
this.vaultPath = vaultPath;
|
||||
}
|
||||
|
||||
@FXML
|
||||
@@ -32,18 +33,28 @@ public class ChooseExistingVaultController implements FxController {
|
||||
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Cryptomator Masterkey", "*.cryptomator"));
|
||||
final File file = fileChooser.showOpenDialog(window);
|
||||
if (file != null) {
|
||||
textField.setText(file.getAbsolutePath());
|
||||
vaultPath.setValue(file.toPath().toAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void goBack() {
|
||||
fxmlLoaders.setScene("/fxml/addvault_welcome.fxml", window);
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void confirm() {
|
||||
//TODO
|
||||
window.close();
|
||||
}
|
||||
|
||||
/* Getter/Setter */
|
||||
|
||||
public Path getVaultPath() {
|
||||
return vaultPath.get();
|
||||
}
|
||||
|
||||
public ObjectProperty<Path> vaultPathProperty() {
|
||||
return vaultPath;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
</padding>
|
||||
<children>
|
||||
<Label text="%addvaultwizard.existing.instruction"/>
|
||||
<TextField fx:id="textField" text="path/to/masterkey.cryptomator" disable="true"/>
|
||||
<TextField promptText="TODO" text="${controller.vaultPath}" disable="true"/>
|
||||
<Button text="file picker" onAction="#chooseFile"/>
|
||||
<Button text="Back" onAction="#goBack"/>
|
||||
<Button text="Open" onAction="#confirm"/>
|
||||
|
||||
Reference in New Issue
Block a user