ladybird/LibGUI/GAction.cpp
Andreas Kling 5e40aa4f1a LibGUI: Move shortcut actions from GEventLoop to GApplications.
I'm gonna want to have nested event loops sooner or later, so let's not
pollute GEventLoop with things that are meant to work globally.

This patch also changes key events to pass around their modifiers as a
bitfield all the way around the system instead of breaking them up.
2019-03-03 12:32:15 +01:00

49 lines
1.4 KiB
C++

#include <LibGUI/GAction.h>
#include <LibGUI/GApplication.h>
GAction::GAction(const String& text, const String& custom_data, Function<void(const GAction&)> on_activation_callback)
: on_activation(move(on_activation_callback))
, m_text(text)
, m_custom_data(custom_data)
{
}
GAction::GAction(const String& text, Function<void(const GAction&)> on_activation_callback)
: GAction(text, String(), move(on_activation_callback))
{
}
GAction::GAction(const String& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(const GAction&)> on_activation_callback)
: on_activation(move(on_activation_callback))
, m_text(text)
, m_icon(move(icon))
{
}
GAction::GAction(const String& text, const GShortcut& shortcut, Function<void(const GAction&)> on_activation_callback)
: GAction(text, shortcut, nullptr, move(on_activation_callback))
{
}
GAction::GAction(const String& text, const GShortcut& shortcut, RetainPtr<GraphicsBitmap>&& icon, Function<void(const GAction&)> on_activation_callback)
: on_activation(move(on_activation_callback))
, m_text(text)
, m_icon(move(icon))
, m_shortcut(shortcut)
{
GApplication::the().register_shortcut_action(Badge<GAction>(), *this);
}
GAction::~GAction()
{
if (m_shortcut.is_valid())
GApplication::the().unregister_shortcut_action(Badge<GAction>(), *this);
}
void GAction::activate()
{
if (on_activation)
on_activation(*this);
}