mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:37:36 +00:00
GToolBar: Make add_action() take a GAction& instead of NonnullRefPtr&&.
There's very little reason to take NonnullRefPtr&& in arguments really. You can avoid ref-count churn in the cases where ownership is transferred from the caller to the callee, but that's a pretty unusual situation and not worth optimizing for at this stage.
This commit is contained in:
parent
8327b12291
commit
7faf878e0a
2 changed files with 5 additions and 6 deletions
|
@ -18,12 +18,11 @@ GToolBar::~GToolBar()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GToolBar::add_action(NonnullRefPtr<GAction>&& action)
|
void GToolBar::add_action(GAction& action)
|
||||||
{
|
{
|
||||||
GAction* raw_action_ptr = action.ptr();
|
|
||||||
auto item = make<Item>();
|
auto item = make<Item>();
|
||||||
item->type = Item::Action;
|
item->type = Item::Action;
|
||||||
item->action = move(action);
|
item->action = action;
|
||||||
|
|
||||||
auto* button = new GButton(this);
|
auto* button = new GButton(this);
|
||||||
button->set_action(*item->action);
|
button->set_action(*item->action);
|
||||||
|
@ -32,8 +31,8 @@ void GToolBar::add_action(NonnullRefPtr<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 = [raw_action_ptr](const GButton&) {
|
button->on_click = [&action](const GButton&) {
|
||||||
raw_action_ptr->activate();
|
action.activate();
|
||||||
};
|
};
|
||||||
|
|
||||||
button->set_button_style(ButtonStyle::CoolBar);
|
button->set_button_style(ButtonStyle::CoolBar);
|
||||||
|
|
|
@ -9,7 +9,7 @@ public:
|
||||||
explicit GToolBar(GWidget* parent);
|
explicit GToolBar(GWidget* parent);
|
||||||
virtual ~GToolBar() override;
|
virtual ~GToolBar() override;
|
||||||
|
|
||||||
void add_action(NonnullRefPtr<GAction>&&);
|
void add_action(GAction&);
|
||||||
void add_separator();
|
void add_separator();
|
||||||
|
|
||||||
bool has_frame() const { return m_has_frame; }
|
bool has_frame() const { return m_has_frame; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue