fix latest change requests
This commit is contained in:
parent
d7c51f7fc4
commit
eb888cc8d7
@ -119,8 +119,10 @@ class AbstractAction:
|
|||||||
action_class = None
|
action_class = None
|
||||||
action_base = None
|
action_base = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, tab, win_id):
|
||||||
self._widget = None
|
self._widget = None
|
||||||
|
self._tab = tab
|
||||||
|
self._win_id = win_id
|
||||||
|
|
||||||
def exit_fullscreen(self):
|
def exit_fullscreen(self):
|
||||||
"""Exit the fullscreen mode."""
|
"""Exit the fullscreen mode."""
|
||||||
@ -137,7 +139,7 @@ class AbstractAction:
|
|||||||
raise WebTabError("{} is not a valid web action!".format(name))
|
raise WebTabError("{} is not a valid web action!".format(name))
|
||||||
self._widget.triggerPageAction(member)
|
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."""
|
"""Show the source of the current page in a new tab."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@ -1509,7 +1509,7 @@ class CommandDispatcher:
|
|||||||
if current_url.scheme() == 'view-source':
|
if current_url.scheme() == 'view-source':
|
||||||
raise cmdexc.CommandError("Already viewing 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',
|
@cmdutils.register(instance='command-dispatcher', scope='window',
|
||||||
debug=True)
|
debug=True)
|
||||||
|
@ -99,18 +99,16 @@ class WebEngineAction(browsertab.AbstractAction):
|
|||||||
"""Save the current page."""
|
"""Save the current page."""
|
||||||
self._widget.triggerPageAction(QWebEnginePage.SavePage)
|
self._widget.triggerPageAction(QWebEnginePage.SavePage)
|
||||||
|
|
||||||
def show_source(self, win_id, url):
|
def show_source(self):
|
||||||
try:
|
try:
|
||||||
self._widget.triggerPageAction(QWebEnginePage.ViewSource)
|
self._widget.triggerPageAction(QWebEnginePage.ViewSource)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# Qt < 5.8
|
# Qt < 5.8
|
||||||
# note: it's not possible to build the QUrl object by setting the
|
url_str = self._tab.url().toString(QUrl.RemoveUserInfo)
|
||||||
# scheme using setScheme('view-source').
|
new_url = QUrl('view-source:' + url_str)
|
||||||
# QUrl does the right thing when URL prefix is "view-source:".
|
tb = objreg.get('tabbed-browser', scope='window',
|
||||||
new_url = QUrl('view-source:' + url.toString())
|
window=self._win_id)
|
||||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
tb.tabopen(new_url, background=False, related=True)
|
||||||
window=win_id)
|
|
||||||
tabbed_browser.tabopen(new_url, background=False, related=True)
|
|
||||||
|
|
||||||
|
|
||||||
class WebEnginePrinting(browsertab.AbstractPrinting):
|
class WebEnginePrinting(browsertab.AbstractPrinting):
|
||||||
@ -609,7 +607,7 @@ class WebEngineTab(browsertab.AbstractTab):
|
|||||||
self.search = WebEngineSearch(parent=self)
|
self.search = WebEngineSearch(parent=self)
|
||||||
self.printing = WebEnginePrinting()
|
self.printing = WebEnginePrinting()
|
||||||
self.elements = WebEngineElements(self)
|
self.elements = WebEngineElements(self)
|
||||||
self.action = WebEngineAction()
|
self.action = WebEngineAction(self, win_id)
|
||||||
self._set_widget(widget)
|
self._set_widget(widget)
|
||||||
self._connect_signals()
|
self._connect_signals()
|
||||||
self.backend = usertypes.Backend.QtWebEngine
|
self.backend = usertypes.Backend.QtWebEngine
|
||||||
|
@ -54,14 +54,7 @@ class WebKitAction(browsertab.AbstractAction):
|
|||||||
"""Save the current page."""
|
"""Save the current page."""
|
||||||
raise browsertab.UnsupportedOperationError
|
raise browsertab.UnsupportedOperationError
|
||||||
|
|
||||||
def show_source(self, win_id, url):
|
def show_source(self):
|
||||||
|
|
||||||
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_cb(source):
|
def show_source_cb(source):
|
||||||
"""Show source as soon as it's ready."""
|
"""Show source as soon as it's ready."""
|
||||||
@ -70,17 +63,18 @@ class WebKitAction(browsertab.AbstractAction):
|
|||||||
lexer = pygments.lexers.HtmlLexer()
|
lexer = pygments.lexers.HtmlLexer()
|
||||||
formatter = pygments.formatters.HtmlFormatter(
|
formatter = pygments.formatters.HtmlFormatter(
|
||||||
full=True, linenos='table',
|
full=True, linenos='table',
|
||||||
title='view-source:' + format_url(url))
|
title='Source for {}'.format(url_str))
|
||||||
# pylint: enable=no-member
|
# pylint: enable=no-member
|
||||||
highlighted = pygments.highlight(source, lexer, formatter)
|
highlighted = pygments.highlight(source, lexer, formatter)
|
||||||
|
|
||||||
base_url = QUrl('view-source:' + url.toString())
|
base_url = QUrl('view-source:' + url_str)
|
||||||
new_tab = tabbed_browser.tabopen(background=False, related=True)
|
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)
|
new_tab.set_html(highlighted, base_url)
|
||||||
|
|
||||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
url_str = self._tab.url().toString(QUrl.RemoveUserInfo)
|
||||||
window=win_id)
|
self._tab.dump_async(show_source_cb)
|
||||||
tabbed_browser.currentWidget().dump_async(show_source_cb)
|
|
||||||
|
|
||||||
|
|
||||||
class WebKitPrinting(browsertab.AbstractPrinting):
|
class WebKitPrinting(browsertab.AbstractPrinting):
|
||||||
@ -657,7 +651,7 @@ class WebKitTab(browsertab.AbstractTab):
|
|||||||
self.search = WebKitSearch(parent=self)
|
self.search = WebKitSearch(parent=self)
|
||||||
self.printing = WebKitPrinting()
|
self.printing = WebKitPrinting()
|
||||||
self.elements = WebKitElements(self)
|
self.elements = WebKitElements(self)
|
||||||
self.action = WebKitAction()
|
self.action = WebKitAction(self, win_id)
|
||||||
self._set_widget(widget)
|
self._set_widget(widget)
|
||||||
self._connect_signals()
|
self._connect_signals()
|
||||||
self.backend = usertypes.Backend.QtWebKit
|
self.backend = usertypes.Backend.QtWebKit
|
||||||
|
@ -69,7 +69,7 @@ Feature: Page history
|
|||||||
Scenario: History with view-source URL
|
Scenario: History with view-source URL
|
||||||
When I open data/title.html
|
When I open data/title.html
|
||||||
And I run :view-source
|
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:
|
Then the history should contain:
|
||||||
http://localhost:(port)/data/title.html Test title
|
http://localhost:(port)/data/title.html Test title
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ class Tab(browsertab.AbstractTab):
|
|||||||
self.search = browsertab.AbstractSearch(parent=self)
|
self.search = browsertab.AbstractSearch(parent=self)
|
||||||
self.printing = browsertab.AbstractPrinting()
|
self.printing = browsertab.AbstractPrinting()
|
||||||
self.elements = browsertab.AbstractElements(self)
|
self.elements = browsertab.AbstractElements(self)
|
||||||
self.action = browsertab.AbstractAction()
|
self.action = browsertab.AbstractAction(self, self.win_id)
|
||||||
|
|
||||||
def _install_event_filter(self):
|
def _install_event_filter(self):
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user