mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:07:34 +00:00
LibGUI: Share code for finding an Action by Shortcut
This moves logic for finding a shortcut on a Window or Widget to Action::find_action_for_shortcut instead.
This commit is contained in:
parent
025c16a6f9
commit
8e7c7e0a2a
4 changed files with 17 additions and 18 deletions
|
@ -63,6 +63,19 @@ NonnullRefPtr<Action> Action::create_checkable(String text, Shortcut const& shor
|
|||
return adopt_ref(*new Action(move(text), shortcut, Shortcut {}, move(icon), move(callback), parent, true));
|
||||
}
|
||||
|
||||
RefPtr<Action> Action::find_action_for_shortcut(Core::Object& object, Shortcut const& shortcut)
|
||||
{
|
||||
RefPtr<Action> found_action = nullptr;
|
||||
object.for_each_child_of_type<Action>([&](auto& action) {
|
||||
if (action.shortcut() == shortcut || action.alternate_shortcut() == shortcut) {
|
||||
found_action = &action;
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
return found_action;
|
||||
}
|
||||
|
||||
Action::Action(String text, Function<void(Action&)> on_activation_callback, Core::Object* parent, bool checkable)
|
||||
: Action(move(text), Shortcut {}, Shortcut {}, nullptr, move(on_activation_callback), parent, checkable)
|
||||
{
|
||||
|
|
|
@ -76,6 +76,8 @@ public:
|
|||
static NonnullRefPtr<Action> create_checkable(String text, Shortcut const& shortcut, Function<void(Action&)> callback, Core::Object* parent = nullptr);
|
||||
static NonnullRefPtr<Action> create_checkable(String text, Shortcut const& shortcut, RefPtr<Gfx::Bitmap> icon, Function<void(Action&)> callback, Core::Object* parent = nullptr);
|
||||
|
||||
static RefPtr<Action> find_action_for_shortcut(Core::Object& object, Shortcut const& shortcut);
|
||||
|
||||
virtual ~Action() override;
|
||||
|
||||
String text() const { return m_text; }
|
||||
|
|
|
@ -957,15 +957,7 @@ bool Widget::is_backmost() const
|
|||
|
||||
Action* Widget::action_for_shortcut(Shortcut const& shortcut)
|
||||
{
|
||||
Action* found_action = nullptr;
|
||||
for_each_child_of_type<Action>([&](auto& action) {
|
||||
if (action.shortcut() == shortcut || action.alternate_shortcut() == shortcut) {
|
||||
found_action = &action;
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
return found_action;
|
||||
return Action::find_action_for_shortcut(*this, shortcut);
|
||||
}
|
||||
|
||||
void Widget::set_updates_enabled(bool enabled)
|
||||
|
|
|
@ -1131,15 +1131,7 @@ void Window::notify_input_preempted(Badge<ConnectionToWindowServer>, InputPreemp
|
|||
|
||||
Action* Window::action_for_shortcut(Shortcut const& shortcut)
|
||||
{
|
||||
Action* found_action = nullptr;
|
||||
for_each_child_of_type<Action>([&](auto& action) {
|
||||
if (action.shortcut() == shortcut || action.alternate_shortcut() == shortcut) {
|
||||
found_action = &action;
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
return found_action;
|
||||
return Action::find_action_for_shortcut(*this, shortcut);
|
||||
}
|
||||
|
||||
void Window::set_base_size(Gfx::IntSize const& base_size)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue