summaryrefslogtreecommitdiff
path: root/LibGUI/GAction.h
blob: 305abc59e38587c444e3d4c53cef616b17832208 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once

#include <AK/AKString.h>
#include <AK/Function.h>
#include <AK/Retainable.h>
#include <AK/Retained.h>
#include <SharedGraphics/GraphicsBitmap.h>

class GAction : public Retainable<GAction> {
public:
    static Retained<GAction> create(const String& text, Function<void(const GAction&)> callback)
    {
        return adopt(*new GAction(text, move(callback)));
    }
    static Retained<GAction> create(const String& text, const String& custom_data, Function<void(const GAction&)> callback)
    {
        return adopt(*new GAction(text, custom_data, move(callback)));
    }
    static Retained<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;
};