Skip to content

Commit e74e320

Browse files
AtkinsSJawesomekling
authored andcommitted
MouseSettings: Update the cursor theme preview when restoring defaults
Previously, if you opened MouseSettings, set the cursor theme to Dark, and then click "Defaults", the cursors list would not update. ComboBox::set_text() does not call the on_change callback, so we have to run the steps manually. I've also made `m_theme_name` into a local variable, since it can be.
1 parent 6ba03de commit e74e320

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

Userland/Applications/MouseSettings/ThemeWidget.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,26 +106,25 @@ ThemeWidget::ThemeWidget()
106106
m_cursors_tableview->set_column_headers_visible(false);
107107
m_cursors_tableview->set_highlight_key_column(false);
108108

109-
auto mouse_cursor_model = MouseCursorModel::create();
110-
auto sorting_proxy_model = MUST(GUI::SortingProxyModel::create(mouse_cursor_model));
109+
m_mouse_cursor_model = MouseCursorModel::create();
110+
auto sorting_proxy_model = MUST(GUI::SortingProxyModel::create(*m_mouse_cursor_model));
111111
sorting_proxy_model->set_sort_role(GUI::ModelRole::Display);
112112

113113
m_cursors_tableview->set_model(sorting_proxy_model);
114114
m_cursors_tableview->set_key_column_and_sort_order(MouseCursorModel::Column::Name, GUI::SortOrder::Ascending);
115115
m_cursors_tableview->set_column_width(0, 25);
116116
m_cursors_tableview->model()->invalidate();
117117

118-
m_theme_name = GUI::ConnectionToWindowServer::the().get_cursor_theme();
119-
mouse_cursor_model->change_theme(m_theme_name);
118+
auto theme_name = GUI::ConnectionToWindowServer::the().get_cursor_theme();
119+
m_mouse_cursor_model->change_theme(theme_name);
120120

121121
m_theme_name_box = find_descendant_of_type_named<GUI::ComboBox>("theme_name_box");
122-
m_theme_name_box->on_change = [this, mouse_cursor_model](String const& value, GUI::ModelIndex const&) mutable {
123-
m_theme_name = value;
124-
mouse_cursor_model->change_theme(m_theme_name);
122+
m_theme_name_box->on_change = [this](String const& value, GUI::ModelIndex const&) mutable {
123+
m_mouse_cursor_model->change_theme(value);
125124
};
126125
m_theme_name_box->set_model(ThemeModel::create());
127126
m_theme_name_box->model()->invalidate();
128-
m_theme_name_box->set_text(m_theme_name);
127+
m_theme_name_box->set_text(theme_name);
129128
}
130129

131130
void ThemeWidget::apply_settings()
@@ -136,4 +135,6 @@ void ThemeWidget::apply_settings()
136135
void ThemeWidget::reset_default_values()
137136
{
138137
m_theme_name_box->set_text("Default");
138+
// FIXME: ComboBox::set_text() doesn't fire the on_change callback, so we have to set the theme here manually.
139+
m_mouse_cursor_model->change_theme("Default");
139140
}

Userland/Applications/MouseSettings/ThemeWidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,5 @@ class ThemeWidget final : public GUI::SettingsWindow::Tab {
7575

7676
RefPtr<GUI::TableView> m_cursors_tableview;
7777
RefPtr<GUI::ComboBox> m_theme_name_box;
78-
String m_theme_name;
78+
RefPtr<MouseCursorModel> m_mouse_cursor_model;
7979
};

0 commit comments

Comments
 (0)