#pragma once #include #include #include #include #include #include #include #include #include class GButton; class GMenuItem; class GAction : public Retainable, public Weakable { public: static Retained create(const String& text, Function callback) { return adopt(*new GAction(text, move(callback))); } static Retained create(const String& text, const String& custom_data, Function callback) { return adopt(*new GAction(text, custom_data, move(callback))); } static Retained create(const String& text, RetainPtr&& icon, Function callback) { return adopt(*new GAction(text, move(icon), move(callback))); } static Retained create(const String& text, const GShortcut& shortcut, Function callback) { return adopt(*new GAction(text, shortcut, move(callback))); } static Retained create(const String& text, const GShortcut& shortcut, RetainPtr&& icon, Function callback) { return adopt(*new GAction(text, shortcut, move(icon), move(callback))); } ~GAction(); String text() const { return m_text; } GShortcut shortcut() const { return m_shortcut; } String custom_data() const { return m_custom_data; } const GraphicsBitmap* icon() const { return m_icon.ptr(); } Function on_activation; void activate(); bool is_enabled() const { return m_enabled; } void set_enabled(bool); void register_button(Badge, GButton&); void unregister_button(Badge, GButton&); void register_menu_item(Badge, GMenuItem&); void unregister_menu_item(Badge, GMenuItem&); private: GAction(const String& text, Function = nullptr); GAction(const String& text, const GShortcut&, Function = nullptr); GAction(const String& text, const GShortcut&, RetainPtr&& icon, Function = nullptr); GAction(const String& text, RetainPtr&& icon, Function = nullptr); GAction(const String& text, const String& custom_data = String(), Function = nullptr); template void for_each_toolbar_button(Callback); template void for_each_menu_item(Callback); String m_text; String m_custom_data; RetainPtr m_icon; GShortcut m_shortcut; bool m_enabled { true }; HashTable m_buttons; HashTable m_menu_items; };