diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/ProfilePage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/ProfilePage.java index fb3caba32..8241fd976 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/ProfilePage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/ProfilePage.java @@ -65,7 +65,7 @@ public final class ProfilePage extends StackPane implements DecoratorPage { FXUtils.onChangeAndOperate(txtProfileName.textProperty(), it -> { btnSave.setDisable(!txtProfileName.validate() || StringUtils.isBlank(getLocation())); }); - gameDir.setProperty(location); + gameDir.pathProperty().bindBidirectional(location); FXUtils.onChangeAndOperate(location, it -> { btnSave.setDisable(!txtProfileName.validate() || StringUtils.isBlank(getLocation())); }); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java index 5be45bbe2..a691adc87 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java @@ -20,6 +20,7 @@ package org.jackhuang.hmcl.ui; import com.jfoenix.controls.*; import com.jfoenix.effects.JFXDepthManager; import javafx.application.Platform; +import javafx.beans.binding.Bindings; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.collections.FXCollections; @@ -178,7 +179,7 @@ public final class SettingsPage extends StackPane implements DecoratorPage { chkProxyAuthentication.selectedProperty().addListener((a, b, newValue) -> Settings.INSTANCE.setHasProxyAuth(newValue)); authPane.disableProperty().bind(chkProxyAuthentication.selectedProperty().not()); - fileCommonLocation.setProperty(Settings.INSTANCE.commonPathProperty()); + fileCommonLocation.pathProperty().bindBidirectional(Settings.INSTANCE.commonPathProperty()); FXUtils.installTooltip(btnUpdate, i18n("update.tooltip")); checkUpdate(); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/FileItem.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/FileItem.java index 987986087..35a341f77 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/FileItem.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/FileItem.java @@ -18,7 +18,6 @@ package org.jackhuang.hmcl.ui.construct; import com.jfoenix.controls.JFXButton; -import javafx.beans.property.Property; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.scene.control.Label; @@ -36,19 +35,20 @@ import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import java.io.File; public class FileItem extends BorderPane { - private Property property; - private final Label x = new Label(); + private final Label lblPath = new Label(); private final SimpleStringProperty name = new SimpleStringProperty(this, "name"); private final SimpleStringProperty title = new SimpleStringProperty(this, "title"); private final SimpleStringProperty tooltip = new SimpleStringProperty(this, "tooltip"); + private final SimpleStringProperty path = new SimpleStringProperty(this, "path"); public FileItem() { VBox left = new VBox(); Label name = new Label(); name.textProperty().bind(nameProperty()); - x.getStyleClass().addAll("subtitle-label"); - left.getChildren().addAll(name, x); + lblPath.getStyleClass().addAll("subtitle-label"); + lblPath.textProperty().bind(path); + left.getChildren().addAll(name, lblPath); setLeft(left); JFXButton right = new JFXButton(); @@ -65,8 +65,8 @@ public class FileItem extends BorderPane { public void onExplore() { DirectoryChooser chooser = new DirectoryChooser(); - if (property.getValue() != null) { - File file = new File(property.getValue()); + if (path.get() != null) { + File file = new File(path.get()); if (file.exists()) { if (file.isFile()) file = file.getAbsoluteFile().getParentFile(); @@ -78,15 +78,10 @@ public class FileItem extends BorderPane { chooser.titleProperty().bind(titleProperty()); File selectedDir = chooser.showDialog(Controllers.getStage()); if (selectedDir != null) - property.setValue(selectedDir.getAbsolutePath()); + path.set(selectedDir.getAbsolutePath()); chooser.titleProperty().unbind(); } - public void setProperty(Property property) { - this.property = property; - x.textProperty().bind(property); - } - public String getName() { return name.get(); } @@ -122,4 +117,16 @@ public class FileItem extends BorderPane { public void setTooltip(String tooltip) { this.tooltip.set(tooltip); } + + public String getPath() { + return path.get(); + } + + public StringProperty pathProperty() { + return path; + } + + public void setPath(String path) { + this.path.set(path); + } }