From 49c408cb23e8ecf68b357462f66448261b7e202c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BF=AB=E4=B9=90=E5=87=A4=E7=88=AA=E7=8E=8B?=
<165921128+KSSJW@users.noreply.github.com>
Date: Wed, 22 Jul 2026 21:45:49 +0800
Subject: [PATCH] Refactor: InstallersPageSkin versionNamePane (#6349)
---
.../ui/download/AbstractInstallersPage.java | 49 +++++++++++++++++--
.../ui/download/AdditionalInstallersPage.java | 9 ++++
.../hmcl/ui/download/InstallersPage.java | 11 +++++
3 files changed, 66 insertions(+), 3 deletions(-)
diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/AbstractInstallersPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/AbstractInstallersPage.java
index b1c2a97d59..96fec6ccfc 100644
--- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/AbstractInstallersPage.java
+++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/AbstractInstallersPage.java
@@ -27,11 +27,14 @@ import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.HBox;
+import javafx.scene.layout.Priority;
+
import org.jackhuang.hmcl.download.DownloadProvider;
import org.jackhuang.hmcl.download.LibraryAnalyzer;
import org.jackhuang.hmcl.ui.Controllers;
import org.jackhuang.hmcl.ui.FXUtils;
import org.jackhuang.hmcl.ui.InstallerItem;
+import org.jackhuang.hmcl.ui.SVG;
import org.jackhuang.hmcl.ui.construct.MessageDialogPane;
import org.jackhuang.hmcl.ui.wizard.Navigation;
import org.jackhuang.hmcl.ui.wizard.WizardController;
@@ -112,6 +115,30 @@ public abstract class AbstractInstallersPage extends Control implements WizardPa
return new InstallersPageSkin(this);
}
+ /**
+ * Determines whether to display the extension pane.
+ *
+ * This method controls the visibility of the extension pane in the UI.
+ * When this method returns {@code true} and the pane is visible, users can
+ * interact with the features inside it, which includes triggering the
+ * "Reset to Default Name" button handled by {@link #resetDefaultName()}.
+ *
+ *
+ * @return {@code true} if the extension pane should be displayed; {@code false} otherwise.
+ */
+ protected abstract boolean showExtendPane();
+
+ /**
+ * Resets the name to its default value.
+ *
+ * This method contains the business logic for the "Reset to Default Name" button
+ * located within the extension pane. This logic can only be triggered by the user
+ * clicking the corresponding button after {@link #showExtendPane()} returns
+ * {@code true} and the extension pane is successfully displayed.
+ *
+ */
+ protected abstract void resetDefaultName();
+
protected static class InstallersPageSkin extends SkinBase {
/**
* Constructor for all SkinBase instances.
@@ -127,11 +154,27 @@ public abstract class AbstractInstallersPage extends Control implements WizardPa
{
HBox versionNamePane = new HBox(8);
versionNamePane.getStyleClass().add("card-non-transparent");
- versionNamePane.setStyle("-fx-padding: 20 8 20 16");
+ versionNamePane.setStyle("-fx-padding: 20 16 20 16");
versionNamePane.setAlignment(Pos.CENTER_LEFT);
- control.txtName.setMaxWidth(300);
- versionNamePane.getChildren().setAll(new Label(i18n("version.name")), control.txtName);
+ HBox.setHgrow(control.txtName, Priority.ALWAYS);
+
+ versionNamePane.getChildren().addAll(new Label(i18n("version.name")), control.txtName);
+
+ if (control.showExtendPane()) {
+ JFXButton clearButton = FXUtils.newToggleButton4(SVG.CLOSE);
+ FXUtils.installFastTooltip(clearButton, i18n("button.clear"));
+ clearButton.disableProperty().bind(control.txtName.textProperty().isEmpty().or(control.txtName.disableProperty()));
+ clearButton.setOnAction(e -> control.txtName.clear());
+
+ JFXButton resetButton = FXUtils.newToggleButton4(SVG.RESTORE);
+ FXUtils.installFastTooltip(resetButton, i18n("button.reset"));
+ resetButton.disableProperty().bind(control.txtName.disableProperty());
+ resetButton.setOnAction(e -> control.resetDefaultName());
+
+ versionNamePane.getChildren().addAll(clearButton, resetButton);
+ }
+
root.setTop(versionNamePane);
}
diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/AdditionalInstallersPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/AdditionalInstallersPage.java
index 7464556d7d..49701af04e 100644
--- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/AdditionalInstallersPage.java
+++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/AdditionalInstallersPage.java
@@ -111,4 +111,13 @@ class AdditionalInstallersPage extends AbstractInstallersPage {
@Override
public void cleanup(SettingsMap settings) {
}
+
+ @Override
+ protected boolean showExtendPane() {
+ return false;
+ }
+
+ @Override
+ protected void resetDefaultName() {
+ }
}
diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallersPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallersPage.java
index 3d07ed74b6..ff8beb5b95 100644
--- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallersPage.java
+++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallersPage.java
@@ -143,4 +143,15 @@ public class InstallersPage extends AbstractInstallersPage {
txtName.setText(nameBuilder.toString());
isNameModifiedByUser = false;
}
+
+ @Override
+ protected boolean showExtendPane() {
+ return true;
+ }
+
+ @Override
+ protected void resetDefaultName() {
+ isNameModifiedByUser = false;
+ setTxtNameWithLoaders();
+ }
}