From 1d0ada32cc33aac5ed9ad8fa65cb051512edd57a Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 23 Jun 2019 07:55:28 +0200 Subject: [PATCH] GComboBox: Add set_text() and on_return_pressed hook. Also give focus back to the editor when closing the list popup window. --- LibGUI/GComboBox.cpp | 10 ++++++++++ LibGUI/GComboBox.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/LibGUI/GComboBox.cpp b/LibGUI/GComboBox.cpp index a552c4d255..159bfebd40 100644 --- a/LibGUI/GComboBox.cpp +++ b/LibGUI/GComboBox.cpp @@ -13,6 +13,10 @@ GComboBox::GComboBox(GWidget* parent) if (on_change) on_change(m_editor->text()); }; + m_editor->on_return_pressed = [this] { + if (on_return_pressed) + on_return_pressed(); + }; m_open_button = new GButton(this); m_open_button->set_focusable(false); m_open_button->set_text("\xf7"); @@ -84,9 +88,15 @@ void GComboBox::open() void GComboBox::close() { m_list_window->hide(); + m_editor->set_focus(true); } String GComboBox::text() const { return m_editor->text(); } + +void GComboBox::set_text(const String& text) +{ + m_editor->set_text(text); +} diff --git a/LibGUI/GComboBox.h b/LibGUI/GComboBox.h index 7d70fe2ae5..d892f1cd57 100644 --- a/LibGUI/GComboBox.h +++ b/LibGUI/GComboBox.h @@ -12,6 +12,7 @@ public: virtual ~GComboBox() override; String text() const; + void set_text(const String&); void open(); void close(); @@ -21,6 +22,7 @@ public: void set_model(NonnullRefPtr); Function on_change; + Function on_return_pressed; virtual const char* class_name() const override { return "GComboBox"; }