fix: 修复代理类型下拉框无法跟随语言切换的问题
Some checks are pending
Auto Alpha Tag / auto-tag (x64, x64) (push) Waiting to run
Release / meta (push) Waiting to run
Release / windows (x64, x64) (push) Blocked by required conditions
Release / release (push) Blocked by required conditions

This commit is contained in:
octopus_yan 2024-09-21 12:46:21 +08:00
parent 4702396bbc
commit 828a2fdb62
3 changed files with 41 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import cn.octopusyan.alistgui.config.Context;
import cn.octopusyan.alistgui.config.I18n; import cn.octopusyan.alistgui.config.I18n;
import cn.octopusyan.alistgui.enums.ProxySetup; import cn.octopusyan.alistgui.enums.ProxySetup;
import cn.octopusyan.alistgui.manager.ConfigManager; import cn.octopusyan.alistgui.manager.ConfigManager;
import cn.octopusyan.alistgui.view.ProxySetupCell;
import cn.octopusyan.alistgui.viewModel.SetupViewModel; import cn.octopusyan.alistgui.viewModel.SetupViewModel;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.fxml.FXML; import javafx.fxml.FXML;
@ -60,6 +61,9 @@ public class SetupController extends BaseController<SetupViewModel> implements I
themeComboBox.setItems(FXCollections.observableList(ConfigManager.THEME_LIST)); themeComboBox.setItems(FXCollections.observableList(ConfigManager.THEME_LIST));
proxySetupComboBox.setItems(FXCollections.observableList(List.of(ProxySetup.values()))); proxySetupComboBox.setItems(FXCollections.observableList(List.of(ProxySetup.values())));
proxySetupComboBox.setCellFactory(_ -> new ProxySetupCell());
proxySetupComboBox.setButtonCell(new ProxySetupCell());
themeComboBox.setConverter(new StringConverter<>() { themeComboBox.setConverter(new StringConverter<>() {
@Override @Override
public String toString(Theme object) { public String toString(Theme object) {
@ -78,6 +82,14 @@ public class SetupController extends BaseController<SetupViewModel> implements I
proxySetupComboBox.getSelectionModel().selectedItemProperty().addListener((_, _, newValue) -> { proxySetupComboBox.getSelectionModel().selectedItemProperty().addListener((_, _, newValue) -> {
proxySetupPane.setVisible(ProxySetup.MANUAL.equals(newValue)); proxySetupPane.setVisible(ProxySetup.MANUAL.equals(newValue));
proxyCheck.setVisible(!ProxySetup.NO_PROXY.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()); languageComboBox.getSelectionModel().select(ConfigManager.language());

View File

@ -1,6 +1,7 @@
package cn.octopusyan.alistgui.enums; package cn.octopusyan.alistgui.enums;
import cn.octopusyan.alistgui.config.Context; import cn.octopusyan.alistgui.config.Context;
import javafx.beans.binding.StringBinding;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -20,6 +21,10 @@ public enum ProxySetup {
@Override @Override
public String toString() { 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()}");
} }
} }

View File

@ -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<ProxySetup> {
@Override
protected void updateItem(ProxySetup item, boolean empty) {
super.updateItem(item, empty);
textProperty().unbind();
if (empty || item == null) {
setText("");
} else {
textProperty().bind(item.getBinding());
}
}
}