diff options
Diffstat (limited to 'Userland/Libraries/LibGUI/LinkLabel.cpp')
-rw-r--r-- | Userland/Libraries/LibGUI/LinkLabel.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
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 <LibGUI/Action.h> +#include <LibGUI/Clipboard.h> #include <LibGUI/Event.h> #include <LibGUI/LinkLabel.h> +#include <LibGUI/Menu.h> #include <LibGUI/Painter.h> #include <LibGUI/Window.h> #include <LibGfx/Font.h> @@ -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); +} + } |