فهرست منبع

MouseSettings: Use on_change callback to resetting default cursor theme

Kyle Lanmon 1 سال پیش
والد
کامیت
04708f11e1
2فایلهای تغییر یافته به همراه17 افزوده شده و 2 حذف شده
  1. 16 2
      Userland/Applications/MouseSettings/ThemeWidget.cpp
  2. 1 0
      Userland/Applications/MouseSettings/ThemeWidget.h

+ 16 - 2
Userland/Applications/MouseSettings/ThemeWidget.cpp

@@ -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");
 }

+ 1 - 0
Userland/Applications/MouseSettings/ThemeWidget.h

@@ -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: