Close popup when deleted an account

This commit is contained in:
huangyuhui
2018-03-05 19:13:58 +08:00
parent db08b61cfa
commit 5eb46395ae
2 changed files with 19 additions and 1 deletions

View File

@@ -18,6 +18,8 @@
package org.jackhuang.hmcl.ui; package org.jackhuang.hmcl.ui;
import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXButton;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty; import javafx.beans.property.StringProperty;
import javafx.fxml.FXML; import javafx.fxml.FXML;
@@ -37,8 +39,11 @@ import org.jackhuang.hmcl.task.Schedulers;
import org.jackhuang.hmcl.ui.construct.ComponentList; import org.jackhuang.hmcl.ui.construct.ComponentList;
import org.jackhuang.hmcl.ui.wizard.DecoratorPage; import org.jackhuang.hmcl.ui.wizard.DecoratorPage;
import java.util.Optional;
public class AccountPage extends StackPane implements DecoratorPage { public class AccountPage extends StackPane implements DecoratorPage {
private final StringProperty title; private final StringProperty title;
private final ObjectProperty<Runnable> onDelete = new SimpleObjectProperty<>(this, "onDelete");
private final Account account; private final Account account;
@@ -95,7 +100,7 @@ public class AccountPage extends StackPane implements DecoratorPage {
@FXML @FXML
private void onDelete() { private void onDelete() {
Settings.INSTANCE.deleteAccount(account); Settings.INSTANCE.deleteAccount(account);
Controllers.navigate(null); Optional.ofNullable(onDelete.get()).ifPresent(Runnable::run);
} }
@FXML @FXML
@@ -116,4 +121,16 @@ public class AccountPage extends StackPane implements DecoratorPage {
public void setTitle(String title) { public void setTitle(String title) {
this.title.set(title); this.title.set(title);
} }
public Runnable getOnDelete() {
return onDelete.get();
}
public ObjectProperty<Runnable> onDeleteProperty() {
return onDelete;
}
public void setOnDelete(Runnable onDelete) {
this.onDelete.set(onDelete);
}
} }

View File

@@ -150,6 +150,7 @@ public final class LeftPaneController {
item.setOnSettingsButtonClicked(e -> { item.setOnSettingsButtonClicked(e -> {
AccountPage accountPage = new AccountPage(account); AccountPage accountPage = new AccountPage(account);
JFXPopup popup = new JFXPopup(accountPage); JFXPopup popup = new JFXPopup(accountPage);
accountPage.setOnDelete(popup::hide);
popup.show((Node) e.getSource(), JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, e.getX(), e.getY()); popup.show((Node) e.getSource(), JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, e.getX(), e.getY());
}); });
ripplerContainer.setOnMouseClicked(e -> { ripplerContainer.setOnMouseClicked(e -> {