2019-02-12 14:09:48 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/AKString.h>
|
|
|
|
#include <AK/Function.h>
|
2019-02-20 02:39:46 +01:00
|
|
|
#include <AK/Retainable.h>
|
2019-02-25 12:43:52 +01:00
|
|
|
#include <AK/Retained.h>
|
2019-02-20 02:39:46 +01:00
|
|
|
#include <SharedGraphics/GraphicsBitmap.h>
|
2019-03-02 10:04:49 +01:00
|
|
|
#include <LibGUI/GShortcut.h>
|
2019-02-12 14:09:48 +01:00
|
|
|
|
2019-02-20 02:39:46 +01:00
|
|
|
class GAction : public Retainable<GAction> {
|
2019-02-12 14:09:48 +01:00
|
|
|
public:
|
2019-02-25 12:43:52 +01:00
|
|
|
static Retained<GAction> create(const String& text, Function<void(const GAction&)> callback)
|
2019-02-20 02:39:46 +01:00
|
|
|
{
|
|
|
|
return adopt(*new GAction(text, move(callback)));
|
|
|
|
}
|
2019-02-25 12:43:52 +01:00
|
|
|
static Retained<GAction> create(const String& text, const String& custom_data, Function<void(const GAction&)> callback)
|
2019-02-20 02:39:46 +01:00
|
|
|
{
|
|
|
|
return adopt(*new GAction(text, custom_data, move(callback)));
|
|
|
|
}
|
2019-02-25 12:43:52 +01:00
|
|
|
static Retained<GAction> create(const String& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(const GAction&)> callback)
|
2019-02-20 02:39:46 +01:00
|
|
|
{
|
|
|
|
return adopt(*new GAction(text, move(icon), move(callback)));
|
|
|
|
}
|
2019-03-02 10:04:49 +01:00
|
|
|
static Retained<GAction> create(const String& text, const GShortcut& shortcut, RetainPtr<GraphicsBitmap>&& icon, Function<void(const GAction&)> callback)
|
|
|
|
{
|
|
|
|
return adopt(*new GAction(text, shortcut, move(icon), move(callback)));
|
|
|
|
}
|
2019-02-12 14:09:48 +01:00
|
|
|
~GAction();
|
|
|
|
|
|
|
|
String text() const { return m_text; }
|
2019-03-02 10:04:49 +01:00
|
|
|
GShortcut shortcut() const { return m_shortcut; }
|
2019-02-12 14:09:48 +01:00
|
|
|
String custom_data() const { return m_custom_data; }
|
2019-02-20 02:39:46 +01:00
|
|
|
const GraphicsBitmap* icon() const { return m_icon.ptr(); }
|
2019-02-12 14:09:48 +01:00
|
|
|
|
|
|
|
Function<void(GAction&)> on_activation;
|
|
|
|
|
|
|
|
void activate();
|
|
|
|
|
|
|
|
private:
|
2019-02-20 02:39:46 +01:00
|
|
|
GAction(const String& text, Function<void(const GAction&)> = nullptr);
|
2019-03-02 10:04:49 +01:00
|
|
|
GAction(const String& text, const GShortcut&, RetainPtr<GraphicsBitmap>&& icon, Function<void(const GAction&)> = nullptr);
|
2019-02-20 02:39:46 +01:00
|
|
|
GAction(const String& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(const GAction&)> = nullptr);
|
|
|
|
GAction(const String& text, const String& custom_data = String(), Function<void(const GAction&)> = nullptr);
|
|
|
|
|
2019-02-12 14:09:48 +01:00
|
|
|
String m_text;
|
|
|
|
String m_custom_data;
|
2019-02-20 02:39:46 +01:00
|
|
|
RetainPtr<GraphicsBitmap> m_icon;
|
2019-03-02 10:04:49 +01:00
|
|
|
GShortcut m_shortcut;
|
2019-02-12 14:09:48 +01:00
|
|
|
};
|
|
|
|
|