1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:37:35 +00:00

LibVT: Add "Open URL" and "Copy URL" to TerminalWidget context menu

These only show up when you right click a hyperlinked character cell.
This commit is contained in:
Andreas Kling 2020-05-09 16:42:42 +02:00
parent 7aa2acefd0
commit 27d1e7f432
2 changed files with 20 additions and 6 deletions

View file

@ -125,6 +125,21 @@ TerminalWidget::TerminalWidget(int ptm_fd, bool automatic_size_policy, RefPtr<Co
m_paste_action = GUI::Action::create("Paste", { Mod_Ctrl | Mod_Shift, Key_V }, Gfx::Bitmap::load_from_file("/res/icons/paste16.png"), [this](auto&) {
paste();
});
m_context_menu = GUI::Menu::construct();
m_context_menu->add_action(copy_action());
m_context_menu->add_action(paste_action());
m_context_menu_for_hyperlink = GUI::Menu::construct();
m_context_menu_for_hyperlink->add_action(GUI::Action::create("Open URL", [this](auto&) {
Desktop::Launcher::open(m_hovered_href);
}));
m_context_menu_for_hyperlink->add_action(GUI::Action::create("Copy URL", [this](auto&) {
GUI::Clipboard::the().set_data(m_hovered_href);
}));
m_context_menu_for_hyperlink->add_separator();
m_context_menu_for_hyperlink->add_action(copy_action());
m_context_menu_for_hyperlink->add_action(paste_action());
}
TerminalWidget::~TerminalWidget()
@ -743,12 +758,10 @@ void TerminalWidget::emit(const u8* data, size_t size)
void TerminalWidget::context_menu_event(GUI::ContextMenuEvent& event)
{
if (!m_context_menu) {
m_context_menu = GUI::Menu::construct();
m_context_menu->add_action(copy_action());
m_context_menu->add_action(paste_action());
}
m_context_menu->popup(event.screen_position());
if (m_hovered_href_id.is_null())
m_context_menu->popup(event.screen_position());
else
m_context_menu_for_hyperlink->popup(event.screen_position());
}
void TerminalWidget::drop_event(GUI::DropEvent& event)