1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 17:37:35 +00:00

GComboBox: Include the selected index with the on_change notification

This will be useful for clients that need to fetch additional data from
the model on selection change.
This commit is contained in:
Andreas Kling 2019-08-05 18:42:51 +02:00
parent ffff150435
commit 6311a617be
3 changed files with 5 additions and 5 deletions

View file

@ -37,7 +37,7 @@ public:
combo->set_only_allow_values_from_model(true); combo->set_only_allow_values_from_model(true);
combo->set_model(adopt(*new BoolValuesModel)); combo->set_model(adopt(*new BoolValuesModel));
combo->on_return_pressed = [this] { commit(); }; combo->on_return_pressed = [this] { commit(); };
combo->on_change = [this](auto&) { commit(); }; combo->on_change = [this](auto&, auto&) { commit(); };
return combo; return combo;
} }
virtual GVariant value() const override { return static_cast<const GComboBox*>(widget())->text() == "true"; } virtual GVariant value() const override { return static_cast<const GComboBox*>(widget())->text() == "true"; }

View file

@ -12,7 +12,7 @@ GComboBox::GComboBox(GWidget* parent)
m_editor = new GTextEditor(GTextEditor::Type::SingleLine, this); m_editor = new GTextEditor(GTextEditor::Type::SingleLine, this);
m_editor->on_change = [this] { m_editor->on_change = [this] {
if (on_change) if (on_change)
on_change(m_editor->text()); on_change(m_editor->text(), model()->selected_index());
}; };
m_editor->on_return_pressed = [this] { m_editor->on_return_pressed = [this] {
if (on_return_pressed) if (on_return_pressed)
@ -43,9 +43,9 @@ GComboBox::GComboBox(GWidget* parent)
m_editor->set_text(new_value); m_editor->set_text(new_value);
m_editor->select_all(); m_editor->select_all();
close(); close();
deferred_invoke([this](auto&) { deferred_invoke([this, index](auto&) {
if (on_change) if (on_change)
on_change(m_editor->text()); on_change(m_editor->text(), index);
}); });
}; };
} }

View file

@ -29,7 +29,7 @@ public:
int model_column() const { return m_list_view->model_column(); } int model_column() const { return m_list_view->model_column(); }
void set_model_column(int column) { m_list_view->set_model_column(column); } void set_model_column(int column) { m_list_view->set_model_column(column); }
Function<void(const String&)> on_change; Function<void(const String&, const GModelIndex&)> on_change;
Function<void()> on_return_pressed; Function<void()> on_return_pressed;
protected: protected: