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-04-12 02:53:27 +02:00
|
|
|
#include <AK/Weakable.h>
|
|
|
|
#include <AK/Badge.h>
|
|
|
|
#include <AK/HashTable.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-04-12 02:53:27 +02:00
|
|
|
class GButton;
|
|
|
|
class GMenuItem;
|
|
|
|
|
|
|
|
class GAction : public Retainable<GAction>, public Weakable<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-03 02:52:22 +01:00
|
|
|
static Retained<GAction> create(const String& text, const GShortcut& shortcut, Function<void(const GAction&)> callback)
|
|
|
|
{
|
|
|
|
return adopt(*new GAction(text, shortcut, 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();
|
|
|
|
|
2019-04-12 02:53:27 +02:00
|
|
|
bool is_enabled() const { return m_enabled; }
|
|
|
|
void set_enabled(bool);
|
|
|
|
|
|
|
|
void register_button(Badge<GButton>, GButton&);
|
|
|
|
void unregister_button(Badge<GButton>, GButton&);
|
|
|
|
void register_menu_item(Badge<GMenuItem>, GMenuItem&);
|
|
|
|
void unregister_menu_item(Badge<GMenuItem>, GMenuItem&);
|
|
|
|
|
2019-02-12 14:09:48 +01:00
|
|
|
private:
|
2019-02-20 02:39:46 +01:00
|
|
|
GAction(const String& text, Function<void(const GAction&)> = nullptr);
|
2019-03-03 02:52:22 +01:00
|
|
|
GAction(const String& text, const GShortcut&, 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-04-12 02:53:27 +02:00
|
|
|
template<typename Callback> void for_each_toolbar_button(Callback);
|
|
|
|
template<typename Callback> void for_each_menu_item(Callback);
|
|
|
|
|
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-04-12 02:53:27 +02:00
|
|
|
bool m_enabled { true };
|
|
|
|
|
|
|
|
HashTable<GButton*> m_buttons;
|
|
|
|
HashTable<GMenuItem*> m_menu_items;
|
2019-02-12 14:09:48 +01:00
|
|
|
};
|
|
|
|
|