mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-17 02:01:27 +00:00
disable "remove" button when the selected vault is unlocked [ci skip]
This commit is contained in:
@@ -90,7 +90,7 @@ final class MacOsXWebDavMounter implements WebDavMounterStrategy {
|
||||
public void reveal() throws CommandFailedException {
|
||||
try {
|
||||
Process proc = revealCommand.start();
|
||||
waitForProcessAndCheckSuccess(proc, 1, TimeUnit.SECONDS);
|
||||
waitForProcessAndCheckSuccess(proc, 2, TimeUnit.SECONDS);
|
||||
} catch (IOException e) {
|
||||
throw new CommandFailedException(e);
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ import org.cryptomator.ui.controls.DirectoryListCell;
|
||||
import org.cryptomator.ui.model.Vault;
|
||||
import org.cryptomator.ui.model.VaultFactory;
|
||||
import org.cryptomator.ui.settings.Settings;
|
||||
import org.cryptomator.ui.util.Listeners;
|
||||
import org.fxmisc.easybind.EasyBind;
|
||||
import org.fxmisc.easybind.monadic.MonadicBinding;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -37,7 +37,6 @@ import javafx.beans.binding.Binding;
|
||||
import javafx.beans.binding.BooleanBinding;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
@@ -69,7 +68,8 @@ public class MainController extends AbstractFXMLViewController {
|
||||
private final ObjectProperty<AbstractFXMLViewController> activeController = new SimpleObjectProperty<>();
|
||||
private final ObservableList<Vault> vaults;
|
||||
private final ObjectProperty<Vault> selectedVault = new SimpleObjectProperty<>();
|
||||
private final Binding<Boolean> isSelectedVaultUnlocked = EasyBind.select(selectedVault).selectObject(Vault::unlockedProperty);
|
||||
private final MonadicBinding<Boolean> isSelectedVaultUnlocked = EasyBind.select(selectedVault).selectObject(Vault::unlockedProperty);
|
||||
private final Binding<Boolean> canEditSelectedVault = EasyBind.combine(selectedVault.isNull(), isSelectedVaultUnlocked.orElse(false), Boolean::logicalOr);
|
||||
private final BooleanBinding isShowingSettings;
|
||||
private final Map<Vault, UnlockedController> unlockedVaults = new HashMap<>();
|
||||
|
||||
@@ -117,16 +117,17 @@ public class MainController extends AbstractFXMLViewController {
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
activeController.addListener(this::activeControllerDidChange);
|
||||
activeController.set(welcomeController.get());
|
||||
vaultList.setItems(vaults);
|
||||
vaultList.setCellFactory(this::createDirecoryListCell);
|
||||
selectedVault.addListener(this::selectedVaultDidChange);
|
||||
activeController.set(welcomeController.get());
|
||||
selectedVault.bind(vaultList.getSelectionModel().selectedItemProperty());
|
||||
addVaultContextMenu.showingProperty().addListener(Listeners.withNewValue(addVaultButton::setSelected));
|
||||
removeVaultButton.disableProperty().bind(selectedVault.isNull());
|
||||
isShowingSettings.addListener(Listeners.withNewValue(settingsButton::setSelected));
|
||||
isSelectedVaultUnlocked.addListener(Listeners.withNewValue(this::selectedVaultUnlockedDidChange));
|
||||
removeVaultButton.disableProperty().bind(canEditSelectedVault);
|
||||
|
||||
EasyBind.subscribe(activeController, this::activeControllerDidChange);
|
||||
EasyBind.subscribe(selectedVault, this::selectedVaultDidChange);
|
||||
EasyBind.subscribe(isSelectedVaultUnlocked, this::selectedVaultUnlockedDidChange);
|
||||
EasyBind.subscribe(isShowingSettings, settingsButton::setSelected);
|
||||
EasyBind.subscribe(addVaultContextMenu.showingProperty(), addVaultButton::setSelected);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -151,6 +152,10 @@ public class MainController extends AbstractFXMLViewController {
|
||||
this.stage = stage;
|
||||
}
|
||||
|
||||
// ****************************************
|
||||
// UI Events
|
||||
// ****************************************
|
||||
|
||||
@FXML
|
||||
private void didClickAddVault(ActionEvent event) {
|
||||
if (addVaultContextMenu.isShowing()) {
|
||||
@@ -245,16 +250,16 @@ public class MainController extends AbstractFXMLViewController {
|
||||
}
|
||||
|
||||
// ****************************************
|
||||
// Bindings and Property Listeners
|
||||
// Binding Listeners
|
||||
// ****************************************
|
||||
|
||||
private void activeControllerDidChange(ObservableValue<? extends AbstractFXMLViewController> property, AbstractFXMLViewController oldValue, AbstractFXMLViewController newValue) {
|
||||
private void activeControllerDidChange(AbstractFXMLViewController newValue) {
|
||||
final Parent root = newValue.loadFxml();
|
||||
contentPane.getChildren().clear();
|
||||
contentPane.getChildren().add(root);
|
||||
}
|
||||
|
||||
private void selectedVaultDidChange(ObservableValue<? extends Vault> property, Vault oldValue, Vault newValue) {
|
||||
private void selectedVaultDidChange(Vault newValue) {
|
||||
if (newValue == null) {
|
||||
return;
|
||||
}
|
||||
@@ -278,6 +283,10 @@ public class MainController extends AbstractFXMLViewController {
|
||||
}
|
||||
}
|
||||
|
||||
// ****************************************
|
||||
// Public Bindings
|
||||
// ****************************************
|
||||
|
||||
public Binding<String> windowTitle() {
|
||||
return EasyBind.monadic(selectedVault).map(Vault::getName).orElse(resourceBundle.getString("app.name"));
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
package org.cryptomator.ui.util;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
|
||||
public final class Listeners {
|
||||
|
||||
private Listeners() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes the given consumer with the new value as soon as a change is reported by an {@link ObservableValue}.
|
||||
*
|
||||
* @param consumer The function to call with the changed value.
|
||||
* @return A listener that can i.e. be used in {@link ObservableValue#addListener(ChangeListener)}.
|
||||
*/
|
||||
public static <T> ChangeListener<T> withNewValue(Consumer<T> consumer) {
|
||||
return (ObservableValue<? extends T> observable, T oldValue, T newValue) -> {
|
||||
consumer.accept(newValue);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user