diff --git a/src/librssguard/gui/messagetextbrowser.cpp b/src/librssguard/gui/messagetextbrowser.cpp index 9a5de1009..e4e64183d 100644 --- a/src/librssguard/gui/messagetextbrowser.cpp +++ b/src/librssguard/gui/messagetextbrowser.cpp @@ -3,9 +3,13 @@ #include "gui/messagetextbrowser.h" #include "miscellaneous/application.h" +#include "miscellaneous/externaltool.h" #include "miscellaneous/iconfactory.h" #include "network-web/networkfactory.h" +#include +#include + MessageTextBrowser::MessageTextBrowser(QWidget* parent) : QTextBrowser(parent) { setAutoFillBackground(true); setFrameShape(QFrame::StyledPanel); @@ -44,6 +48,50 @@ QSize MessageTextBrowser::sizeHint() const { return doc_size; } +void MessageTextBrowser::contextMenuEvent(QContextMenuEvent* event) { + event->accept(); + + auto* menu = createStandardContextMenu(); + + if (menu == nullptr) { + return; + } + + auto anchor = anchorAt(event->pos()); + + if (!anchor.isEmpty()) { + QFileIconProvider icon_provider; + QMenu* menu_ext_tools = new QMenu(tr("Open with external tool"), menu); + auto tools = ExternalTool::toolsFromSettings(); + + menu_ext_tools->setIcon(qApp->icons()->fromTheme(QSL("document-open"))); + + for (const ExternalTool& tool : qAsConst(tools)) { + QAction* act_tool = new QAction(QFileInfo(tool.executable()).fileName(), menu_ext_tools); + + act_tool->setIcon(icon_provider.icon(tool.executable())); + act_tool->setToolTip(tool.executable()); + act_tool->setData(QVariant::fromValue(tool)); + menu_ext_tools->addAction(act_tool); + + connect(act_tool, &QAction::triggered, this, [act_tool, anchor]() { + act_tool->data().value().run(anchor); + }); + } + + if (menu_ext_tools->actions().isEmpty()) { + QAction* act_not_tools = new QAction("No external tools activated"); + + act_not_tools->setEnabled(false); + menu_ext_tools->addAction(act_not_tools); + } + + menu->addMenu(menu_ext_tools); + } + + menu->popup(event->globalPos()); +} + void MessageTextBrowser::wheelEvent(QWheelEvent* event) { QTextBrowser::wheelEvent(event); qApp->settings()->setValue(GROUP(Messages), Messages::PreviewerFontStandard, font().toString()); diff --git a/src/librssguard/gui/messagetextbrowser.h b/src/librssguard/gui/messagetextbrowser.h index a3b61cc61..9c4bcb574 100644 --- a/src/librssguard/gui/messagetextbrowser.h +++ b/src/librssguard/gui/messagetextbrowser.h @@ -18,6 +18,7 @@ class MessageTextBrowser : public QTextBrowser { virtual QSize sizeHint() const; protected: + virtual void contextMenuEvent(QContextMenuEvent* event); virtual void wheelEvent(QWheelEvent* event); virtual void resizeEvent (QResizeEvent* event);