From 7252a1aa4d8896ef8104a4e76537eea5290404b9 Mon Sep 17 00:00:00 2001 From: thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> Date: Mon, 26 Sep 2022 08:40:49 -0400 Subject: [PATCH] LibGUI: Add fallible try_create_checkable() Action --- Userland/Libraries/LibGUI/Action.cpp | 5 +++++ Userland/Libraries/LibGUI/Action.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/Userland/Libraries/LibGUI/Action.cpp b/Userland/Libraries/LibGUI/Action.cpp index 5408c02ac0..4b55731e25 100644 --- a/Userland/Libraries/LibGUI/Action.cpp +++ b/Userland/Libraries/LibGUI/Action.cpp @@ -63,6 +63,11 @@ NonnullRefPtr Action::create_checkable(String text, Shortcut const& shor return adopt_ref(*new Action(move(text), shortcut, Shortcut {}, move(icon), move(callback), parent, true)); } +ErrorOr> Action::try_create_checkable(String text, Shortcut const& shortcut, Function callback, Core::Object* parent) +{ + return adopt_nonnull_ref_or_enomem(new (nothrow) Action(move(text), shortcut, Shortcut {}, move(callback), parent, true)); +} + RefPtr Action::find_action_for_shortcut(Core::Object& object, Shortcut const& shortcut) { RefPtr found_action = nullptr; diff --git a/Userland/Libraries/LibGUI/Action.h b/Userland/Libraries/LibGUI/Action.h index efe0f1c5fe..1aa517fa09 100644 --- a/Userland/Libraries/LibGUI/Action.h +++ b/Userland/Libraries/LibGUI/Action.h @@ -76,6 +76,8 @@ public: static NonnullRefPtr create_checkable(String text, Shortcut const& shortcut, Function callback, Core::Object* parent = nullptr); static NonnullRefPtr create_checkable(String text, Shortcut const& shortcut, RefPtr icon, Function callback, Core::Object* parent = nullptr); + static ErrorOr> try_create_checkable(String text, Shortcut const& shortcut, Function callback, Core::Object* parent = nullptr); + static RefPtr find_action_for_shortcut(Core::Object& object, Shortcut const& shortcut); virtual ~Action() override;