From 1d243ef3e3eed974e8381219d656d2caec33a20f Mon Sep 17 00:00:00 2001 From: Kyle Lanmon Date: Thu, 14 Mar 2024 15:54:18 -0500 Subject: [PATCH] GamesSettings: Use on_change callback for resetting chess defaults --- .../GamesSettings/ChessSettingsWidget.cpp | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/Userland/Applications/GamesSettings/ChessSettingsWidget.cpp b/Userland/Applications/GamesSettings/ChessSettingsWidget.cpp index e5766e69168..bd9ed53933d 100644 --- a/Userland/Applications/GamesSettings/ChessSettingsWidget.cpp +++ b/Userland/Applications/GamesSettings/ChessSettingsWidget.cpp @@ -69,6 +69,23 @@ public: return s_board_themes.at(index.row()).name; } + virtual Vector matches(StringView needle, unsigned flags = MatchesFlag::AllMatching, GUI::ModelIndex const& parent = GUI::ModelIndex()) override + { + Vector found = {}; + + for (size_t i = 0; i < s_board_themes.size(); ++i) { + auto theme = s_board_themes[i]; + if (!string_matches(theme.name, needle, flags)) + continue; + + found.append(index(i, 0, parent)); + if (flags & FirstMatchOnly) + break; + } + + return found; + } + private: BoardThemeModel() { @@ -294,14 +311,8 @@ void ChessSettingsWidget::apply_settings() void ChessSettingsWidget::reset_default_values() { - // FIXME: `set_text()` on a combobox doesn't trigger the `on_change` callback, but it probably should! - // Until then, we have to manually tell the preview to update. - m_piece_set_combobox->set_text("Classic"); - m_preview->set_piece_set_name("Classic"_string); - auto& board_theme = get_board_theme("Beige"sv); - m_board_theme_combobox->set_text(board_theme.name); - m_preview->set_dark_square_color(board_theme.dark_square_color); - m_preview->set_light_square_color(board_theme.light_square_color); + m_piece_set_combobox->set_text("Classic"sv); + m_board_theme_combobox->set_text("Beige"sv); m_show_coordinates_checkbox->set_checked(true); m_highlight_checks_checkbox->set_checked(true); }