diff options
Diffstat (limited to 'Libraries/LibGUI')
-rw-r--r-- | Libraries/LibGUI/GAction.cpp | 34 | ||||
-rw-r--r-- | Libraries/LibGUI/GAction.h | 14 |
2 files changed, 45 insertions, 3 deletions
diff --git a/Libraries/LibGUI/GAction.cpp b/Libraries/LibGUI/GAction.cpp index b655c67f58..40228d9ba5 100644 --- a/Libraries/LibGUI/GAction.cpp +++ b/Libraries/LibGUI/GAction.cpp @@ -4,6 +4,40 @@ #include <LibGUI/GButton.h> #include <LibGUI/GMenuItem.h> +NonnullRefPtr<GAction> GCommonActions::make_cut_action(Function<void()> callback, GWidget* widget) +{ + return GAction::create( + "Cut", { Mod_Ctrl, Key_X }, GraphicsBitmap::load_from_file("/res/icons/cut16.png"), [callback = move(callback)](const GAction&) { + callback(); + }, + widget); +} + +NonnullRefPtr<GAction> GCommonActions::make_copy_action(Function<void()> callback, GWidget* widget) +{ + return GAction::create( + "Copy", { Mod_Ctrl, Key_C }, GraphicsBitmap::load_from_file("/res/icons/16x16/edit-copy.png"), [callback = move(callback)](const GAction&) { + callback(); + }, + widget); +} + +NonnullRefPtr<GAction> GCommonActions::make_paste_action(Function<void()> callback, GWidget* widget) +{ + return GAction::create( + "Paste", { Mod_Ctrl, Key_V }, GraphicsBitmap::load_from_file("/res/icons/paste16.png"), [callback = move(callback)](const GAction&) { + callback(); + }, + widget); +} + +NonnullRefPtr<GAction> GCommonActions::make_quit_action(Function<void()> callback) +{ + return GAction::create("Quit", { Mod_Alt, Key_F4 }, [callback = move(callback)](const GAction&) { + callback(); + }); +} + GAction::GAction(const StringView& text, Function<void(GAction&)> on_activation_callback, GWidget* widget) : on_activation(move(on_activation_callback)) , m_text(text) diff --git a/Libraries/LibGUI/GAction.h b/Libraries/LibGUI/GAction.h index c294d65de9..08be487d39 100644 --- a/Libraries/LibGUI/GAction.h +++ b/Libraries/LibGUI/GAction.h @@ -4,18 +4,27 @@ #include <AK/Badge.h> #include <AK/Function.h> #include <AK/HashTable.h> -#include <AK/RefCounted.h> #include <AK/NonnullRefPtr.h> +#include <AK/RefCounted.h> #include <AK/WeakPtr.h> #include <AK/Weakable.h> -#include <LibGUI/GShortcut.h> #include <LibDraw/GraphicsBitmap.h> +#include <LibGUI/GShortcut.h> +#include <LibGUI/GWindow.h> +class GAction; class GActionGroup; class GButton; class GMenuItem; class GWidget; +namespace GCommonActions { +NonnullRefPtr<GAction> make_cut_action(Function<void()>, GWidget* widget); +NonnullRefPtr<GAction> make_copy_action(Function<void()>, GWidget* widget); +NonnullRefPtr<GAction> make_paste_action(Function<void()>, GWidget* widget); +NonnullRefPtr<GAction> make_quit_action(Function<void()>); +}; + class GAction : public RefCounted<GAction> , public Weakable<GAction> { public: @@ -41,7 +50,6 @@ public: return adopt(*new GAction(text, shortcut, move(icon), move(callback), widget)); } ~GAction(); - GWidget* widget() { return m_widget.ptr(); } const GWidget* widget() const { return m_widget.ptr(); } |