fix latest change requests

This commit is contained in:
Marc Jauvin 2018-01-25 13:35:23 -05:00
parent d7c51f7fc4
commit eb888cc8d7
6 changed files with 23 additions and 29 deletions

View File

@ -119,8 +119,10 @@ class AbstractAction:
action_class = None
action_base = None
def __init__(self):
def __init__(self, tab, win_id):
self._widget = None
self._tab = tab
self._win_id = win_id
def exit_fullscreen(self):
"""Exit the fullscreen mode."""
@ -137,7 +139,7 @@ class AbstractAction:
raise WebTabError("{} is not a valid web action!".format(name))
self._widget.triggerPageAction(member)
def show_source(self, win_id, url):
def show_source(self):
"""Show the source of the current page in a new tab."""
raise NotImplementedError

View File

@ -1509,7 +1509,7 @@ class CommandDispatcher:
if current_url.scheme() == 'view-source':
raise cmdexc.CommandError("Already viewing source!")
tab.action.show_source(self._win_id, current_url)
tab.action.show_source()
@cmdutils.register(instance='command-dispatcher', scope='window',
debug=True)

View File

@ -99,18 +99,16 @@ class WebEngineAction(browsertab.AbstractAction):
"""Save the current page."""
self._widget.triggerPageAction(QWebEnginePage.SavePage)
def show_source(self, win_id, url):
def show_source(self):
try:
self._widget.triggerPageAction(QWebEnginePage.ViewSource)
except AttributeError:
# Qt < 5.8
# note: it's not possible to build the QUrl object by setting the
# scheme using setScheme('view-source').
# QUrl does the right thing when URL prefix is "view-source:".
new_url = QUrl('view-source:' + url.toString())
tabbed_browser = objreg.get('tabbed-browser', scope='window',
window=win_id)
tabbed_browser.tabopen(new_url, background=False, related=True)
url_str = self._tab.url().toString(QUrl.RemoveUserInfo)
new_url = QUrl('view-source:' + url_str)
tb = objreg.get('tabbed-browser', scope='window',
window=self._win_id)
tb.tabopen(new_url, background=False, related=True)
class WebEnginePrinting(browsertab.AbstractPrinting):
@ -609,7 +607,7 @@ class WebEngineTab(browsertab.AbstractTab):
self.search = WebEngineSearch(parent=self)
self.printing = WebEnginePrinting()
self.elements = WebEngineElements(self)
self.action = WebEngineAction()
self.action = WebEngineAction(self, win_id)
self._set_widget(widget)
self._connect_signals()
self.backend = usertypes.Backend.QtWebEngine

View File

@ -54,14 +54,7 @@ class WebKitAction(browsertab.AbstractAction):
"""Save the current page."""
raise browsertab.UnsupportedOperationError
def show_source(self, win_id, url):
def format_url(url):
"""emulate what WebEnginePage::ViewSource does."""
s = url.toString()
s = s.split('//')[-1] # strip scheme
s = s.split('@')[-1] # strip userinfo
return s
def show_source(self):
def show_source_cb(source):
"""Show source as soon as it's ready."""
@ -70,17 +63,18 @@ class WebKitAction(browsertab.AbstractAction):
lexer = pygments.lexers.HtmlLexer()
formatter = pygments.formatters.HtmlFormatter(
full=True, linenos='table',
title='view-source:' + format_url(url))
title='Source for {}'.format(url_str))
# pylint: enable=no-member
highlighted = pygments.highlight(source, lexer, formatter)
base_url = QUrl('view-source:' + url.toString())
new_tab = tabbed_browser.tabopen(background=False, related=True)
base_url = QUrl('view-source:' + url_str)
tb = objreg.get('tabbed-browser', scope='window',
window=self._win_id)
new_tab = tb.tabopen(background=False, related=True)
new_tab.set_html(highlighted, base_url)
tabbed_browser = objreg.get('tabbed-browser', scope='window',
window=win_id)
tabbed_browser.currentWidget().dump_async(show_source_cb)
url_str = self._tab.url().toString(QUrl.RemoveUserInfo)
self._tab.dump_async(show_source_cb)
class WebKitPrinting(browsertab.AbstractPrinting):
@ -657,7 +651,7 @@ class WebKitTab(browsertab.AbstractTab):
self.search = WebKitSearch(parent=self)
self.printing = WebKitPrinting()
self.elements = WebKitElements(self)
self.action = WebKitAction()
self.action = WebKitAction(self, win_id)
self._set_widget(widget)
self._connect_signals()
self.backend = usertypes.Backend.QtWebKit

View File

@ -69,7 +69,7 @@ Feature: Page history
Scenario: History with view-source URL
When I open data/title.html
And I run :view-source
And I wait for "Changing title for idx * to 'view-source:http://localhost:*/data/title.html'" in the log
And I wait for regex "Changing title for idx \d+ to '(Source for |view-source:)(http://)?localhost:\d+/data/title.html'" in the log
Then the history should contain:
http://localhost:(port)/data/title.html Test title

View File

@ -87,7 +87,7 @@ class Tab(browsertab.AbstractTab):
self.search = browsertab.AbstractSearch(parent=self)
self.printing = browsertab.AbstractPrinting()
self.elements = browsertab.AbstractElements(self)
self.action = browsertab.AbstractAction()
self.action = browsertab.AbstractAction(self, self.win_id)
def _install_event_filter(self):
pass