Support back/forward mouse buttons
This commit is contained in:
parent
4b78e9a9f5
commit
d9bb1e904f
@ -193,10 +193,7 @@ class CurCommandDispatcher(QObject):
|
||||
count: How many pages to go back.
|
||||
"""
|
||||
for _ in range(count):
|
||||
if self._tabs.currentWidget().page_.history().canGoBack():
|
||||
self._tabs.currentWidget().back()
|
||||
else:
|
||||
message.error("At beginning of history.")
|
||||
if not self._tabs.currentWidget().go_back():
|
||||
break
|
||||
|
||||
@cmdutils.register(instance='mainwindow.tabs.cur')
|
||||
@ -209,10 +206,7 @@ class CurCommandDispatcher(QObject):
|
||||
count: How many pages to go forward.
|
||||
"""
|
||||
for _ in range(count):
|
||||
if self._tabs.currentWidget().page_.history().canGoForward():
|
||||
self._tabs.currentWidget().forward()
|
||||
else:
|
||||
message.error("At end of history.")
|
||||
if not self._tabs.currentWidget().go_forward():
|
||||
break
|
||||
|
||||
@cmdutils.register(instance='mainwindow.tabs.cur')
|
||||
|
@ -194,6 +194,32 @@ 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.
|
||||
|
||||
Return:
|
||||
True if going back succeeded, False otherwise.
|
||||
"""
|
||||
if self.page_.history().canGoBack():
|
||||
self.back()
|
||||
return True
|
||||
else:
|
||||
message.error("At beginning of history.")
|
||||
return False
|
||||
|
||||
def go_forward(self):
|
||||
"""Go forward a page in the history.
|
||||
|
||||
Return:
|
||||
True if going forward succeeded, False otherwise.
|
||||
"""
|
||||
if self.page_.history().canGoForward():
|
||||
self.forward()
|
||||
return True
|
||||
else:
|
||||
message.error("At end of history.")
|
||||
return False
|
||||
|
||||
def shutdown(self, callback=None):
|
||||
"""Shut down the tab cleanly and remove it.
|
||||
|
||||
@ -352,6 +378,14 @@ class WebView(QWebView):
|
||||
Return:
|
||||
The superclass return value.
|
||||
"""
|
||||
if e.button() == Qt.XButton1:
|
||||
# Back button on mice which have it.
|
||||
self.go_back()
|
||||
return super().mousePressEvent(e)
|
||||
elif e.button() == Qt.XButton2:
|
||||
# Forward button on mice which have it.
|
||||
self.go_forward()
|
||||
return super().mousePressEvent(e)
|
||||
pos = e.pos()
|
||||
frame = self.page_.frameAt(pos)
|
||||
if frame is None:
|
||||
|
Loading…
Reference in New Issue
Block a user