Fix :view-source
This commit is contained in:
parent
04ee021bdb
commit
822e193682
@ -1210,19 +1210,21 @@ class CommandDispatcher:
|
||||
"""Show the source of the current page."""
|
||||
# pylint: disable=no-member
|
||||
# WORKAROUND for https://bitbucket.org/logilab/pylint/issue/491/
|
||||
widget = self._current_widget()
|
||||
if widget.viewing_source:
|
||||
tab = self._current_widget()
|
||||
if tab.data.viewing_source:
|
||||
raise cmdexc.CommandError("Already viewing source!")
|
||||
frame = widget.page().currentFrame()
|
||||
html = frame.toHtml()
|
||||
lexer = pygments.lexers.HtmlLexer()
|
||||
formatter = pygments.formatters.HtmlFormatter(full=True,
|
||||
linenos='table')
|
||||
highlighted = pygments.highlight(html, lexer, formatter)
|
||||
current_url = self._current_url()
|
||||
tab = self._tabbed_browser.tabopen(explicit=True)
|
||||
tab.setHtml(highlighted, current_url)
|
||||
tab.viewing_source = True
|
||||
|
||||
def show_source_cb(source):
|
||||
lexer = pygments.lexers.HtmlLexer()
|
||||
formatter = pygments.formatters.HtmlFormatter(full=True,
|
||||
linenos='table')
|
||||
highlighted = pygments.highlight(source, lexer, formatter)
|
||||
current_url = self._current_url()
|
||||
new_tab = self._tabbed_browser.tabopen(explicit=True)
|
||||
new_tab.set_html(highlighted, current_url)
|
||||
new_tab.data.viewing_source = True
|
||||
|
||||
tab.dump_async(show_source_cb)
|
||||
|
||||
@cmdutils.register(instance='command-dispatcher', scope='window',
|
||||
debug=True)
|
||||
|
@ -73,7 +73,10 @@ class TabData(QObject):
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self._data = {'keep_icon': False}
|
||||
self._data = {
|
||||
'keep_icon': False,
|
||||
'viewing_source': False,
|
||||
}
|
||||
|
||||
def __getattr__(self, attr):
|
||||
if attr.startswith('_'):
|
||||
@ -459,6 +462,11 @@ class AbstractTab(QWidget):
|
||||
widget.setParent(self)
|
||||
self.setFocusProxy(widget)
|
||||
|
||||
@pyqtSlot()
|
||||
def _on_load_started(self):
|
||||
self.data.viewing_source = False
|
||||
self.load_started.emit()
|
||||
|
||||
@property
|
||||
def cur_url(self):
|
||||
raise NotImplementedError
|
||||
|
@ -172,7 +172,7 @@ class WebEngineViewTab(tab.AbstractTab):
|
||||
page.windowCloseRequested.connect(self.window_close_requested)
|
||||
page.linkHovered.connect(self.link_hovered)
|
||||
page.loadProgress.connect(self.load_progress)
|
||||
page.loadStarted.connect(self.load_started)
|
||||
page.loadStarted.connect(self._on_load_started)
|
||||
view.titleChanged.connect(self.title_changed)
|
||||
page.loadFinished.connect(self.load_finished)
|
||||
# FIXME:refactor
|
||||
|
@ -512,7 +512,7 @@ class WebViewTab(tab.AbstractTab):
|
||||
page.windowCloseRequested.connect(self.window_close_requested)
|
||||
page.linkHovered.connect(self.link_hovered)
|
||||
page.loadProgress.connect(self.load_progress)
|
||||
frame.loadStarted.connect(self.load_started)
|
||||
frame.loadStarted.connect(self._on_load_started)
|
||||
view.scroll_pos_changed.connect(self.scroll.perc_changed)
|
||||
view.titleChanged.connect(self.title_changed)
|
||||
view.url_text_changed.connect(self.url_text_changed)
|
||||
|
@ -50,8 +50,6 @@ class WebView(QWebView):
|
||||
statusbar_message: The current javascript statusbar message.
|
||||
inspector: The QWebInspector used for this webview.
|
||||
load_status: loading status of this page (index into LoadStatus)
|
||||
viewing_source: Whether the webview is currently displaying source
|
||||
code.
|
||||
registry: The ObjectRegistry associated with this tab.
|
||||
win_id: The window ID of the view.
|
||||
_tab_id: The tab ID of the view.
|
||||
@ -118,7 +116,6 @@ class WebView(QWebView):
|
||||
window=win_id)
|
||||
mode_manager.entered.connect(self.on_mode_entered)
|
||||
mode_manager.left.connect(self.on_mode_left)
|
||||
self.viewing_source = False
|
||||
if config.get('input', 'rocker-gestures'):
|
||||
self.setContextMenuPolicy(Qt.PreventContextMenu)
|
||||
self.urlChanged.connect(self.on_url_changed)
|
||||
@ -370,7 +367,6 @@ class WebView(QWebView):
|
||||
def on_load_started(self):
|
||||
"""Leave insert/hint mode and set vars when a new page is loading."""
|
||||
self.progress = 0
|
||||
self.viewing_source = False
|
||||
self._has_ssl_errors = False
|
||||
self._set_load_status(usertypes.LoadStatus.loading)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user