MouseSettings: Use on_change callback to resetting default cursor theme

This commit is contained in:
Kyle Lanmon 2024-03-14 16:14:18 -05:00 committed by Andrew Kaster
parent c2e13764bc
commit 04708f11e1
2 changed files with 17 additions and 2 deletions

View file

@ -97,6 +97,22 @@ void ThemeModel::invalidate()
Model::invalidate();
}
Vector<GUI::ModelIndex> ThemeModel::matches(StringView needle, unsigned flags, const GUI::ModelIndex& parent)
{
Vector<GUI::ModelIndex> found = {};
for (size_t i = 0; i < m_themes.size(); ++i) {
auto theme = m_themes[i];
if (!string_matches(theme, needle, flags))
continue;
found.append(index(i, 0, parent));
if (flags & GUI::Model::MatchesFlag::FirstMatchOnly)
break;
}
return found;
}
ErrorOr<NonnullRefPtr<ThemeWidget>> ThemeWidget::try_create()
{
auto widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ThemeWidget()));
@ -145,6 +161,4 @@ void ThemeWidget::apply_settings()
void ThemeWidget::reset_default_values()
{
m_theme_name_box->set_text("Default");
// FIXME: ComboBox::set_text() doesn't fire the on_change callback, so we have to set the theme here manually.
m_mouse_cursor_model->change_theme("Default");
}

View file

@ -56,6 +56,7 @@ public:
virtual int column_count(const GUI::ModelIndex&) const override { return 1; }
virtual GUI::Variant data(const GUI::ModelIndex& index, GUI::ModelRole role) const override;
virtual Vector<GUI::ModelIndex> matches(StringView, unsigned = GUI::Model::MatchesFlag::AllMatching, GUI::ModelIndex const& = GUI::ModelIndex()) override;
virtual void invalidate() override;
private: