1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:08:12 +00:00

LibGUI+TextEditor: Make GButton activate its action if present

Previously even if you assigned a GAction to a GButton, you still had
to activate() the action manually by hooking the GButton::on_click
callback.
This commit is contained in:
Andreas Kling 2019-08-25 21:42:37 +02:00
parent ded005500d
commit e8e8741c88
3 changed files with 2 additions and 9 deletions

View file

@ -74,17 +74,11 @@ TextEditorWidget::TextEditorWidget()
m_find_previous_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill); m_find_previous_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
m_find_previous_button->set_preferred_size(64, 0); m_find_previous_button->set_preferred_size(64, 0);
m_find_previous_button->set_action(*m_find_previous_action); m_find_previous_button->set_action(*m_find_previous_action);
m_find_previous_button->on_click = [&](auto&) {
m_find_previous_action->activate();
};
m_find_next_button = new GButton("Next", m_find_widget); m_find_next_button = new GButton("Next", m_find_widget);
m_find_next_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill); m_find_next_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
m_find_next_button->set_preferred_size(64, 0); m_find_next_button->set_preferred_size(64, 0);
m_find_next_button->set_action(*m_find_next_action); m_find_next_button->set_action(*m_find_next_action);
m_find_next_button->on_click = [&](auto&) {
m_find_next_action->activate();
};
m_find_textbox->on_return_pressed = [this] { m_find_textbox->on_return_pressed = [this] {
m_find_next_button->click(); m_find_next_button->click();

View file

@ -68,6 +68,8 @@ void GButton::click()
} }
if (on_click) if (on_click)
on_click(*this); on_click(*this);
if (m_action)
m_action->activate();
} }
bool GButton::supports_keyboard_activation() const bool GButton::supports_keyboard_activation() const

View file

@ -31,9 +31,6 @@ void GToolBar::add_action(GAction& action)
button->set_icon(item->action->icon()); button->set_icon(item->action->icon());
else else
button->set_text(item->action->text()); button->set_text(item->action->text());
button->on_click = [&action](const GButton&) {
action.activate();
};
button->set_button_style(ButtonStyle::CoolBar); button->set_button_style(ButtonStyle::CoolBar);
button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed); button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);