Implement count everywhere

This commit is contained in:
Florian Bruhin 2014-01-30 07:05:17 +01:00
parent 58103fa7e4
commit 85c44ed78c
3 changed files with 92 additions and 51 deletions

View File

@ -23,13 +23,14 @@ from qutebrowser.commands.template import Command
class Open(Command): class Open(Command):
"""Open a page. """Open a page in the current or [count]th tab.
arg: The URL to open. arg: The URL to open.
""" """
nargs = 1 nargs = 1
split_args = False split_args = False
count = True
class TabOpen(Command): class TabOpen(Command):
@ -43,21 +44,21 @@ class TabOpen(Command):
class TabClose(Command): class TabClose(Command):
"""Close the current tab.""" """Close the current tab, or tab [count]."""
nargs = 0 nargs = 0
# FIXME also close [count]th tab count = True
class TabNext(Command): class TabNext(Command):
"""Switch to the next tab.""" """Switch to the next tab, or skip [count] tabs."""
nargs = 0 nargs = 0
# FIXME also support [count] count = True
class TabPrev(Command): class TabPrev(Command):
"""Switch to the previous tab.""" """Switch to the previous tab, or skip [count] tabs."""
nargs = 0 nargs = 0
# FIXME also support [count] count = True
class Quit(Command): class Quit(Command):
@ -67,30 +68,33 @@ class Quit(Command):
class Reload(Command): class Reload(Command):
"""Reload the current page.""" """Reload the current page, or the page in tab [count]."""
nargs = 0 nargs = 0
count = True
class Stop(Command): class Stop(Command):
"""Stop loading the current page.""" """Stop loading the current page, or the page in tab [count]."""
nargs = 0 nargs = 0
count = True
class Back(Command): class Back(Command):
"""Go back one page in the history.""" """Go back one/[count] page(s) in the history."""
nargs = 0 nargs = 0
# FIXME also support [count] count = True
class Forward(Command): class Forward(Command):
"""Go forward one page in the history.""" """Go forward one/[count] page(s) in the history."""
nargs = 0 nargs = 0
# FIXME also support [count] count = True
class Print(Command): class Print(Command):
"""Print the current page.""" """Print the current page, or the page in tab [count]."""
nargs = 0 nargs = 0
count = True
class Scroll(Command): class Scroll(Command):
@ -148,10 +152,11 @@ class PyEval(Command):
class NextSearch(Command): class NextSearch(Command):
"""Jump to the next search term.""" """Jump to the next or [count]th next search term."""
nargs = 0 nargs = 0
hide = True hide = True
count = True
class Yank(Command): class Yank(Command):

View File

@ -61,10 +61,13 @@ class SearchParser(QObject):
self.flags = QWebPage.FindBackward self.flags = QWebPage.FindBackward
self.do_search.emit(self.text, self.flags) self.do_search.emit(self.text, self.flags)
def nextsearch(self): def nextsearch(self, count=None):
"""Continue the search to the next term.""" """Continue the search to the ([count]th) next term."""
if count is None:
count = 1
if self.text is not None: 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): class CommandParser(QObject):

View File

@ -75,13 +75,15 @@ class TabbedBrowser(TabWidget):
# FIXME sometimes this doesn't load # FIXME sometimes this doesn't load
tab.open_tab.connect(self.tabopen) tab.open_tab.connect(self.tabopen)
def openurl(self, url): def openurl(self, url, count=None):
"""Open an url in the current tab. """Open an url in the current/[count]th tab.
Command handler for :open. Command handler for :open.
url -- The URL to 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): def undo_close(self):
"""Undo closing a tab. """Undo closing a tab.
@ -91,60 +93,75 @@ class TabbedBrowser(TabWidget):
if self._url_stack: if self._url_stack:
self.tabopen(self._url_stack.pop()) self.tabopen(self._url_stack.pop())
def cur_close(self): def cur_close(self, count=None):
"""Close the current tab. """Close the current/[count]th tab.
Command handler for :close. Command handler for :close.
""" """
if self.count() > 1: if self.count() > 1:
idx = self.currentIndex() idx = self.currentIndex() if count is None else count - 1
tab = self.currentWidget() tab = self._widget(count)
# FIXME maybe we actually should store the webview objects here if tab is not None:
self._url_stack.append(tab.url()) # FIXME maybe we actually should store the webview objects here
self.removeTab(idx) self._url_stack.append(tab.url())
self.removeTab(idx)
else: else:
# FIXME # FIXME
pass pass
def cur_reload(self): def cur_reload(self, count=None):
"""Reload the current tab. """Reload the current/[count]th tab.
Command handler for :reload. Command handler for :reload.
""" """
self.currentWidget().reload() tab = self._widget(count)
if tab is not None:
tab.reload()
def cur_stop(self): def cur_stop(self, count=None):
"""Stop loading in the current tab. """Stop loading in the current/[count]th tab.
Command handler for :stop. Command handler for :stop.
""" """
self.currentWidget().stop() tab = self._widget(count)
if tab is not None:
tab.stop()
def cur_print(self): def cur_print(self, count=None):
"""Print the current tab. """Print the current/[count]th tab.
Command handler for :print. Command handler for :print.
""" """
# FIXME that does not what I expect # FIXME that does not what I expect
preview = QPrintPreviewDialog() tab = self._widget(count)
preview.paintRequested.connect(self.currentWidget().print) if tab is not None:
preview.exec_() 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 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. Command handler for :back.
""" """
# FIXME display warning if beginning of history # 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 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. Command handler for :forward.
""" """
# FIXME display warning if end of history # 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): def cur_search(self, text, flags):
"""Search for text in the current page. """Search for text in the current page.
@ -195,26 +212,30 @@ class TabbedBrowser(TabWidget):
return return
frame.setScrollBarValue(orientation, int(m * perc / 100)) frame.setScrollBarValue(orientation, int(m * perc / 100))
def switch_prev(self): def switch_prev(self, count=None):
"""Switch to the previous tab. """Switch to the ([count]th) previous tab.
Command handler for :tabprev. Command handler for :tabprev.
""" """
if count is None:
count = 1
idx = self.currentIndex() idx = self.currentIndex()
if idx > 0: if idx - count >= 0:
self.setCurrentIndex(idx - 1) self.setCurrentIndex(idx - count)
else: else:
# FIXME # FIXME
pass pass
def switch_next(self): def switch_next(self, count=None):
"""Switch to the next tab. """Switch to the ([count]th) next tab.
Command handler for :tabnext. Command handler for :tabnext.
""" """
if count is None:
count = 1
idx = self.currentIndex() idx = self.currentIndex()
if idx < self.count() - 1: if idx + count < self.count():
self.setCurrentIndex(idx + 1) self.setCurrentIndex(idx + count)
else: else:
# FIXME # FIXME
pass pass
@ -281,6 +302,18 @@ class TabbedBrowser(TabWidget):
self.keypress.emit(e) self.keypress.emit(e)
super().keyPressEvent(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): def _titleChanged_handler(self, text):
"""Set the title of a tab. """Set the title of a tab.