LibGUI: Tidy up Action constructors and factory functions a bit

This commit is contained in:
Andreas Kling 2021-02-20 12:45:55 +01:00
parent a1a625b565
commit 1bc17d2870
Notes: sideshowbarker 2024-07-18 22:07:07 +09:00
2 changed files with 60 additions and 44 deletions

View file

@ -143,32 +143,72 @@ NonnullRefPtr<Action> make_select_all_action(Function<void(Action&)> callback, C
}
Action::Action(const StringView& text, Function<void(Action&)> on_activation_callback, Core::Object* parent, bool checkable)
NonnullRefPtr<Action> Action::create(String text, Function<void(Action&)> callback, Core::Object* parent)
{
return adopt(*new Action(move(text), move(callback), parent));
}
NonnullRefPtr<Action> Action::create(String text, RefPtr<Gfx::Bitmap> icon, Function<void(Action&)> callback, Core::Object* parent)
{
return adopt(*new Action(move(text), move(icon), move(callback), parent));
}
NonnullRefPtr<Action> Action::create(String text, const Shortcut& shortcut, Function<void(Action&)> callback, Core::Object* parent)
{
return adopt(*new Action(move(text), shortcut, move(callback), parent));
}
NonnullRefPtr<Action> Action::create(String text, const Shortcut& shortcut, RefPtr<Gfx::Bitmap> icon, Function<void(Action&)> callback, Core::Object* parent)
{
return adopt(*new Action(move(text), shortcut, move(icon), move(callback), parent));
}
NonnullRefPtr<Action> Action::create_checkable(String text, Function<void(Action&)> callback, Core::Object* parent)
{
return adopt(*new Action(move(text), move(callback), parent, true));
}
NonnullRefPtr<Action> Action::create_checkable(String text, RefPtr<Gfx::Bitmap> icon, Function<void(Action&)> callback, Core::Object* parent)
{
return adopt(*new Action(move(text), move(icon), move(callback), parent, true));
}
NonnullRefPtr<Action> Action::create_checkable(String text, const Shortcut& shortcut, Function<void(Action&)> callback, Core::Object* parent)
{
return adopt(*new Action(move(text), shortcut, move(callback), parent, true));
}
NonnullRefPtr<Action> Action::create_checkable(String text, const Shortcut& shortcut, RefPtr<Gfx::Bitmap> icon, Function<void(Action&)> callback, Core::Object* parent)
{
return adopt(*new Action(move(text), shortcut, move(icon), move(callback), parent, true));
}
Action::Action(String text, Function<void(Action&)> on_activation_callback, Core::Object* parent, bool checkable)
: Core::Object(parent)
, on_activation(move(on_activation_callback))
, m_text(text)
, m_text(move(text))
, m_checkable(checkable)
{
}
Action::Action(const StringView& text, RefPtr<Gfx::Bitmap>&& icon, Function<void(Action&)> on_activation_callback, Core::Object* parent, bool checkable)
Action::Action(String text, RefPtr<Gfx::Bitmap> icon, Function<void(Action&)> on_activation_callback, Core::Object* parent, bool checkable)
: Core::Object(parent)
, on_activation(move(on_activation_callback))
, m_text(text)
, m_text(move(text))
, m_icon(move(icon))
, m_checkable(checkable)
{
}
Action::Action(const StringView& text, const Shortcut& shortcut, Function<void(Action&)> on_activation_callback, Core::Object* parent, bool checkable)
: Action(text, shortcut, nullptr, move(on_activation_callback), parent, checkable)
Action::Action(String text, const Shortcut& shortcut, Function<void(Action&)> on_activation_callback, Core::Object* parent, bool checkable)
: Action(move(text), shortcut, nullptr, move(on_activation_callback), parent, checkable)
{
}
Action::Action(const StringView& text, const Shortcut& shortcut, RefPtr<Gfx::Bitmap>&& icon, Function<void(Action&)> on_activation_callback, Core::Object* parent, bool checkable)
Action::Action(String text, const Shortcut& shortcut, RefPtr<Gfx::Bitmap> icon, Function<void(Action&)> on_activation_callback, Core::Object* parent, bool checkable)
: Core::Object(parent)
, on_activation(move(on_activation_callback))
, m_text(text)
, m_text(move(text))
, m_icon(move(icon))
, m_shortcut(shortcut)
, m_checkable(checkable)

View file

