diff --git a/src/main/java/cn/octopusyan/alistgui/controller/SetupController.java b/src/main/java/cn/octopusyan/alistgui/controller/SetupController.java index b2b58bc..5e2f529 100644 --- a/src/main/java/cn/octopusyan/alistgui/controller/SetupController.java +++ b/src/main/java/cn/octopusyan/alistgui/controller/SetupController.java @@ -6,6 +6,7 @@ import cn.octopusyan.alistgui.config.Context; import cn.octopusyan.alistgui.config.I18n; import cn.octopusyan.alistgui.enums.ProxySetup; import cn.octopusyan.alistgui.manager.ConfigManager; +import cn.octopusyan.alistgui.view.ProxySetupCell; import cn.octopusyan.alistgui.viewModel.SetupViewModel; import javafx.collections.FXCollections; import javafx.fxml.FXML; @@ -60,6 +61,9 @@ public class SetupController extends BaseController implements I themeComboBox.setItems(FXCollections.observableList(ConfigManager.THEME_LIST)); proxySetupComboBox.setItems(FXCollections.observableList(List.of(ProxySetup.values()))); + proxySetupComboBox.setCellFactory(_ -> new ProxySetupCell()); + proxySetupComboBox.setButtonCell(new ProxySetupCell()); + themeComboBox.setConverter(new StringConverter<>() { @Override public String toString(Theme object) { @@ -78,6 +82,14 @@ public class SetupController extends BaseController implements I proxySetupComboBox.getSelectionModel().selectedItemProperty().addListener((_, _, newValue) -> { proxySetupPane.setVisible(ProxySetup.MANUAL.equals(newValue)); proxyCheck.setVisible(!ProxySetup.NO_PROXY.equals(newValue)); + +// proxySetupComboBox.promptTextProperty().bind( +//// Bindings.createStringBinding( +//// () -> Context.getLanguageBinding(STR."proxy.setup.label.\{newValue.getName()}").get(), +//// Context.currentLocaleProperty() +//// ) +// Context.getLanguageBinding(STR."proxy.setup.label.\{newValue.getName()}") +// ); }); languageComboBox.getSelectionModel().select(ConfigManager.language()); diff --git a/src/main/java/cn/octopusyan/alistgui/enums/ProxySetup.java b/src/main/java/cn/octopusyan/alistgui/enums/ProxySetup.java index d0e119a..5ec896b 100644 --- a/src/main/java/cn/octopusyan/alistgui/enums/ProxySetup.java +++ b/src/main/java/cn/octopusyan/alistgui/enums/ProxySetup.java @@ -1,6 +1,7 @@ package cn.octopusyan.alistgui.enums; import cn.octopusyan.alistgui.config.Context; +import javafx.beans.binding.StringBinding; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -20,6 +21,10 @@ public enum ProxySetup { @Override public String toString() { - return Context.getLanguageBinding("proxy.setup.label." + getName()).getValue(); + return getBinding().get(); + } + + public StringBinding getBinding() { + return Context.getLanguageBinding(STR."proxy.setup.label.\{getName()}"); } } diff --git a/src/main/java/cn/octopusyan/alistgui/view/ProxySetupCell.java b/src/main/java/cn/octopusyan/alistgui/view/ProxySetupCell.java new file mode 100644 index 0000000..b15c26f --- /dev/null +++ b/src/main/java/cn/octopusyan/alistgui/view/ProxySetupCell.java @@ -0,0 +1,23 @@ +package cn.octopusyan.alistgui.view; + +import cn.octopusyan.alistgui.enums.ProxySetup; +import javafx.scene.control.ListCell; + +/** + * ProxySetup I18n Cell + * + * @author octopus_yan + */ +public class ProxySetupCell extends ListCell { + + @Override + protected void updateItem(ProxySetup item, boolean empty) { + super.updateItem(item, empty); + textProperty().unbind(); + if (empty || item == null) { + setText(""); + } else { + textProperty().bind(item.getBinding()); + } + } +}