Context menu works

This commit is contained in:
Kovid Goyal 2018-07-27 17:43:54 +05:30
parent fe25b8d8f6
commit c5366521eb
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -8,7 +8,6 @@ from __future__ import absolute_import, division, print_function, unicode_litera
# live css # live css
# check that clicking on both internal and external links works # check that clicking on both internal and external links works
# check if you can remove the restriction that prevents inspector dock from being undocked # check if you can remove the restriction that prevents inspector dock from being undocked
# check the context menu
# check syncing of position back and forth # check syncing of position back and forth
# check all buttons in preview panel # check all buttons in preview panel
# rewrite JS from coffeescript to rapydscript # rewrite JS from coffeescript to rapydscript
@ -398,17 +397,18 @@ class WebView(QWebEngineView):
def contextMenuEvent(self, ev): def contextMenuEvent(self, ev):
menu = QMenu(self) menu = QMenu(self)
p = self._page data = self._page.contextMenuData()
mf = p.mainFrame() url = data.linkUrl()
r = mf.hitTestContent(ev.pos()) url = unicode_type(url.toString(NO_URL_FORMATTING)).strip()
url = unicode_type(r.linkUrl().toString(NO_URL_FORMATTING)).strip() text = data.selectedText()
ca = self.pageAction(QWebEnginePage.Copy) if text:
if ca.isEnabled(): ca = self.pageAction(QWebEnginePage.Copy)
menu.addAction(ca) if ca.isEnabled():
menu.addAction(ca)
menu.addAction(actions['reload-preview']) menu.addAction(actions['reload-preview'])
menu.addAction(QIcon(I('debug.png')), _('Inspect element'), self.inspect) menu.addAction(QIcon(I('debug.png')), _('Inspect element'), self.inspect)
if url.partition(':')[0].lower() in {'http', 'https'}: if url.partition(':')[0].lower() in {'http', 'https'}:
menu.addAction(_('Open link'), partial(open_url, r.linkUrl())) menu.addAction(_('Open link'), partial(open_url, data.linkUrl()))
menu.exec_(ev.globalPos()) menu.exec_(ev.globalPos())