@ -73,38 +73,14 @@ public:
WindowLocal,
ApplicationGlobal,
};
static NonnullRefPtr<Action> create(const StringView& text, Function<void(Action&)> callback, Core::Object* parent = nullptr)
{
return adopt(*new Action(text, move(callback), parent));
}
static NonnullRefPtr<Action> create(const StringView& text, RefPtr<Gfx::Bitmap>&& icon, Function<void(Action&)> callback, Core::Object* parent = nullptr)
{
return adopt(*new Action(text, move(icon), move(callback), parent));
}
static NonnullRefPtr<Action> create(const StringView& text, const Shortcut& shortcut, Function<void(Action&)> callback, Core::Object* parent = nullptr)
{
return adopt(*new Action(text, shortcut, move(callback), parent));
}
static NonnullRefPtr<Action> create(const StringView& text, const Shortcut& shortcut, RefPtr<Gfx::Bitmap>&& icon, Function<void(Action&)> callback, Core::Object* parent = nullptr)
{
return adopt(*new Action(text, shortcut, move(icon), move(callback), parent));
}
static NonnullRefPtr<Action> create_checkable(const StringView& text, Function<void(Action&)> callback, Core::Object* parent = nullptr)
{
return adopt(*new Action(text, move(callback), parent, true));
}
static NonnullRefPtr<Action> create_checkable(const StringView& text, RefPtr<Gfx::Bitmap>&& icon, Function<void(Action&)> callback, Core::Object* parent = nullptr)
{
return adopt(*new Action(text, move(icon), move(callback), parent, true));
}
static NonnullRefPtr<Action> create_checkable(const StringView& text, const Shortcut& shortcut, Function<void(Action&)> callback, Core::Object* parent = nullptr)
{
return adopt(*new Action(text, shortcut, move(callback), parent, true));
}
static NonnullRefPtr<Action> create_checkable(const StringView& text, const Shortcut& shortcut, RefPtr<Gfx::Bitmap>&& icon, Function<void(Action&)> callback, Core::Object* parent = nullptr)
{
return adopt(*new Action(text, shortcut, move(icon), move(callback), parent, true));
}
static NonnullRefPtr<Action> create(String text, Function<void(Action&)> callback, Core::Object* parent = nullptr);
static NonnullRefPtr<Action> create(String text, RefPtr<Gfx::Bitmap> icon, Function<void(Action&)> callback, Core::Object* parent = nullptr);
static NonnullRefPtr<Action> create(String text, const Shortcut& shortcut, Function<void(Action&)> callback, Core::Object* parent = nullptr);
static NonnullRefPtr<Action> create(String text, const Shortcut& shortcut, RefPtr<Gfx::Bitmap> icon, Function<void(Action&)> callback, Core::Object* parent = nullptr);
static NonnullRefPtr<Action> create_checkable(String text, Function<void(Action&)> callback, Core::Object* parent = nullptr);
static NonnullRefPtr<Action> create_checkable(String text, RefPtr<Gfx::Bitmap> icon, Function<void(Action&)> callback, Core::Object* parent = nullptr);
static NonnullRefPtr<Action> create_checkable(String text, const Shortcut& shortcut, Function<void(Action&)> callback, Core::Object* parent = nullptr);
static NonnullRefPtr<Action> create_checkable(String text, const Shortcut& shortcut, RefPtr<Gfx::Bitmap> icon, Function<void(Action&)> callback, Core::Object* parent = nullptr);
virtual ~Action() override;
@ -146,10 +122,10 @@ public:
void set_group(Badge<ActionGroup>, ActionGroup*);
private:
Action(const StringView& text, Function<void(Action&)> = nullptr, Core::Object* = nullptr, bool checkable = false);
Action(const StringView& text, const Shortcut&, Function<void(Action&)> = nullptr, Core::Object* = nullptr, bool checkable = false);
Action(const StringView& text, const Shortcut&, RefPtr<Gfx::Bitmap>&& icon, Function<void(Action&)> = nullptr, Core::Object* = nullptr, bool checkable = false);
Action(const StringView& text, RefPtr<Gfx::Bitmap>&& icon, Function<void(Action&)> = nullptr, Core::Object* = nullptr, bool checkable = false);
Action(String, Function<void(Action&)> = nullptr, Core::Object* = nullptr, bool checkable = false);
Action(String, const Shortcut&, Function<void(Action&)> = nullptr, Core::Object* = nullptr, bool checkable = false);
Action(String, const Shortcut&, RefPtr<Gfx::Bitmap> icon, Function<void(Action&)> = nullptr, Core::Object* = nullptr, bool checkable = false);
Action(String, RefPtr<Gfx::Bitmap> icon, Function<void(Action&)> = nullptr, Core::Object* = nullptr, bool checkable = false);
template<typename Callback>
void for_each_toolbar_button(Callback);