MCPcopy Create free account
hub / github.com/KDE/falkon / populateWebViewMenu

Method populateWebViewMenu

src/plugins/GreaseMonkey/gm_plugin.cpp:71–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71void GM_Plugin::populateWebViewMenu(QMenu* menu, WebView* view, const WebHitTestResult& r)
72{
73 Q_UNUSED(r)
74
75 if (!m_manager->isEnabled()) {
76 return;
77 }
78
79 if (m_manager->contextMenuScripts().isEmpty()) {
80 return;
81 }
82
83 const QUrl url = view->url();
84 QList<GM_Script*> matchingScripts;
85
86 auto contextMenuScripts = m_manager->contextMenuScripts();
87 for (const auto &script : std::as_const(contextMenuScripts)) {
88 if (script->match(url)) {
89 matchingScripts.append(script);
90 }
91 }
92
93 if (matchingScripts.isEmpty()) {
94 return;
95 }
96
97 auto* gmMenu = new QMenu(tr("GreaseMonkey"));
98 gmMenu->setIcon(QIcon(QSL(":gm/data/icon.svg")));
99
100 for (const auto &script : std::as_const(matchingScripts)) {
101 gmMenu->addAction(script->icon(), script->name(), this, [script, view]() {
102 view->page()->execJavaScript(script->webScript().sourceCode(), WebPage::SafeJsWorld);
103 });
104 }
105
106 menu->addMenu(gmMenu);
107}
108
109bool GM_Plugin::acceptNavigationRequest(WebPage *page, const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame)
110{

Callers

nothing calls this directly

Calls 14

contextMenuScriptsMethod · 0.80
addActionMethod · 0.80
sourceCodeMethod · 0.80
webScriptMethod · 0.80
addMenuMethod · 0.80
QIconClass · 0.50
isEnabledMethod · 0.45
urlMethod · 0.45
matchMethod · 0.45
setIconMethod · 0.45
iconMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected