Move back/forward logic to AbstractHistory, fix method names
This commit is contained in:
parent
bf074d14de
commit
6ab49fdf1d
@ -466,10 +466,20 @@ class AbstractHistory:
|
||||
raise NotImplementedError
|
||||
|
||||
def back(self, count):
|
||||
raise NotImplementedError
|
||||
idx = self.current_idx() - count
|
||||
if idx >= 0:
|
||||
self._go_to_item(self._item_at(idx))
|
||||
else:
|
||||
self._go_to_item(self._item_at(0))
|
||||
raise WebTabError("At beginning of history.")
|
||||
|
||||
def forward(self, count):
|
||||
raise NotImplementedError
|
||||
idx = self.current_idx() + count
|
||||
if idx < len(self):
|
||||
self._go_to_item(self._item_at(idx))
|
||||
else:
|
||||
self._go_to_item(self._item_at(len(self) - 1))
|
||||
raise WebTabError("At end of history.")
|
||||
|
||||
def can_go_back(self):
|
||||
raise NotImplementedError
|
||||
@ -477,10 +487,10 @@ class AbstractHistory:
|
||||
def can_go_forward(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def itemAt(self, i):
|
||||
def _item_at(self, i):
|
||||
raise NotImplementedError
|
||||
|
||||
def goToItem(self, item):
|
||||
def _go_to_item(self, item):
|
||||
raise NotImplementedError
|
||||
|
||||
def serialize(self):
|
||||
|
@ -543,13 +543,13 @@ class CommandDispatcher:
|
||||
if forward:
|
||||
try:
|
||||
widget.history.forward(count)
|
||||
except IndexError:
|
||||
raise cmdexc.CommandError("At end of history.")
|
||||
except browsertab.WebTabError as e:
|
||||
raise cmdexc.CommandError(e)
|
||||
else:
|
||||
try:
|
||||
widget.history.back(count)
|
||||
except IndexError:
|
||||
raise cmdexc.CommandError("At beginning of history.")
|
||||
except browsertab.WebTabError as e:
|
||||
raise cmdexc.CommandError(e)
|
||||
|
||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||
@cmdutils.argument('count', count=True)
|
||||
|
@ -411,32 +411,16 @@ class WebEngineHistory(browsertab.AbstractHistory):
|
||||
def current_idx(self):
|
||||
return self._history.currentItemIndex()
|
||||
|
||||
def back(self, count):
|
||||
idx = self.current_idx() - count
|
||||
if idx >= 0:
|
||||
self.goToItem(self.itemAt(idx))
|
||||
else:
|
||||
self.goToItem(self.itemAt(0))
|
||||
raise IndexError
|
||||
|
||||
def forward(self, count):
|
||||
idx = self.current_idx() + count
|
||||
if idx < len(self):
|
||||
self.goToItem(self.itemAt(idx))
|
||||
else:
|
||||
self.goToItem(self.itemAt(len(self) - 1))
|
||||
raise IndexError
|
||||
|
||||
def can_go_back(self):
|
||||
return self._history.canGoBack()
|
||||
|
||||
def can_go_forward(self):
|
||||
return self._history.canGoForward()
|
||||
|
||||
def itemAt(self, i):
|
||||
def _item_at(self, i):
|
||||
return self._history.itemAt(i)
|
||||
|
||||
def goToItem(self, item):
|
||||
def _go_to_item(self, item):
|
||||
return self._history.goToItem(item)
|
||||
|
||||
def serialize(self):
|
||||
|
@ -506,32 +506,16 @@ class WebKitHistory(browsertab.AbstractHistory):
|
||||
def current_idx(self):
|
||||
return self._history.currentItemIndex()
|
||||
|
||||
def back(self, count):
|
||||
idx = self.current_idx() - count
|
||||
if idx >= 0:
|
||||
self.goToItem(self.itemAt(idx))
|
||||
else:
|
||||
self.goToItem(self.itemAt(0))
|
||||
raise IndexError
|
||||
|
||||
def forward(self, count):
|
||||
idx = self.current_idx() + count
|
||||
if idx < len(self):
|
||||
self.goToItem(self.itemAt(idx))
|
||||
else:
|
||||
self.goToItem(self.itemAt(len(self) - 1))
|
||||
raise IndexError
|
||||
|
||||
def can_go_back(self):
|
||||
return self._history.canGoBack()
|
||||
|
||||
def can_go_forward(self):
|
||||
return self._history.canGoForward()
|
||||
|
||||
def itemAt(self, i):
|
||||
def _item_at(self, i):
|
||||
return self._history.itemAt(i)
|
||||
|
||||
def goToItem(self, item):
|
||||
def _go_to_item(self, item):
|
||||
return self._history.goToItem(item)
|
||||
|
||||
def serialize(self):
|
||||
|
Loading…
Reference in New Issue
Block a user