diff options
author | Andreas Kling <kling@serenityos.org> | 2020-08-21 20:01:45 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-21 21:16:13 +0200 |
commit | 8055813ecf002a8e617f3d722e562a9425e82481 (patch) | |
tree | 4446af9e3daaf7ef4736f8dd12e88f646a7bba66 /Libraries | |
parent | 50076997f4608a8b072d5bf1e4ec1413bad9e8d5 (diff) | |
download | serenity-8055813ecf002a8e617f3d722e562a9425e82481.zip |
LibGUI: Add ComboBox::selected_index()
This returns the currently selected index. It was a bit strange that
we had set_selected_index() but not a way to read it back. :^)
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibGUI/ComboBox.cpp | 5 | ||||
-rw-r--r-- | Libraries/LibGUI/ComboBox.h | 1 |
2 files changed, 6 insertions, 0 deletions
diff --git a/Libraries/LibGUI/ComboBox.cpp b/Libraries/LibGUI/ComboBox.cpp index e04ec4f09f..fa082c85c2 100644 --- a/Libraries/LibGUI/ComboBox.cpp +++ b/Libraries/LibGUI/ComboBox.cpp @@ -163,6 +163,11 @@ void ComboBox::set_selected_index(size_t index) this->m_list_view->selection().set(model_index); } +size_t ComboBox::selected_index() const +{ + return m_list_view->selection().first().row(); +} + void ComboBox::select_all() { m_editor->select_all(); diff --git a/Libraries/LibGUI/ComboBox.h b/Libraries/LibGUI/ComboBox.h index 0a82d17ff1..b9c3fe8e21 100644 --- a/Libraries/LibGUI/ComboBox.h +++ b/Libraries/LibGUI/ComboBox.h @@ -49,6 +49,7 @@ public: const Model* model() const; void set_model(NonnullRefPtr<Model>); + size_t selected_index() const; void set_selected_index(size_t index); bool only_allow_values_from_model() const { return m_only_allow_values_from_model; } |