summaryrefslogtreecommitdiff
path: root/LibGUI/GAction.h
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-02-20 02:39:46 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-02-20 02:39:46 +0100
commitb704d3d295dd364279546f7b04b89420fda39751 (patch)
tree4afdadfedf64ce82a1cfff65774fb502b0a7e9e0 /LibGUI/GAction.h
parent4804609b7e8e2488b28d68e5171a61cd7a5ea848 (diff)
downloadserenity-b704d3d295dd364279546f7b04b89420fda39751.zip
LibGUI: Add a GToolBar class that can be populated with GActions.
The same action can be added to both a menu and a toolbar. Use this to put a toolbar into FileManager. This is pretty neat. :^)
Diffstat (limited to 'LibGUI/GAction.h')
-rw-r--r--LibGUI/GAction.h25
1 files changed, 22 insertions, 3 deletions
diff --git a/LibGUI/GAction.h b/LibGUI/GAction.h
index 6e2bea0404..64797fedf7 100644
--- a/LibGUI/GAction.h
+++ b/LibGUI/GAction.h
@@ -2,22 +2,41 @@
#include <AK/AKString.h>
#include <AK/Function.h>
+#include <AK/Retainable.h>
+#include <AK/RetainPtr.h>
+#include <SharedGraphics/GraphicsBitmap.h>
-class GAction {
+class GAction : public Retainable<GAction> {
public:
- GAction(const String& text, Function<void(const GAction&)> = nullptr);
- GAction(const String& text, const String& custom_data = String(), Function<void(const GAction&)> = nullptr);
+ static RetainPtr<GAction> create(const String& text, Function<void(const GAction&)> callback)
+ {
+ return adopt(*new GAction(text, move(callback)));
+ }
+ static RetainPtr<GAction> create(const String& text, const String& custom_data, Function<void(const GAction&)> callback)
+ {
+ return adopt(*new GAction(text, custom_data, move(callback)));
+ }
+ static RetainPtr<GAction> create(const String& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(const GAction&)> callback)
+ {
+ return adopt(*new GAction(text, move(icon), move(callback)));
+ }
~GAction();
String text() const { return m_text; }
String custom_data() const { return m_custom_data; }
+ const GraphicsBitmap* icon() const { return m_icon.ptr(); }
Function<void(GAction&)> on_activation;
void activate();
private:
+ GAction(const String& text, Function<void(const GAction&)> = nullptr);
+ 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);
+
String m_text;
String m_custom_data;
+ RetainPtr<GraphicsBitmap> m_icon;
};