| 
									
										
										
										
											2019-02-12 14:09:48 +01:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/AKString.h>
 | 
					
						
							| 
									
										
										
										
											2019-05-28 11:53:16 +02:00
										 |  |  | #include <AK/Badge.h>
 | 
					
						
							| 
									
										
										
										
											2019-02-12 14:09:48 +01:00
										 |  |  | #include <AK/Function.h>
 | 
					
						
							| 
									
										
										
										
											2019-05-28 11:53:16 +02:00
										 |  |  | #include <AK/HashTable.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-20 21:56:56 +02:00
										 |  |  | #include <AK/WeakPtr.h>
 | 
					
						
							| 
									
										
										
										
											2019-05-28 11:53:16 +02:00
										 |  |  | #include <AK/Weakable.h>
 | 
					
						
							| 
									
										
										
										
											2019-03-02 10:04:49 +01:00
										 |  |  | #include <LibGUI/GShortcut.h>
 | 
					
						
							| 
									
										
										
										
											2019-05-28 11:53:16 +02:00
										 |  |  | #include <SharedGraphics/GraphicsBitmap.h>
 | 
					
						
							| 
									
										
										
										
											2019-02-12 14:09:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-12 02:53:27 +02:00
										 |  |  | class GButton; | 
					
						
							|  |  |  | class GMenuItem; | 
					
						
							| 
									
										
										
										
											2019-04-20 21:56:56 +02:00
										 |  |  | class GWidget; | 
					
						
							| 
									
										
										
										
											2019-04-12 02:53:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-28 11:53:16 +02:00
										 |  |  | class GAction : public Retainable<GAction> | 
					
						
							|  |  |  |     , public Weakable<GAction> { | 
					
						
							| 
									
										
										
										
											2019-02-12 14:09:48 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2019-05-28 11:53:16 +02:00
										 |  |  |     enum class ShortcutScope | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-04-20 21:56:56 +02:00
										 |  |  |         None, | 
					
						
							|  |  |  |         ApplicationGlobal, | 
					
						
							|  |  |  |         WidgetLocal, | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2019-05-10 20:26:55 +02:00
										 |  |  |     static Retained<GAction> create(const String& text, Function<void(GAction&)> callback, GWidget* widget = nullptr) | 
					
						
							| 
									
										
										
										
											2019-02-20 02:39:46 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-04-20 21:56:56 +02:00
										 |  |  |         return adopt(*new GAction(text, move(callback), widget)); | 
					
						
							| 
									
										
										
										
											2019-02-20 02:39:46 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-05-10 20:26:55 +02:00
										 |  |  |     static Retained<GAction> create(const String& text, const String& custom_data, Function<void(GAction&)> callback, GWidget* widget = nullptr) | 
					
						
							| 
									
										
										
										
											2019-02-20 02:39:46 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-04-20 21:56:56 +02:00
										 |  |  |         return adopt(*new GAction(text, custom_data, move(callback), widget)); | 
					
						
							| 
									
										
										
										
											2019-02-20 02:39:46 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-05-10 20:26:55 +02:00
										 |  |  |     static Retained<GAction> create(const String& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> callback, GWidget* widget = nullptr) | 
					
						
							| 
									
										
										
										
											2019-02-20 02:39:46 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-04-20 21:56:56 +02:00
										 |  |  |         return adopt(*new GAction(text, move(icon), move(callback), widget)); | 
					
						
							| 
									
										
										
										
											2019-02-20 02:39:46 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-05-10 20:26:55 +02:00
										 |  |  |     static Retained<GAction> create(const String& text, const GShortcut& shortcut, Function<void(GAction&)> callback, GWidget* widget = nullptr) | 
					
						
							| 
									
										
										
										
											2019-03-03 02:52:22 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-04-20 21:56:56 +02:00
										 |  |  |         return adopt(*new GAction(text, shortcut, move(callback), widget)); | 
					
						
							| 
									
										
										
										
											2019-03-03 02:52:22 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-05-10 20:26:55 +02:00
										 |  |  |     static Retained<GAction> create(const String& text, const GShortcut& shortcut, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> callback, GWidget* widget = nullptr) | 
					
						
							| 
									
										
										
										
											2019-03-02 10:04:49 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-04-20 21:56:56 +02:00
										 |  |  |         return adopt(*new GAction(text, shortcut, move(icon), move(callback), widget)); | 
					
						
							| 
									
										
										
										
											2019-03-02 10:04:49 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-02-12 14:09:48 +01:00
										 |  |  |     ~GAction(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-20 21:56:56 +02:00
										 |  |  |     GWidget* widget() { return m_widget.ptr(); } | 
					
						
							|  |  |  |     const GWidget* widget() const { return m_widget.ptr(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-12 14:09:48 +01:00
										 |  |  |     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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-26 21:09:56 +02:00
										 |  |  |     bool is_checkable() const { return m_checkable; } | 
					
						
							|  |  |  |     void set_checkable(bool checkable) { m_checkable = checkable; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-28 11:53:16 +02:00
										 |  |  |     bool is_checked() const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         ASSERT(is_checkable()); | 
					
						
							|  |  |  |         return m_checked; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-26 21:09:56 +02:00
										 |  |  |     void set_checked(bool); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-12 02:53:27 +02:00
										 |  |  |     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-05-10 20:26:55 +02:00
										 |  |  |     GAction(const String& text, Function<void(GAction&)> = nullptr, GWidget* = nullptr); | 
					
						
							|  |  |  |     GAction(const String& text, const GShortcut&, Function<void(GAction&)> = nullptr, GWidget* = nullptr); | 
					
						
							|  |  |  |     GAction(const String& text, const GShortcut&, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> = nullptr, GWidget* = nullptr); | 
					
						
							|  |  |  |     GAction(const String& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(GAction&)> = nullptr, GWidget* = nullptr); | 
					
						
							|  |  |  |     GAction(const String& text, const String& custom_data = String(), Function<void(GAction&)> = nullptr, GWidget* = nullptr); | 
					
						
							| 
									
										
										
										
											2019-02-20 02:39:46 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-28 11:53:16 +02:00
										 |  |  |     template<typename Callback> | 
					
						
							|  |  |  |     void for_each_toolbar_button(Callback); | 
					
						
							|  |  |  |     template<typename Callback> | 
					
						
							|  |  |  |     void for_each_menu_item(Callback); | 
					
						
							| 
									
										
										
										
											2019-04-12 02:53:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 }; | 
					
						
							| 
									
										
										
										
											2019-04-26 21:09:56 +02:00
										 |  |  |     bool m_checkable { false }; | 
					
						
							|  |  |  |     bool m_checked { false }; | 
					
						
							| 
									
										
										
										
											2019-04-20 21:56:56 +02:00
										 |  |  |     ShortcutScope m_scope { ShortcutScope::None }; | 
					
						
							| 
									
										
										
										
											2019-04-12 02:53:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     HashTable<GButton*> m_buttons; | 
					
						
							|  |  |  |     HashTable<GMenuItem*> m_menu_items; | 
					
						
							| 
									
										
										
										
											2019-04-20 21:56:56 +02:00
										 |  |  |     WeakPtr<GWidget> m_widget; | 
					
						
							| 
									
										
										
										
											2019-02-12 14:09:48 +01:00
										 |  |  | }; |