diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/profile/ProfilePage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/profile/ProfilePage.java index 91ea0b5ef..7b720e4c3 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/profile/ProfilePage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/profile/ProfilePage.java @@ -48,6 +48,7 @@ import java.nio.file.Path; import java.util.Optional; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; +import static org.jackhuang.hmcl.util.logging.Logger.LOG; public final class ProfilePage extends BorderPane implements DecoratorPage { private final ReadOnlyObjectWrapper state = new ReadOnlyObjectWrapper<>(); @@ -114,6 +115,24 @@ public final class ProfilePage extends BorderPane implements DecoratorPage { gameDir.setTitle(i18n("profile.instance_directory.choose")); gameDir.pathProperty().bindBidirectional(location); + locationProperty().addListener((observable, oldValue, newValue) -> { + LOG.debug("OnChange locationProperty"); + + var folder = new File(newValue); + var oldFolder = new File(oldValue); + File parentFolder = folder.getParentFile(); + File parentOldFolder = oldFolder.getParentFile(); + // txtProfileName + if (parentFolder != null) { + if (txtProfileName.getText().isEmpty()) { + txtProfileName.setText(parentFolder.getName()); + } + else if (!parentFolder.getName().equals(parentOldFolder.getName())) { + txtProfileName.setText(parentFolder.getName()); + } + } + }); + toggleUseRelativePath = new OptionToggleButton(); toggleUseRelativePath.setTitle(i18n("profile.use_relative_path"));