Skip to content

Commit 49c408c

Browse files
authored
Refactor: InstallersPageSkin versionNamePane (HMCL-dev#6349)
1 parent b81c339 commit 49c408c

3 files changed

Lines changed: 66 additions & 3 deletions

File tree

HMCL/src/main/java/org/jackhuang/hmcl/ui/download/AbstractInstallersPage.java

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@
2727
import javafx.scene.layout.BorderPane;
2828
import javafx.scene.layout.FlowPane;
2929
import javafx.scene.layout.HBox;
30+
import javafx.scene.layout.Priority;
31+
3032
import org.jackhuang.hmcl.download.DownloadProvider;
3133
import org.jackhuang.hmcl.download.LibraryAnalyzer;
3234
import org.jackhuang.hmcl.ui.Controllers;
3335
import org.jackhuang.hmcl.ui.FXUtils;
3436
import org.jackhuang.hmcl.ui.InstallerItem;
37+
import org.jackhuang.hmcl.ui.SVG;
3538
import org.jackhuang.hmcl.ui.construct.MessageDialogPane;
3639
import org.jackhuang.hmcl.ui.wizard.Navigation;
3740
import 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

HMCL/src/main/java/org/jackhuang/hmcl/ui/download/AdditionalInstallersPage.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,13 @@ protected void reload() {
111111
@Override
112112
public void cleanup(SettingsMap settings) {
113113
}
114+
115+
@Override
116+
protected boolean showExtendPane() {
117+
return false;
118+
}
119+
120+
@Override
121+
protected void resetDefaultName() {
122+
}
114123
}

HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallersPage.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,15 @@ private void setTxtNameWithLoaders() {
143143
txtName.setText(nameBuilder.toString());
144144
isNameModifiedByUser = false;
145145
}
146+
147+
@Override
148+
protected boolean showExtendPane() {
149+
return true;
150+
}
151+
152+
@Override
153+
protected void resetDefaultName() {
154+
isNameModifiedByUser = false;
155+
setTxtNameWithLoaders();
156+
}
146157
}

0 commit comments

Comments
 (0)