2727import javafx .scene .layout .BorderPane ;
2828import javafx .scene .layout .FlowPane ;
2929import javafx .scene .layout .HBox ;
30+ import javafx .scene .layout .Priority ;
31+
3032import org .jackhuang .hmcl .download .DownloadProvider ;
3133import org .jackhuang .hmcl .download .LibraryAnalyzer ;
3234import org .jackhuang .hmcl .ui .Controllers ;
3335import org .jackhuang .hmcl .ui .FXUtils ;
3436import org .jackhuang .hmcl .ui .InstallerItem ;
37+ import org .jackhuang .hmcl .ui .SVG ;
3538import org .jackhuang .hmcl .ui .construct .MessageDialogPane ;
3639import org .jackhuang .hmcl .ui .wizard .Navigation ;
3740import org .jackhuang .hmcl .ui .wizard .WizardController ;
@@ -112,6 +115,30 @@ protected Skin<?> createDefaultSkin() {
112115 return new InstallersPageSkin (this );
113116 }
114117
118+ /**
119+ * Determines whether to display the extension pane.
120+ * <p>
121+ * This method controls the visibility of the extension pane in the UI.
122+ * When this method returns {@code true} and the pane is visible, users can
123+ * interact with the features inside it, which includes triggering the
124+ * "Reset to Default Name" button handled by {@link #resetDefaultName()}.
125+ * </p>
126+ *
127+ * @return {@code true} if the extension pane should be displayed; {@code false} otherwise.
128+ */
129+ protected abstract boolean showExtendPane ();
130+
131+ /**
132+ * Resets the name to its default value.
133+ * <p>
134+ * This method contains the business logic for the "Reset to Default Name" button
135+ * located within the extension pane. This logic can only be triggered by the user
136+ * clicking the corresponding button after {@link #showExtendPane()} returns
137+ * {@code true} and the extension pane is successfully displayed.
138+ * </p>
139+ */
140+ protected abstract void resetDefaultName ();
141+
115142 protected static class InstallersPageSkin extends SkinBase <AbstractInstallersPage > {
116143 /**
117144 * Constructor for all SkinBase instances.
@@ -127,11 +154,27 @@ protected InstallersPageSkin(AbstractInstallersPage control) {
127154 {
128155 HBox versionNamePane = new HBox (8 );
129156 versionNamePane .getStyleClass ().add ("card-non-transparent" );
130- versionNamePane .setStyle ("-fx-padding: 20 8 20 16" );
157+ versionNamePane .setStyle ("-fx-padding: 20 16 20 16" );
131158 versionNamePane .setAlignment (Pos .CENTER_LEFT );
132159
133- control .txtName .setMaxWidth (300 );
134- versionNamePane .getChildren ().setAll (new Label (i18n ("version.name" )), control .txtName );
160+ HBox .setHgrow (control .txtName , Priority .ALWAYS );
161+
162+ versionNamePane .getChildren ().addAll (new Label (i18n ("version.name" )), control .txtName );
163+
164+ if (control .showExtendPane ()) {
165+ JFXButton clearButton = FXUtils .newToggleButton4 (SVG .CLOSE );
166+ FXUtils .installFastTooltip (clearButton , i18n ("button.clear" ));
167+ clearButton .disableProperty ().bind (control .txtName .textProperty ().isEmpty ().or (control .txtName .disableProperty ()));
168+ clearButton .setOnAction (e -> control .txtName .clear ());
169+
170+ JFXButton resetButton = FXUtils .newToggleButton4 (SVG .RESTORE );
171+ FXUtils .installFastTooltip (resetButton , i18n ("button.reset" ));
172+ resetButton .disableProperty ().bind (control .txtName .disableProperty ());
173+ resetButton .setOnAction (e -> control .resetDefaultName ());
174+
175+ versionNamePane .getChildren ().addAll (clearButton , resetButton );
176+ }
177+
135178 root .setTop (versionNamePane );
136179 }
137180
0 commit comments