mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-17 02:01:27 +00:00
fixes #1249
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package org.cryptomator.ui.common;
|
||||
|
||||
import javafx.beans.binding.StringBinding;
|
||||
import javafx.beans.value.ObservableObjectValue;
|
||||
|
||||
|
||||
/**
|
||||
* Contains a variety of method to create {@link java.util.function.Function#identity() identity}-bindings
|
||||
* to facilitate the Weak References used internally in JavaFX's Bindings.
|
||||
*/
|
||||
public final class WeakBindings {
|
||||
|
||||
/**
|
||||
* Create a new StringBinding that listens to changes from the given observable without being strongly referenced by it.
|
||||
*
|
||||
* @param observable The observable
|
||||
* @return a StringBinding weakly referenced from the given observable
|
||||
*/
|
||||
public static StringBinding bindString(ObservableObjectValue<String> observable) {
|
||||
return new StringBinding() {
|
||||
{
|
||||
bind(observable);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String computeValue() {
|
||||
return observable.get();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import javafx.animation.Timeline;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.binding.BooleanBinding;
|
||||
import javafx.beans.binding.ObjectBinding;
|
||||
import javafx.beans.binding.StringBinding;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.ReadOnlyBooleanProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
@@ -23,6 +24,7 @@ import org.cryptomator.common.vaults.Vault;
|
||||
import org.cryptomator.keychain.KeychainManager;
|
||||
import org.cryptomator.ui.common.FxController;
|
||||
import org.cryptomator.ui.common.UserInteractionLock;
|
||||
import org.cryptomator.ui.common.WeakBindings;
|
||||
import org.cryptomator.ui.controls.NiceSecurePasswordField;
|
||||
import org.cryptomator.ui.forgetPassword.ForgetPasswordComponent;
|
||||
import org.slf4j.Logger;
|
||||
@@ -51,7 +53,8 @@ public class UnlockController implements FxController {
|
||||
private final ObjectBinding<ContentDisplay> unlockButtonContentDisplay;
|
||||
private final BooleanBinding userInteractionDisabled;
|
||||
private final BooleanProperty unlockButtonDisabled;
|
||||
|
||||
private final StringBinding vaultName;
|
||||
|
||||
public NiceSecurePasswordField passwordField;
|
||||
public CheckBox savePasswordCheckbox;
|
||||
public ImageView face;
|
||||
@@ -74,6 +77,7 @@ public class UnlockController implements FxController {
|
||||
this.unlockButtonContentDisplay = Bindings.createObjectBinding(this::getUnlockButtonContentDisplay, passwordEntryLock.awaitingInteraction());
|
||||
this.userInteractionDisabled = passwordEntryLock.awaitingInteraction().not();
|
||||
this.unlockButtonDisabled = new SimpleBooleanProperty();
|
||||
this.vaultName = WeakBindings.bindString(vault.displayableNameProperty());
|
||||
this.window.setOnCloseRequest(windowEvent -> cancel());
|
||||
}
|
||||
|
||||
@@ -177,8 +181,12 @@ public class UnlockController implements FxController {
|
||||
|
||||
/* Getter/Setter */
|
||||
|
||||
public Vault getVault() {
|
||||
return vault;
|
||||
public String getVaultName() {
|
||||
return vaultName.get();
|
||||
}
|
||||
|
||||
public StringBinding vaultNameProperty() {
|
||||
return vaultName;
|
||||
}
|
||||
|
||||
public ObjectBinding<ContentDisplay> unlockButtonContentDisplayProperty() {
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
</ImageView>
|
||||
</StackPane>
|
||||
<VBox spacing="6" HBox.hgrow="ALWAYS">
|
||||
<FormattedLabel format="%unlock.passwordPrompt" arg1="${controller.vault.displayableName}" wrapText="true"/>
|
||||
<FormattedLabel format="%unlock.passwordPrompt" arg1="${controller.vaultName}" wrapText="true"/>
|
||||
<NiceSecurePasswordField fx:id="passwordField" disable="${controller.userInteractionDisabled}"/>
|
||||
<CheckBox fx:id="savePasswordCheckbox" text="%unlock.savePassword" onAction="#didClickSavePasswordCheckbox" disable="${controller.userInteractionDisabled}" visible="${controller.keychainAccessAvailable}"/>
|
||||
</VBox>
|
||||
|
||||
Reference in New Issue
Block a user