From c5366521ebafe016cb4e78300c41db1ed018a15b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 27 Jul 2018 17:43:54 +0530 Subject: [PATCH] Context menu works --- src/calibre/gui2/tweak_book/preview.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/calibre/gui2/tweak_book/preview.py b/src/calibre/gui2/tweak_book/preview.py index 9dda18dc76..26fa1a987e 100644 --- a/src/calibre/gui2/tweak_book/preview.py +++ b/src/calibre/gui2/tweak_book/preview.py @@ -8,7 +8,6 @@ from __future__ import absolute_import, division, print_function, unicode_litera # live css # 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 the context menu # check syncing of position back and forth # check all buttons in preview panel # rewrite JS from coffeescript to rapydscript @@ -398,17 +397,18 @@ class WebView(QWebEngineView): def contextMenuEvent(self, ev): menu = QMenu(self) - p = self._page - mf = p.mainFrame() - r = mf.hitTestContent(ev.pos()) - url = unicode_type(r.linkUrl().toString(NO_URL_FORMATTING)).strip() - ca = self.pageAction(QWebEnginePage.Copy) - if ca.isEnabled(): - menu.addAction(ca) + data = self._page.contextMenuData() + url = data.linkUrl() + url = unicode_type(url.toString(NO_URL_FORMATTING)).strip() + text = data.selectedText() + if text: + ca = self.pageAction(QWebEnginePage.Copy) + if ca.isEnabled(): + menu.addAction(ca) menu.addAction(actions['reload-preview']) menu.addAction(QIcon(I('debug.png')), _('Inspect element'), self.inspect) 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())