From f12882a3894e3d6e08680bdf86852cde7024b418 Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Mon, 23 May 2022 22:27:30 +0800 Subject: [PATCH] fix(download): should update category list after download soruce changed. --- .../hmcl/ui/versions/DownloadListPage.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadListPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadListPage.java index 8c220ae6d..28744272d 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadListPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadListPage.java @@ -191,7 +191,10 @@ public class DownloadListPage extends Control implements DecoratorPage, VersionP } protected String getLocalizedCategoryIndent(ModDownloadListPageSkin.CategoryIndented category) { - return StringUtils.repeats(' ', category.indent * 4) + getLocalizedCategory(category.getCategory() == null ? "0" : category.getCategory().getId()); + return StringUtils.repeats(' ', category.indent * 4) + + (category.getCategory() == null + ? i18n("curse.category.0") + : getLocalizedCategory(category.getCategory().getId())); } protected String getLocalizedOfficialPage() { @@ -309,15 +312,17 @@ public class DownloadListPage extends Control implements DecoratorPage, VersionP categoryComboBox.setPromptText(i18n("mods.category")); categoryComboBox.getSelectionModel().select(0); categoryComboBox.setConverter(stringConverter(getSkinnable()::getLocalizedCategoryIndent)); - Task.supplyAsync(() -> getSkinnable().repository.getCategories()) - .thenAcceptAsync(Schedulers.javafx(), categories -> { - List result = new ArrayList<>(); - result.add(new CategoryIndented(0, null)); - for (RemoteModRepository.Category category : Lang.toIterable(categories)) { - resolveCategory(category, 0, result); - } - categoryComboBox.getItems().setAll(result); - }).start(); + FXUtils.onChangeAndOperate(getSkinnable().downloadSource, downloadSource -> { + Task.supplyAsync(() -> getSkinnable().repository.getCategories()) + .thenAcceptAsync(Schedulers.javafx(), categories -> { + List result = new ArrayList<>(); + result.add(new CategoryIndented(0, null)); + for (RemoteModRepository.Category category : Lang.toIterable(categories)) { + resolveCategory(category, 0, result); + } + categoryComboBox.getItems().setAll(result); + }).start(); + }); StackPane sortStackPane = new StackPane(); JFXComboBox sortComboBox = new JFXComboBox<>();