From 28f74df2e6a2bf284866400d3df37437da2edf96 Mon Sep 17 00:00:00 2001 From: FalseHonesty Date: Mon, 18 May 2020 21:25:28 -0400 Subject: [PATCH] LibGUI: Add hook when a context menu is requested on a button --- Libraries/LibGUI/Button.cpp | 8 ++++++++ Libraries/LibGUI/Button.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/Libraries/LibGUI/Button.cpp b/Libraries/LibGUI/Button.cpp index f662c82de4d..7ff306890d3 100644 --- a/Libraries/LibGUI/Button.cpp +++ b/Libraries/LibGUI/Button.cpp @@ -101,6 +101,14 @@ void Button::click(unsigned modifiers) m_action->activate(this); } +void Button::context_menu_event(ContextMenuEvent& context_menu_event) +{ + if (!is_enabled()) + return; + if (on_context_menu_request) + on_context_menu_request(context_menu_event); +} + void Button::set_action(Action& action) { m_action = action.make_weak_ptr(); diff --git a/Libraries/LibGUI/Button.h b/Libraries/LibGUI/Button.h index e28972ca4bd..5ada722f3ae 100644 --- a/Libraries/LibGUI/Button.h +++ b/Libraries/LibGUI/Button.h @@ -48,11 +48,13 @@ public: Gfx::TextAlignment text_alignment() const { return m_text_alignment; } Function on_click; + Function on_context_menu_request; void set_button_style(Gfx::ButtonStyle style) { m_button_style = style; } Gfx::ButtonStyle button_style() const { return m_button_style; } virtual void click(unsigned modifiers = 0) override; + virtual void context_menu_event(ContextMenuEvent&) override; void set_action(Action&);