1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-22 10:47:43 +00:00

GComboBox: Add set_text() and on_return_pressed hook.

Also give focus back to the editor when closing the list popup window.
This commit is contained in:
Andreas Kling 2019-06-23 07:55:28 +02:00
parent 0af61e9123
commit 1d0ada32cc
2 changed files with 12 additions and 0 deletions

View file

@ -13,6 +13,10 @@ GComboBox::GComboBox(GWidget* parent)
if (on_change) if (on_change)
on_change(m_editor->text()); 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 = new GButton(this);
m_open_button->set_focusable(false); m_open_button->set_focusable(false);
m_open_button->set_text("\xf7"); m_open_button->set_text("\xf7");
@ -84,9 +88,15 @@ void GComboBox::open()
void GComboBox::close() void GComboBox::close()
{ {
m_list_window->hide(); m_list_window->hide();
m_editor->set_focus(true);
} }
String GComboBox::text() const String GComboBox::text() const
{ {
return m_editor->text(); return m_editor->text();
} }
void GComboBox::set_text(const String& text)
{
m_editor->set_text(text);
}

View file

@ -12,6 +12,7 @@ public:
virtual ~GComboBox() override; virtual ~GComboBox() override;
String text() const; String text() const;
void set_text(const String&);
void open(); void open();
void close(); void close();
@ -21,6 +22,7 @@ public:
void set_model(NonnullRefPtr<GModel>); void set_model(NonnullRefPtr<GModel>);
Function<void(const String&)> on_change; Function<void(const String&)> on_change;
Function<void()> on_return_pressed;
virtual const char* class_name() const override { return "GComboBox"; } virtual const char* class_name() const override { return "GComboBox"; }