1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:17:36 +00:00

LibGUI+FontEditor: Allow ComboBox on_change callback to be toggled

When calling set_selected_index() on ComboBox, allow its on_change
callback to be disabled. Fixes FontEditor window state erroneously
switching to modified when initializing between different slopes
and weights.
This commit is contained in:
thankyouverycool 2021-11-29 14:43:02 -05:00 committed by Andreas Kling
parent ca062d83db
commit 298a6b9937
3 changed files with 5 additions and 5 deletions

View file

@ -521,7 +521,7 @@ void FontEditorWidget::initialize(String const& path, RefPtr<Gfx::BitmapFont>&&
int i = 0;
for (auto& it : Gfx::font_weight_names) {
if (it.style == m_edited_font->weight()) {
m_weight_combobox->set_selected_index(i);
m_weight_combobox->set_selected_index(i, GUI::AllowCallback::No);
break;
}
i++;
@ -529,7 +529,7 @@ void FontEditorWidget::initialize(String const& path, RefPtr<Gfx::BitmapFont>&&
i = 0;
for (auto& it : Gfx::font_slope_names) {
if (it.style == m_edited_font->slope()) {
m_slope_combobox->set_selected_index(i);
m_slope_combobox->set_selected_index(i, GUI::AllowCallback::No);
break;
}
i++;

View file

@ -201,14 +201,14 @@ void ComboBox::set_model(NonnullRefPtr<Model> model)
m_list_view->set_model(move(model));
}
void ComboBox::set_selected_index(size_t index)
void ComboBox::set_selected_index(size_t index, AllowCallback allow_callback)
{
if (!m_list_view->model())
return;
size_t previous_index = selected_index();
TemporaryChange change(m_updating_model, true);
m_list_view->set_cursor(m_list_view->model()->index(index, 0), AbstractView::SelectionUpdate::Set);
if (previous_index != selected_index() && on_change)
if (previous_index != selected_index() && on_change && allow_callback == AllowCallback::Yes)
on_change(m_editor->text(), m_list_view->cursor_index());
}

View file

@ -32,7 +32,7 @@ public:
void set_model(NonnullRefPtr<Model>);
size_t selected_index() const;
void set_selected_index(size_t index);
void set_selected_index(size_t index, AllowCallback = AllowCallback::Yes);
bool only_allow_values_from_model() const { return m_only_allow_values_from_model; }
void set_only_allow_values_from_model(bool);