fix: should not navigate to DownloadPage when clicking GameListItem

This commit is contained in:
huanghongxun
2021-09-20 13:31:35 +08:00
parent cfe801f280
commit 90976cc7e0
4 changed files with 31 additions and 24 deletions

View File

@@ -20,10 +20,12 @@ package org.jackhuang.hmcl.ui;
import javafx.beans.property.*;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.control.Control;
import static org.jackhuang.hmcl.ui.construct.SpinnerPane.FAILED_ACTION;
public class ListPageBase<T> extends Control {
private final ListProperty<T> items = new SimpleListProperty<>(this, "items", FXCollections.observableArrayList());
private final BooleanProperty loading = new SimpleBooleanProperty(this, "loading", false);
@@ -65,23 +67,22 @@ public class ListPageBase<T> extends Control {
this.failedReason.set(failedReason);
}
public final ObjectProperty<EventHandler<ActionEvent>> onActionProperty() {
return onAction;
public final ObjectProperty<EventHandler<Event>> onFailedActionProperty() {
return onFailedAction;
}
public final void setOnAction(EventHandler<ActionEvent> value) {
onActionProperty().set(value);
public final void setOnFailedAction(EventHandler<Event> value) {
onFailedActionProperty().set(value);
}
public final EventHandler<ActionEvent> getOnAction() {
return onActionProperty().get();
public final EventHandler<Event> getOnFailedAction() {
return onFailedActionProperty().get();
}
private ObjectProperty<EventHandler<ActionEvent>> onAction = new SimpleObjectProperty<EventHandler<ActionEvent>>(this, "onAction") {
private ObjectProperty<EventHandler<Event>> onFailedAction = new SimpleObjectProperty<EventHandler<Event>>(this, "onFailedAction") {
@Override
protected void invalidated() {
setEventHandler(ActionEvent.ACTION, get());
setEventHandler(FAILED_ACTION, get());
}
};
}

View File

@@ -43,7 +43,7 @@ public abstract class ToolbarListPageSkin<T extends ListPageBase<? extends Node>
SpinnerPane spinnerPane = new SpinnerPane();
spinnerPane.loadingProperty().bind(skinnable.loadingProperty());
spinnerPane.failedReasonProperty().bind(skinnable.failedReasonProperty());
spinnerPane.onActionProperty().bind(skinnable.onActionProperty());
spinnerPane.onFailedActionProperty().bind(skinnable.onFailedActionProperty());
spinnerPane.getStyleClass().add("large-spinner-pane");
ComponentList root = new ComponentList();

View File

@@ -21,8 +21,9 @@ import com.jfoenix.controls.JFXSpinner;
import javafx.beans.DefaultProperty;
import javafx.beans.InvalidationListener;
import javafx.beans.property.*;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.event.EventType;
import javafx.scene.Node;
import javafx.scene.control.Control;
import javafx.scene.control.Label;
@@ -88,25 +89,24 @@ public class SpinnerPane extends Control {
this.failedReason.set(failedReason);
}
public final ObjectProperty<EventHandler<ActionEvent>> onActionProperty() {
return onAction;
public final ObjectProperty<EventHandler<Event>> onFailedActionProperty() {
return onFailedAction;
}
public final void setOnAction(EventHandler<ActionEvent> value) {
onActionProperty().set(value);
public final void setOnFailedAction(EventHandler<Event> value) {
onFailedActionProperty().set(value);
}
public final EventHandler<ActionEvent> getOnAction() {
return onActionProperty().get();
public final EventHandler<Event> getOnFailedAction() {
return onFailedActionProperty().get();
}
private ObjectProperty<EventHandler<ActionEvent>> onAction = new SimpleObjectProperty<EventHandler<ActionEvent>>(this, "onAction") {
private ObjectProperty<EventHandler<Event>> onFailedAction = new SimpleObjectProperty<EventHandler<Event>>(this, "onFailedAction") {
@Override
protected void invalidated() {
setEventHandler(ActionEvent.ACTION, get());
setEventHandler(FAILED_ACTION, get());
}
};
@Override
protected Skin createDefaultSkin() {
return new Skin(this);
@@ -130,8 +130,12 @@ public class SpinnerPane extends Control {
failedPane.getStyleClass().add("notice-pane");
failedPane.getChildren().setAll(failedReasonLabel);
failedPane.onMouseClickedProperty().bind(
BindingMapping.of(control.onAction)
.map(actionHandler -> (e -> actionHandler.handle(new ActionEvent()))));
BindingMapping.of(control.onFailedAction)
.map(actionHandler -> (e -> {
if (actionHandler != null) {
actionHandler.handle(new Event(FAILED_ACTION));
}
})));
FXUtils.onChangeAndOperate(getSkinnable().content, newValue -> {
if (newValue == null) {
@@ -172,4 +176,6 @@ public class SpinnerPane extends Control {
return reason;
}
}
public static final EventType<Event> FAILED_ACTION = new EventType<>(Event.ANY, "FAILED_ACTION");
}

View File

@@ -180,7 +180,7 @@ public class GameListPage extends ListPageBase<GameListItem> implements Decorato
Profiles.registerVersionsListener(this::loadVersions);
setOnAction(e -> Controllers.navigate(Controllers.getDownloadPage()));
setOnFailedAction(e -> Controllers.navigate(Controllers.getDownloadPage()));
}
private void loadVersions(Profile profile) {