summaryrefslogtreecommitdiff
path: root/Libraries/LibGUI/GAction.cpp
diff options
context:
space:
mode:
authorrhin123 <ryanrhin@gmail.com>2019-09-01 15:28:07 -0500
committerAndreas Kling <awesomekling@gmail.com>2019-09-04 06:56:29 +0200
commitdeb31645aa25db3cfd6b490a76ff7fdc900602ba (patch)
tree6d904110ac5739f799bf5a0bf4d25ef8d76ba294 /Libraries/LibGUI/GAction.cpp
parent6126edcd75d9594eab08b2beb038c5eeb4a28585 (diff)
downloadserenity-deb31645aa25db3cfd6b490a76ff7fdc900602ba.zip
GAction: Added GCommonActions as a template to create standard actions
Instead of creating actions from the ground up, GCommonActions contains all related information to that common action. Such as the icon, keybind, ect.
Diffstat (limited to 'Libraries/LibGUI/GAction.cpp')
-rw-r--r--Libraries/LibGUI/GAction.cpp34
1 files changed, 34 insertions, 0 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)