summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI/LinkLabel.cpp
diff options
context:
space:
mode:
authorMițca Dumitru <dumitru0mitca@gmail.com>2021-02-22 00:06:38 +0200
committerAndreas Kling <kling@serenityos.org>2021-02-21 23:47:05 +0100
commit8d6525fc50879d1b8db3fb5da799db1a3e217ed9 (patch)
treee431d92b744d578237bb26a4638905a613959862 /Userland/Libraries/LibGUI/LinkLabel.cpp
parent8d2d0809235dc7ed34afaf2b32ccc3755ce8278b (diff)
downloadserenity-8d6525fc50879d1b8db3fb5da799db1a3e217ed9.zip
LibGUI: Show context menu when right-clicking a LinkLabel
Fixes #4794
Diffstat (limited to 'Userland/Libraries/LibGUI/LinkLabel.cpp')
-rw-r--r--Userland/Libraries/LibGUI/LinkLabel.cpp29
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);
+}
+
}