Implement count everywhere
This commit is contained in:
parent
58103fa7e4
commit
85c44ed78c
@ -23,13 +23,14 @@ from qutebrowser.commands.template import Command
|
||||
|
||||
|
||||
class Open(Command):
|
||||
"""Open a page.
|
||||
"""Open a page in the current or [count]th tab.
|
||||
|
||||
arg: The URL to open.
|
||||
"""
|
||||
|
||||
nargs = 1
|
||||
split_args = False
|
||||
count = True
|
||||
|
||||
|
||||
class TabOpen(Command):
|
||||
@ -43,21 +44,21 @@ class TabOpen(Command):
|
||||
|
||||
|
||||
class TabClose(Command):
|
||||
"""Close the current tab."""
|
||||
"""Close the current tab, or tab [count]."""
|
||||
nargs = 0
|
||||
# FIXME also close [count]th tab
|
||||
count = True
|
||||
|
||||
|
||||
class TabNext(Command):
|
||||
"""Switch to the next tab."""
|
||||
"""Switch to the next tab, or skip [count] tabs."""
|
||||
nargs = 0
|
||||
# FIXME also support [count]
|
||||
count = True
|
||||
|
||||
|
||||
class TabPrev(Command):
|
||||
"""Switch to the previous tab."""
|
||||
"""Switch to the previous tab, or skip [count] tabs."""
|
||||
nargs = 0
|
||||
# FIXME also support [count]
|
||||
count = True
|
||||
|
||||
|
||||
class Quit(Command):
|
||||
@ -67,30 +68,33 @@ class Quit(Command):
|
||||
|
||||
|
||||
class Reload(Command):
|
||||
"""Reload the current page."""
|
||||
"""Reload the current page, or the page in tab [count]."""
|
||||
nargs = 0
|
||||
count = True
|
||||
|
||||
|
||||
class Stop(Command):
|
||||
"""Stop loading the current page."""
|
||||
"""Stop loading the current page, or the page in tab [count]."""
|
||||
nargs = 0
|
||||
count = True
|
||||
|
||||
|
||||
class Back(Command):
|
||||
"""Go back one page in the history."""
|
||||
"""Go back one/[count] page(s) in the history."""
|
||||
nargs = 0
|
||||
# FIXME also support [count]
|
||||
count = True
|
||||
|
||||
|
||||
class Forward(Command):
|
||||
"""Go forward one page in the history."""
|
||||
"""Go forward one/[count] page(s) in the history."""
|
||||
nargs = 0
|
||||
# FIXME also support [count]
|
||||
count = True
|
||||
|
||||
|
||||
class Print(Command):
|
||||
"""Print the current page."""
|
||||
"""Print the current page, or the page in tab [count]."""
|
||||
nargs = 0
|
||||
count = True
|
||||
|
||||
|
||||
class Scroll(Command):
|
||||
@ -148,10 +152,11 @@ class PyEval(Command):
|
||||
|
||||
|
||||
class NextSearch(Command):
|
||||
"""Jump to the next search term."""
|
||||
"""Jump to the next or [count]th next search term."""
|
||||
|
||||
nargs = 0
|
||||
hide = True
|
||||
count = True
|
||||
|
||||
|
||||
class Yank(Command):
|
||||
|
@ -61,10 +61,13 @@ class SearchParser(QObject):
|
||||
self.flags = QWebPage.FindBackward
|
||||
self.do_search.emit(self.text, self.flags)
|
||||
|
||||
def nextsearch(self):
|
||||
"""Continue the search to the next term."""
|
||||
def nextsearch(self, count=None):
|
||||
"""Continue the search to the ([count]th) next term."""
|
||||
if count is None:
|
||||
count = 1
|
||||
if self.text is not None:
|
||||
self.do_search.emit(self.text, self.flags)
|
||||
for i in range(count): # pylint: disable=unused-variable
|
||||
self.do_search.emit(self.text, self.flags)
|
||||
|
||||
|
||||
class CommandParser(QObject):
|
||||
|
@ -75,13 +75,15 @@ class TabbedBrowser(TabWidget):
|
||||
# FIXME sometimes this doesn't load
|
||||
tab.open_tab.connect(self.tabopen)
|
||||
|
||||
def openurl(self, url):
|
||||
"""Open an url in the current tab.
|
||||
def openurl(self, url, count=None):
|
||||
"""Open an url in the current/[count]th tab.
|
||||
|
||||
Command handler for :open.
|
||||
url -- The URL to open.
|
||||
"""
|
||||
self.currentWidget().openurl(url)
|
||||
tab = self._widget(count)
|
||||
if tab is not None:
|
||||
tab.openurl(url)
|
||||
|
||||
def undo_close(self):
|
||||
"""Undo closing a tab.
|
||||
@ -91,60 +93,75 @@ class TabbedBrowser(TabWidget):
|
||||
if self._url_stack:
|
||||
self.tabopen(self._url_stack.pop())
|
||||
|
||||
def cur_close(self):
|
||||
"""Close the current tab.
|
||||
def cur_close(self, count=None):
|
||||
"""Close the current/[count]th tab.
|
||||
|
||||
Command handler for :close.
|
||||
"""
|
||||
if self.count() > 1:
|
||||
idx = self.currentIndex()
|
||||
tab = self.currentWidget()
|
||||
# FIXME maybe we actually should store the webview objects here
|
||||
self._url_stack.append(tab.url())
|
||||
self.removeTab(idx)
|
||||
idx = self.currentIndex() if count is None else count - 1
|
||||
tab = self._widget(count)
|
||||
if tab is not None:
|
||||
# FIXME maybe we actually should store the webview objects here
|
||||
self._url_stack.append(tab.url())
|
||||
self.removeTab(idx)
|
||||
else:
|
||||
# FIXME
|
||||
pass
|
||||
|
||||
def cur_reload(self):
|
||||
"""Reload the current tab.
|
||||
def cur_reload(self, count=None):
|
||||
"""Reload the current/[count]th tab.
|
||||
|
||||
Command handler for :reload.
|
||||
"""
|
||||
self.currentWidget().reload()
|
||||
tab = self._widget(count)
|
||||
if tab is not None:
|
||||
tab.reload()
|
||||
|
||||
def cur_stop(self):
|
||||
"""Stop loading in the current tab.
|
||||
def cur_stop(self, count=None):
|
||||
"""Stop loading in the current/[count]th tab.
|
||||
|
||||
Command handler for :stop.
|
||||
"""
|
||||
self.currentWidget().stop()
|
||||
tab = self._widget(count)
|
||||
if tab is not None:
|
||||
tab.stop()
|
||||
|
||||
def cur_print(self):
|
||||
"""Print the current tab.
|
||||
def cur_print(self, count=None):
|
||||
"""Print the current/[count]th tab.
|
||||
|
||||
Command handler for :print.
|
||||
"""
|
||||
# FIXME that does not what I expect
|
||||
preview = QPrintPreviewDialog()
|
||||
preview.paintRequested.connect(self.currentWidget().print)
|
||||
preview.exec_()
|
||||
tab = self._widget(count)
|
||||
if tab is not None:
|
||||
preview = QPrintPreviewDialog()
|
||||
preview.paintRequested.connect(tab.print)
|
||||
preview.exec_()
|
||||
|
||||
def cur_back(self):
|
||||
def cur_back(self, count=None):
|
||||
"""Go back in the history of the current tab.
|
||||
|
||||
Go back for 1 page if count is unset, else go back [count] pages.
|
||||
Command handler for :back.
|
||||
"""
|
||||
# FIXME display warning if beginning of history
|
||||
self.currentWidget().back()
|
||||
if count is None:
|
||||
count = 1
|
||||
for i in range(count): # pylint: disable=unused-variable
|
||||
self.currentWidget().back()
|
||||
|
||||
def cur_forward(self):
|
||||
def cur_forward(self, count=None):
|
||||
"""Go forward in the history of the current tab.
|
||||
|
||||
Go forward for 1 page if count is unset, else go forward [count] pages.
|
||||
Command handler for :forward.
|
||||
"""
|
||||
# FIXME display warning if end of history
|
||||
self.currentWidget().forward()
|
||||
if count is None:
|
||||
count = 1
|
||||
for i in range(count): # pylint: disable=unused-variable
|
||||
self.currentWidget().forward()
|
||||
|
||||
def cur_search(self, text, flags):
|
||||
"""Search for text in the current page.
|
||||
@ -195,26 +212,30 @@ class TabbedBrowser(TabWidget):
|
||||
return
|
||||
frame.setScrollBarValue(orientation, int(m * perc / 100))
|
||||
|
||||
def switch_prev(self):
|
||||
"""Switch to the previous tab.
|
||||
def switch_prev(self, count=None):
|
||||
"""Switch to the ([count]th) previous tab.
|
||||
|
||||
Command handler for :tabprev.
|
||||
"""
|
||||
if count is None:
|
||||
count = 1
|
||||
idx = self.currentIndex()
|
||||
if idx > 0:
|
||||
self.setCurrentIndex(idx - 1)
|
||||
if idx - count >= 0:
|
||||
self.setCurrentIndex(idx - count)
|
||||
else:
|
||||
# FIXME
|
||||
pass
|
||||
|
||||
def switch_next(self):
|
||||
"""Switch to the next tab.
|
||||
def switch_next(self, count=None):
|
||||
"""Switch to the ([count]th) next tab.
|
||||
|
||||
Command handler for :tabnext.
|
||||
"""
|
||||
if count is None:
|
||||
count = 1
|
||||
idx = self.currentIndex()
|
||||
if idx < self.count() - 1:
|
||||
self.setCurrentIndex(idx + 1)
|
||||
if idx + count < self.count():
|
||||
self.setCurrentIndex(idx + count)
|
||||
else:
|
||||
# FIXME
|
||||
pass
|
||||
@ -281,6 +302,18 @@ class TabbedBrowser(TabWidget):
|
||||
self.keypress.emit(e)
|
||||
super().keyPressEvent(e)
|
||||
|
||||
def _widget(self, count=None):
|
||||
"""Return a widget based on a count/idx.
|
||||
|
||||
If count is None, return the current widget.
|
||||
"""
|
||||
if count is None:
|
||||
return self.currentWidget()
|
||||
elif 1 <= count <= self.count():
|
||||
return self.widget(count - 1)
|
||||
else:
|
||||
return None
|
||||
|
||||
def _titleChanged_handler(self, text):
|
||||
"""Set the title of a tab.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user