|
@@ -1,6 +1,8 @@
|
|
|
package org.cryptomator.ui.addvaultwizard;
|
|
|
|
|
|
import dagger.Lazy;
|
|
|
+import org.cryptomator.common.locationpresets.LocationPresetsProvider;
|
|
|
+import org.cryptomator.common.locationpresets.LocationPreset;
|
|
|
import org.cryptomator.ui.common.FxController;
|
|
|
import org.cryptomator.ui.common.FxmlFile;
|
|
|
import org.cryptomator.ui.common.FxmlScene;
|
|
@@ -26,6 +28,7 @@ import javafx.scene.control.Label;
|
|
|
import javafx.scene.control.RadioButton;
|
|
|
import javafx.scene.control.Toggle;
|
|
|
import javafx.scene.control.ToggleGroup;
|
|
|
+import javafx.scene.layout.VBox;
|
|
|
import javafx.stage.DirectoryChooser;
|
|
|
import javafx.stage.Stage;
|
|
|
import java.io.File;
|
|
@@ -34,6 +37,9 @@ import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
import java.nio.file.Paths;
|
|
|
import java.nio.file.StandardOpenOption;
|
|
|
+import java.util.Comparator;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
import java.util.ResourceBundle;
|
|
|
|
|
|
@AddVaultWizardScoped
|
|
@@ -46,7 +52,7 @@ public class CreateNewVaultLocationController implements FxController {
|
|
|
private final Stage window;
|
|
|
private final Lazy<Scene> chooseNameScene;
|
|
|
private final Lazy<Scene> choosePasswordScene;
|
|
|
- private final ObservedLocationPresets locationPresets;
|
|
|
+ private final List<RadioButton> locationPresetBtns;
|
|
|
private final ObjectProperty<Path> vaultPath;
|
|
|
private final StringProperty vaultName;
|
|
|
private final ResourceBundle resourceBundle;
|
|
@@ -58,24 +64,18 @@ public class CreateNewVaultLocationController implements FxController {
|
|
|
private Path customVaultPath = DEFAULT_CUSTOM_VAULT_PATH;
|
|
|
|
|
|
//FXML
|
|
|
- public ToggleGroup predefinedLocationToggler;
|
|
|
- public RadioButton iclouddriveRadioButton;
|
|
|
- public RadioButton dropboxRadioButton;
|
|
|
- public RadioButton gdriveRadioButton;
|
|
|
- public RadioButton onedriveRadioButton;
|
|
|
- public RadioButton megaRadioButton;
|
|
|
- public RadioButton pcloudRadioButton;
|
|
|
+ public ToggleGroup locationPresetsToggler;
|
|
|
+ public VBox radioButtonVBox;
|
|
|
public RadioButton customRadioButton;
|
|
|
public Label vaultPathStatus;
|
|
|
public FontAwesome5IconView goodLocation;
|
|
|
public FontAwesome5IconView badLocation;
|
|
|
|
|
|
@Inject
|
|
|
- CreateNewVaultLocationController(@AddVaultWizardWindow Stage window, @FxmlScene(FxmlFile.ADDVAULT_NEW_NAME) Lazy<Scene> chooseNameScene, @FxmlScene(FxmlFile.ADDVAULT_NEW_PASSWORD) Lazy<Scene> choosePasswordScene, ObservedLocationPresets locationPresets, ObjectProperty<Path> vaultPath, @Named("vaultName") StringProperty vaultName, ResourceBundle resourceBundle) {
|
|
|
+ CreateNewVaultLocationController(@AddVaultWizardWindow Stage window, @FxmlScene(FxmlFile.ADDVAULT_NEW_NAME) Lazy<Scene> chooseNameScene, @FxmlScene(FxmlFile.ADDVAULT_NEW_PASSWORD) Lazy<Scene> choosePasswordScene, ObjectProperty<Path> vaultPath, @Named("vaultName") StringProperty vaultName, ResourceBundle resourceBundle) {
|
|
|
this.window = window;
|
|
|
this.chooseNameScene = chooseNameScene;
|
|
|
this.choosePasswordScene = choosePasswordScene;
|
|
|
- this.locationPresets = locationPresets;
|
|
|
this.vaultPath = vaultPath;
|
|
|
this.vaultName = vaultName;
|
|
|
this.resourceBundle = resourceBundle;
|
|
@@ -83,6 +83,14 @@ public class CreateNewVaultLocationController implements FxController {
|
|
|
this.usePresetPath = new SimpleBooleanProperty();
|
|
|
this.statusText = new SimpleStringProperty();
|
|
|
this.statusGraphic = new SimpleObjectProperty<>();
|
|
|
+ this.locationPresetBtns = LocationPresetsProvider.loadAll(LocationPresetsProvider.class) //
|
|
|
+ .flatMap(LocationPresetsProvider::getLocations) //
|
|
|
+ .sorted(Comparator.comparing(LocationPreset::name)) //
|
|
|
+ .map(preset -> { //
|
|
|
+ var btn = new RadioButton(preset.name());
|
|
|
+ btn.setUserData(preset.path());
|
|
|
+ return btn;
|
|
|
+ }).toList();
|
|
|
}
|
|
|
|
|
|
private boolean validateVaultPathAndSetStatus() {
|
|
@@ -127,26 +135,15 @@ public class CreateNewVaultLocationController implements FxController {
|
|
|
|
|
|
@FXML
|
|
|
public void initialize() {
|
|
|
- predefinedLocationToggler.selectedToggleProperty().addListener(this::togglePredefinedLocation);
|
|
|
- usePresetPath.bind(predefinedLocationToggler.selectedToggleProperty().isNotEqualTo(customRadioButton));
|
|
|
+ radioButtonVBox.getChildren().addAll(1, locationPresetBtns); //first item is the list header
|
|
|
+ locationPresetsToggler.getToggles().addAll(locationPresetBtns);
|
|
|
+ locationPresetsToggler.selectedToggleProperty().addListener(this::togglePredefinedLocation);
|
|
|
+ usePresetPath.bind(locationPresetsToggler.selectedToggleProperty().isNotEqualTo(customRadioButton));
|
|
|
}
|
|
|
|
|
|
private void togglePredefinedLocation(@SuppressWarnings("unused") ObservableValue<? extends Toggle> observable, @SuppressWarnings("unused") Toggle oldValue, Toggle newValue) {
|
|
|
- if (iclouddriveRadioButton.equals(newValue)) {
|
|
|
- vaultPath.set(locationPresets.getIclouddriveLocation().resolve(vaultName.get()));
|
|
|
- } else if (dropboxRadioButton.equals(newValue)) {
|
|
|
- vaultPath.set(locationPresets.getDropboxLocation().resolve(vaultName.get()));
|
|
|
- } else if (gdriveRadioButton.equals(newValue)) {
|
|
|
- vaultPath.set(locationPresets.getGdriveLocation().resolve(vaultName.get()));
|
|
|
- } else if (onedriveRadioButton.equals(newValue)) {
|
|
|
- vaultPath.set(locationPresets.getOnedriveLocation().resolve(vaultName.get()));
|
|
|
- } else if (megaRadioButton.equals(newValue)) {
|
|
|
- vaultPath.set(locationPresets.getMegaLocation().resolve(vaultName.get()));
|
|
|
- } else if (pcloudRadioButton.equals(newValue)) {
|
|
|
- vaultPath.set(locationPresets.getPcloudLocation().resolve(vaultName.get()));
|
|
|
- } else if (customRadioButton.equals(newValue)) {
|
|
|
- vaultPath.set(customVaultPath.resolve(vaultName.get()));
|
|
|
- }
|
|
|
+ var storagePath = Optional.ofNullable((Path) newValue.getUserData()).orElse(customVaultPath);
|
|
|
+ vaultPath.set(storagePath.resolve(vaultName.get()));
|
|
|
}
|
|
|
|
|
|
@FXML
|
|
@@ -197,10 +194,6 @@ public class CreateNewVaultLocationController implements FxController {
|
|
|
return validVaultPath.get();
|
|
|
}
|
|
|
|
|
|
- public ObservedLocationPresets getObservedLocationPresets() {
|
|
|
- return locationPresets;
|
|
|
- }
|
|
|
-
|
|
|
public BooleanProperty usePresetPathProperty() {
|
|
|
return usePresetPath;
|
|
|
}
|
|
@@ -210,7 +203,7 @@ public class CreateNewVaultLocationController implements FxController {
|
|
|
}
|
|
|
|
|
|
public BooleanBinding anyRadioButtonSelectedProperty() {
|
|
|
- return predefinedLocationToggler.selectedToggleProperty().isNotNull();
|
|
|
+ return locationPresetsToggler.selectedToggleProperty().isNotNull();
|
|
|
}
|
|
|
|
|
|
public boolean isAnyRadioButtonSelected() {
|
|
@@ -232,4 +225,5 @@ public class CreateNewVaultLocationController implements FxController {
|
|
|
public Node getStatusGraphic() {
|
|
|
return statusGraphic.get();
|
|
|
}
|
|
|
+
|
|
|
}
|