Skip to content

Commit 3ef7156

Browse files
authored
Merge pull request #1422 from Bad-ptr/copylink
Introduce "copy link" in context menu
2 parents 5c3392b + 052a3ae commit 3ef7156

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

resources/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
"ok":"ok",
115115
"no-filter":"no filter",
116116
"open-link-in-web-browser":"Open link in web browser",
117+
"copy-link":"Copy link",
117118
"open-link-new-tab":"Open link in new tab",
118119
"download-dir-dialog-title":"Are you sure you want to change the download directory?",
119120
"download-dir-dialog-msg":"The new download directory path will be:\n{{DIRECTORY}}",

src/webview.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class QMenu;
44

55
#include <QDesktopServices>
66
#include <QAction>
7+
#include <QClipboard>
78
#include <iostream>
89
#include "kiwixapp.h"
910
#include "webpage.h"
@@ -352,6 +353,13 @@ QMenu* WebView::createLinkContextMenu() {
352353
QMenu* menu = new QMenu(this);
353354

354355
if (!m_linkHovered.startsWith("zim://")) {
356+
auto copyLinkAction = new QAction(gt("copy-link"));
357+
menu->addAction(copyLinkAction);
358+
connect(menu, &QObject::destroyed, copyLinkAction, &QObject::deleteLater);
359+
connect(copyLinkAction, &QAction::triggered, this, [=](bool checked) {
360+
Q_UNUSED(checked);
361+
QApplication::clipboard()->setText(m_linkHovered);
362+
});
355363
auto openLinkInWebBrowserAction = new QAction(gt("open-link-in-web-browser"));
356364
menu->addAction(openLinkInWebBrowserAction);
357365
connect(menu, &QObject::destroyed, openLinkInWebBrowserAction, &QObject::deleteLater);

0 commit comments

Comments
 (0)