diff --git a/Userland/Libraries/LibGUI/LinkLabel.cpp b/Userland/Libraries/LibGUI/LinkLabel.cpp index db6dd09188..7ec2838c77 100644 --- a/Userland/Libraries/LibGUI/LinkLabel.cpp +++ b/Userland/Libraries/LibGUI/LinkLabel.cpp @@ -24,8 +24,11 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include +#include #include #include +#include #include #include #include @@ -41,10 +44,25 @@ LinkLabel::LinkLabel(String text) set_override_cursor(Gfx::StandardCursor::Hand); set_foreground_role(Gfx::ColorRole::Link); set_focus_policy(FocusPolicy::TabFocus); + setup_actions(); +} + +void LinkLabel::setup_actions() +{ + m_open_action = CommonActions::make_open_action([this](auto&) { + if (on_click) + on_click(); + }, + this); + + m_copy_action = CommonActions::make_copy_action([this](auto&) { Clipboard::the().set_plain_text(text()); }, this); } void LinkLabel::mousedown_event(MouseEvent& event) { + if (event.button() != MouseButton::Left) + return; + Label::mousedown_event(event); if (on_click) { on_click(); @@ -107,4 +125,15 @@ void LinkLabel::resize_event(ResizeEvent& event) update_tooltip_if_needed(); } +void LinkLabel::context_menu_event(ContextMenuEvent& event) +{ + if (!m_context_menu) { + m_context_menu = Menu::construct(); + m_context_menu->add_action(*m_open_action); + m_context_menu->add_separator(); + m_context_menu->add_action(*m_copy_action); + } + m_context_menu->popup(event.screen_position(), m_open_action); +} + } diff --git a/Userland/Libraries/LibGUI/LinkLabel.h b/Userland/Libraries/LibGUI/LinkLabel.h index b438bfe670..5364ea6960 100644 --- a/Userland/Libraries/LibGUI/LinkLabel.h +++ b/Userland/Libraries/LibGUI/LinkLabel.h @@ -45,10 +45,16 @@ private: virtual void enter_event(Core::Event&) override; virtual void leave_event(Core::Event&) override; virtual void keydown_event(KeyEvent&) override; + virtual void context_menu_event(ContextMenuEvent&) override; virtual void did_change_text() override; void update_tooltip_if_needed(); + void setup_actions(); + + RefPtr m_context_menu; + RefPtr m_open_action; + RefPtr m_copy_action; bool m_hovered { false }; };