Remove go_back() and go_forward() from WebView.

If we use these in commands.py, we spawn a new window before checking if we can
go back/forward - but we want to check that before opening a new window.
This commit is contained in:
Florian Bruhin 2014-10-06 19:47:35 +02:00
parent d2abd06513
commit 796dce86ae
2 changed files with 18 additions and 24 deletions

View File

@ -328,15 +328,21 @@ class CommandDispatcher:
def _back_forward(self, tab, bg, window, count, forward):
"""Helper function for :back/:forward."""
if (not forward and not
self._current_widget().page().history().canGoBack()):
raise cmdexc.CommandError("At beginning of history.")
if (forward and not
self._current_widget().page().history().canGoForward()):
raise cmdexc.CommandError("At end of history.")
if tab or bg or window:
widget = self.tab_clone(bg, window)
else:
widget = self._current_widget()
for _ in range(count):
if forward:
widget.go_forward()
widget.forward()
else:
widget.go_back()
widget.back()
@cmdutils.register(instance='command-dispatcher', scope='window')
def back(self, tab=False, bg=False, window=False, count=1):

View File

@ -154,16 +154,18 @@ class WebView(QWebView):
"""
if e.button() == Qt.XButton1:
# Back button on mice which have it.
try:
self.go_back()
except cmdexc.CommandError as ex:
message.error(self._win_id, ex, immediately=True)
if self.page().history().canGoBack():
self.back()
else:
message.error(self._win_id, "At beginning of history.",
immediately=True)
elif e.button() == Qt.XButton2:
# Forward button on mice which have it.
try:
self.go_forward()
except cmdexc.CommandError as ex:
message.error(self._win_id, ex, immediately=True)
if self.page().history().canGoForward():
self.forward()
else:
message.error(self._win_id, "At end of history.",
immediately=True)
def _mousepress_insertmode(self, e):
"""Switch to insert mode when an editable element was clicked.
@ -312,20 +314,6 @@ class WebView(QWebView):
level = self._zoom.getitem(offset)
self.zoom_perc(level, fuzzyval=False)
def go_back(self):
"""Go back a page in the history."""
if self.page().history().canGoBack():
self.back()
else:
raise cmdexc.CommandError("At beginning of history.")
def go_forward(self):
"""Go forward a page in the history."""
if self.page().history().canGoForward():
self.forward()
else:
raise cmdexc.CommandError("At end of history.")
@pyqtSlot('QUrl')
def on_url_changed(self, url):
"""Update cur_url when URL has changed."""