Use object registry for command-dispatcher.
This commit is contained in:
parent
5f45d3de60
commit
f5b1d3ce4d
@ -155,7 +155,7 @@ class CommandDispatcher:
|
|||||||
except PermissionError:
|
except PermissionError:
|
||||||
raise cmdexc.CommandError("Failed to delete tempfile...")
|
raise cmdexc.CommandError("Failed to delete tempfile...")
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
@cmdutils.register(instance='command-dispatcher')
|
||||||
def tab_close(self, count=None):
|
def tab_close(self, count=None):
|
||||||
"""Close the current/[count]th tab.
|
"""Close the current/[count]th tab.
|
||||||
|
|
||||||
@ -171,7 +171,7 @@ class CommandDispatcher:
|
|||||||
return
|
return
|
||||||
self._tabs.close_tab(tab)
|
self._tabs.close_tab(tab)
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd', name='open',
|
@cmdutils.register(instance='command-dispatcher', name='open',
|
||||||
split=False)
|
split=False)
|
||||||
def openurl(self, url, bg=False, tab=False, count=None):
|
def openurl(self, url, bg=False, tab=False, count=None):
|
||||||
"""Open a URL in the current/[count]th tab.
|
"""Open a URL in the current/[count]th tab.
|
||||||
@ -203,7 +203,7 @@ class CommandDispatcher:
|
|||||||
else:
|
else:
|
||||||
curtab.openurl(url)
|
curtab.openurl(url)
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd', name='reload')
|
@cmdutils.register(instance='command-dispatcher', name='reload')
|
||||||
def reloadpage(self, count=None):
|
def reloadpage(self, count=None):
|
||||||
"""Reload the current/[count]th tab.
|
"""Reload the current/[count]th tab.
|
||||||
|
|
||||||
@ -214,7 +214,7 @@ class CommandDispatcher:
|
|||||||
if tab is not None:
|
if tab is not None:
|
||||||
tab.reload()
|
tab.reload()
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
@cmdutils.register(instance='command-dispatcher')
|
||||||
def stop(self, count=None):
|
def stop(self, count=None):
|
||||||
"""Stop loading in the current/[count]th tab.
|
"""Stop loading in the current/[count]th tab.
|
||||||
|
|
||||||
@ -225,7 +225,7 @@ class CommandDispatcher:
|
|||||||
if tab is not None:
|
if tab is not None:
|
||||||
tab.stop()
|
tab.stop()
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd', name='print')
|
@cmdutils.register(instance='command-dispatcher', name='print')
|
||||||
def printpage(self, preview=False, count=None):
|
def printpage(self, preview=False, count=None):
|
||||||
"""Print the current/[count]th tab.
|
"""Print the current/[count]th tab.
|
||||||
|
|
||||||
@ -249,7 +249,7 @@ class CommandDispatcher:
|
|||||||
diag.setAttribute(Qt.WA_DeleteOnClose)
|
diag.setAttribute(Qt.WA_DeleteOnClose)
|
||||||
diag.open(lambda: tab.print(diag.printer()))
|
diag.open(lambda: tab.print(diag.printer()))
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
@cmdutils.register(instance='command-dispatcher')
|
||||||
def back(self, count=1):
|
def back(self, count=1):
|
||||||
"""Go back in the history of the current tab.
|
"""Go back in the history of the current tab.
|
||||||
|
|
||||||
@ -259,7 +259,7 @@ class CommandDispatcher:
|
|||||||
for _ in range(count):
|
for _ in range(count):
|
||||||
self._current_widget().go_back()
|
self._current_widget().go_back()
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
@cmdutils.register(instance='command-dispatcher')
|
||||||
def forward(self, count=1):
|
def forward(self, count=1):
|
||||||
"""Go forward in the history of the current tab.
|
"""Go forward in the history of the current tab.
|
||||||
|
|
||||||
@ -269,7 +269,7 @@ class CommandDispatcher:
|
|||||||
for _ in range(count):
|
for _ in range(count):
|
||||||
self._current_widget().go_forward()
|
self._current_widget().go_forward()
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
@cmdutils.register(instance='command-dispatcher')
|
||||||
def hint(self, group=webelem.Group.all, target=hints.Target.normal,
|
def hint(self, group=webelem.Group.all, target=hints.Target.normal,
|
||||||
*args: {'nargs': '*'}):
|
*args: {'nargs': '*'}):
|
||||||
"""Start hinting.
|
"""Start hinting.
|
||||||
@ -313,7 +313,7 @@ class CommandDispatcher:
|
|||||||
widget.hintmanager.start(frame, self._tabs.current_url(), group,
|
widget.hintmanager.start(frame, self._tabs.current_url(), group,
|
||||||
target, *args)
|
target, *args)
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd', hide=True)
|
@cmdutils.register(instance='command-dispatcher', hide=True)
|
||||||
def follow_hint(self):
|
def follow_hint(self):
|
||||||
"""Follow the currently selected hint."""
|
"""Follow the currently selected hint."""
|
||||||
self._current_widget().hintmanager.follow_hint()
|
self._current_widget().hintmanager.follow_hint()
|
||||||
@ -365,7 +365,7 @@ class CommandDispatcher:
|
|||||||
url.setPath(new_path)
|
url.setPath(new_path)
|
||||||
self._open(url, tab, background=False)
|
self._open(url, tab, background=False)
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
@cmdutils.register(instance='command-dispatcher')
|
||||||
def navigate(self, where: ('prev', 'next', 'up', 'increment', 'decrement'),
|
def navigate(self, where: ('prev', 'next', 'up', 'increment', 'decrement'),
|
||||||
tab=False):
|
tab=False):
|
||||||
"""Open typical prev/next links or navigate using the URL path.
|
"""Open typical prev/next links or navigate using the URL path.
|
||||||
@ -405,7 +405,7 @@ class CommandDispatcher:
|
|||||||
raise ValueError("Got called with invalid value {} for "
|
raise ValueError("Got called with invalid value {} for "
|
||||||
"`where'.".format(where))
|
"`where'.".format(where))
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd', hide=True)
|
@cmdutils.register(instance='command-dispatcher', hide=True)
|
||||||
def scroll(self, dx: float, dy: float, count=1):
|
def scroll(self, dx: float, dy: float, count=1):
|
||||||
"""Scroll the current tab by 'count * dx/dy'.
|
"""Scroll the current tab by 'count * dx/dy'.
|
||||||
|
|
||||||
@ -420,7 +420,7 @@ class CommandDispatcher:
|
|||||||
cmdutils.check_overflow(dy, 'int')
|
cmdutils.check_overflow(dy, 'int')
|
||||||
self._current_widget().page().currentFrame().scroll(dx, dy)
|
self._current_widget().page().currentFrame().scroll(dx, dy)
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd', hide=True)
|
@cmdutils.register(instance='command-dispatcher', hide=True)
|
||||||
def scroll_perc(self, perc: float=None,
|
def scroll_perc(self, perc: float=None,
|
||||||
horizontal: {'flag': 'x'}=False, count=None):
|
horizontal: {'flag': 'x'}=False, count=None):
|
||||||
"""Scroll to a specific percentage of the page.
|
"""Scroll to a specific percentage of the page.
|
||||||
@ -436,7 +436,7 @@ class CommandDispatcher:
|
|||||||
self._scroll_percent(perc, count,
|
self._scroll_percent(perc, count,
|
||||||
Qt.Horizontal if horizontal else Qt.Vertical)
|
Qt.Horizontal if horizontal else Qt.Vertical)
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd', hide=True)
|
@cmdutils.register(instance='command-dispatcher', hide=True)
|
||||||
def scroll_page(self, x: float, y: float, count=1):
|
def scroll_page(self, x: float, y: float, count=1):
|
||||||
"""Scroll the frame page-wise.
|
"""Scroll the frame page-wise.
|
||||||
|
|
||||||
@ -453,7 +453,7 @@ class CommandDispatcher:
|
|||||||
cmdutils.check_overflow(dy, 'int')
|
cmdutils.check_overflow(dy, 'int')
|
||||||
frame.scroll(dx, dy)
|
frame.scroll(dx, dy)
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
@cmdutils.register(instance='command-dispatcher')
|
||||||
def yank(self, title=False, sel=False):
|
def yank(self, title=False, sel=False):
|
||||||
"""Yank the current URL/title to the clipboard or primary selection.
|
"""Yank the current URL/title to the clipboard or primary selection.
|
||||||
|
|
||||||
@ -478,7 +478,7 @@ class CommandDispatcher:
|
|||||||
what = 'Title' if title else 'URL'
|
what = 'Title' if title else 'URL'
|
||||||
message.info("{} yanked to {}".format(what, target))
|
message.info("{} yanked to {}".format(what, target))
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
@cmdutils.register(instance='command-dispatcher')
|
||||||
def zoom_in(self, count=1):
|
def zoom_in(self, count=1):
|
||||||
"""Increase the zoom level for the current tab.
|
"""Increase the zoom level for the current tab.
|
||||||
|
|
||||||
@ -488,7 +488,7 @@ class CommandDispatcher:
|
|||||||
tab = self._current_widget()
|
tab = self._current_widget()
|
||||||
tab.zoom(count)
|
tab.zoom(count)
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
@cmdutils.register(instance='command-dispatcher')
|
||||||
def zoom_out(self, count=1):
|
def zoom_out(self, count=1):
|
||||||
"""Decrease the zoom level for the current tab.
|
"""Decrease the zoom level for the current tab.
|
||||||
|
|
||||||
@ -498,7 +498,7 @@ class CommandDispatcher:
|
|||||||
tab = self._current_widget()
|
tab = self._current_widget()
|
||||||
tab.zoom(-count)
|
tab.zoom(-count)
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
@cmdutils.register(instance='command-dispatcher')
|
||||||
def zoom(self, zoom=None, count=None):
|
def zoom(self, zoom=None, count=None):
|
||||||
"""Set the zoom level for the current tab.
|
"""Set the zoom level for the current tab.
|
||||||
|
|
||||||
@ -516,7 +516,7 @@ class CommandDispatcher:
|
|||||||
tab = self._current_widget()
|
tab = self._current_widget()
|
||||||
tab.zoom_perc(level)
|
tab.zoom_perc(level)
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
@cmdutils.register(instance='command-dispatcher')
|
||||||
def tab_only(self):
|
def tab_only(self):
|
||||||
"""Close all tabs except for the current one."""
|
"""Close all tabs except for the current one."""
|
||||||
for tab in self._tabs.widgets():
|
for tab in self._tabs.widgets():
|
||||||
@ -524,7 +524,7 @@ class CommandDispatcher:
|
|||||||
continue
|
continue
|
||||||
self._tabs.close_tab(tab)
|
self._tabs.close_tab(tab)
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
@cmdutils.register(instance='command-dispatcher')
|
||||||
def undo(self):
|
def undo(self):
|
||||||
"""Re-open a closed tab (optionally skipping [count] closed tabs)."""
|
"""Re-open a closed tab (optionally skipping [count] closed tabs)."""
|
||||||
if self._tabs.url_stack:
|
if self._tabs.url_stack:
|
||||||
@ -532,7 +532,7 @@ class CommandDispatcher:
|
|||||||
else:
|
else:
|
||||||
raise cmdexc.CommandError("Nothing to undo!")
|
raise cmdexc.CommandError("Nothing to undo!")
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
@cmdutils.register(instance='command-dispatcher')
|
||||||
def tab_prev(self, count=1):
|
def tab_prev(self, count=1):
|
||||||
"""Switch to the previous tab, or switch [count] tabs back.
|
"""Switch to the previous tab, or switch [count] tabs back.
|
||||||
|
|
||||||
@ -547,7 +547,7 @@ class CommandDispatcher:
|
|||||||
else:
|
else:
|
||||||
raise cmdexc.CommandError("First tab")
|
raise cmdexc.CommandError("First tab")
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
@cmdutils.register(instance='command-dispatcher')
|
||||||
def tab_next(self, count=1):
|
def tab_next(self, count=1):
|
||||||
"""Switch to the next tab, or switch [count] tabs forward.
|
"""Switch to the next tab, or switch [count] tabs forward.
|
||||||
|
|
||||||
@ -562,7 +562,7 @@ class CommandDispatcher:
|
|||||||
else:
|
else:
|
||||||
raise cmdexc.CommandError("Last tab")
|
raise cmdexc.CommandError("Last tab")
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
@cmdutils.register(instance='command-dispatcher')
|
||||||
def paste(self, sel=False, tab=False, bg=False):
|
def paste(self, sel=False, tab=False, bg=False):
|
||||||
"""Open a page from the clipboard.
|
"""Open a page from the clipboard.
|
||||||
|
|
||||||
@ -588,7 +588,7 @@ class CommandDispatcher:
|
|||||||
raise cmdexc.CommandError(e)
|
raise cmdexc.CommandError(e)
|
||||||
self._open(url, tab, bg)
|
self._open(url, tab, bg)
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
@cmdutils.register(instance='command-dispatcher')
|
||||||
def tab_focus(self, index: (int, 'last')=None, count=None):
|
def tab_focus(self, index: (int, 'last')=None, count=None):
|
||||||
"""Select the tab given as argument/[count].
|
"""Select the tab given as argument/[count].
|
||||||
|
|
||||||
@ -612,7 +612,7 @@ class CommandDispatcher:
|
|||||||
raise cmdexc.CommandError("There's no tab with index {}!".format(
|
raise cmdexc.CommandError("There's no tab with index {}!".format(
|
||||||
idx))
|
idx))
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
@cmdutils.register(instance='command-dispatcher')
|
||||||
def tab_move(self, direction: ('+', '-')=None, count=None):
|
def tab_move(self, direction: ('+', '-')=None, count=None):
|
||||||
"""Move the current tab.
|
"""Move the current tab.
|
||||||
|
|
||||||
@ -650,7 +650,7 @@ class CommandDispatcher:
|
|||||||
finally:
|
finally:
|
||||||
self._tabs.setUpdatesEnabled(True)
|
self._tabs.setUpdatesEnabled(True)
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd', split=False)
|
@cmdutils.register(instance='command-dispatcher', split=False)
|
||||||
def spawn(self, *args):
|
def spawn(self, *args):
|
||||||
"""Spawn a command in a shell.
|
"""Spawn a command in a shell.
|
||||||
|
|
||||||
@ -668,12 +668,12 @@ class CommandDispatcher:
|
|||||||
log.procs.debug("Executing: {}".format(args))
|
log.procs.debug("Executing: {}".format(args))
|
||||||
subprocess.Popen(args)
|
subprocess.Popen(args)
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
@cmdutils.register(instance='command-dispatcher')
|
||||||
def home(self):
|
def home(self):
|
||||||
"""Open main startpage in current tab."""
|
"""Open main startpage in current tab."""
|
||||||
self.openurl(config.get('general', 'startpage')[0])
|
self.openurl(config.get('general', 'startpage')[0])
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
@cmdutils.register(instance='command-dispatcher')
|
||||||
def run_userscript(self, cmd, *args: {'nargs': '*'}):
|
def run_userscript(self, cmd, *args: {'nargs': '*'}):
|
||||||
"""Run an userscript given as argument.
|
"""Run an userscript given as argument.
|
||||||
|
|
||||||
@ -684,12 +684,12 @@ class CommandDispatcher:
|
|||||||
url = self._tabs.current_url()
|
url = self._tabs.current_url()
|
||||||
userscripts.run(cmd, *args, url=url)
|
userscripts.run(cmd, *args, url=url)
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
@cmdutils.register(instance='command-dispatcher')
|
||||||
def quickmark_save(self):
|
def quickmark_save(self):
|
||||||
"""Save the current page as a quickmark."""
|
"""Save the current page as a quickmark."""
|
||||||
quickmarks.prompt_save(self._tabs.current_url())
|
quickmarks.prompt_save(self._tabs.current_url())
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
@cmdutils.register(instance='command-dispatcher')
|
||||||
def quickmark_load(self, name, tab=False, bg=False):
|
def quickmark_load(self, name, tab=False, bg=False):
|
||||||
"""Load a quickmark.
|
"""Load a quickmark.
|
||||||
|
|
||||||
@ -705,7 +705,7 @@ class CommandDispatcher:
|
|||||||
urlstr, url.errorString()))
|
urlstr, url.errorString()))
|
||||||
self._open(url, tab, bg)
|
self._open(url, tab, bg)
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd', name='inspector')
|
@cmdutils.register(instance='command-dispatcher', name='inspector')
|
||||||
def toggle_inspector(self):
|
def toggle_inspector(self):
|
||||||
"""Toggle the web inspector."""
|
"""Toggle the web inspector."""
|
||||||
cur = self._current_widget()
|
cur = self._current_widget()
|
||||||
@ -727,13 +727,13 @@ class CommandDispatcher:
|
|||||||
else:
|
else:
|
||||||
cur.inspector.show()
|
cur.inspector.show()
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
@cmdutils.register(instance='command-dispatcher')
|
||||||
def download_page(self):
|
def download_page(self):
|
||||||
"""Download the current page."""
|
"""Download the current page."""
|
||||||
page = self._current_widget().page()
|
page = self._current_widget().page()
|
||||||
self._tabs.download_get.emit(self._tabs.current_url(), page)
|
self._tabs.download_get.emit(self._tabs.current_url(), page)
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd')
|
@cmdutils.register(instance='command-dispatcher')
|
||||||
def view_source(self):
|
def view_source(self):
|
||||||
"""Show the source of the current page."""
|
"""Show the source of the current page."""
|
||||||
# pylint doesn't seem to like pygments...
|
# pylint doesn't seem to like pygments...
|
||||||
@ -752,7 +752,7 @@ class CommandDispatcher:
|
|||||||
tab.setHtml(highlighted, url)
|
tab.setHtml(highlighted, url)
|
||||||
tab.viewing_source = True
|
tab.viewing_source = True
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd', name='help',
|
@cmdutils.register(instance='command-dispatcher', name='help',
|
||||||
completion=[usertypes.Completion.helptopic])
|
completion=[usertypes.Completion.helptopic])
|
||||||
def show_help(self, topic=None):
|
def show_help(self, topic=None):
|
||||||
r"""Show help about a command or setting.
|
r"""Show help about a command or setting.
|
||||||
@ -789,7 +789,7 @@ class CommandDispatcher:
|
|||||||
raise cmdexc.CommandError("Invalid help topic {}!".format(topic))
|
raise cmdexc.CommandError("Invalid help topic {}!".format(topic))
|
||||||
self.openurl('qute://help/{}'.format(path))
|
self.openurl('qute://help/{}'.format(path))
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cmd',
|
@cmdutils.register(instance='command-dispatcher',
|
||||||
modes=[usertypes.KeyMode.insert],
|
modes=[usertypes.KeyMode.insert],
|
||||||
hide=True)
|
hide=True)
|
||||||
def open_editor(self):
|
def open_editor(self):
|
||||||
|
@ -54,7 +54,6 @@ class TabbedBrowser(tabwidget.TabWidget):
|
|||||||
tabbar -> new-tab-position set to 'left'.
|
tabbar -> new-tab-position set to 'left'.
|
||||||
_tab_insert_idx_right: Same as above, for 'right'.
|
_tab_insert_idx_right: Same as above, for 'right'.
|
||||||
url_stack: Stack of URLs of closed tabs.
|
url_stack: Stack of URLs of closed tabs.
|
||||||
cmd: A TabCommandDispatcher instance.
|
|
||||||
last_focused: The tab which was focused last.
|
last_focused: The tab which was focused last.
|
||||||
|
|
||||||
Signals:
|
Signals:
|
||||||
@ -110,7 +109,8 @@ class TabbedBrowser(tabwidget.TabWidget):
|
|||||||
self._tabs = []
|
self._tabs = []
|
||||||
self.url_stack = []
|
self.url_stack = []
|
||||||
self._filter = signalfilter.SignalFilter(self)
|
self._filter = signalfilter.SignalFilter(self)
|
||||||
self.cmd = commands.CommandDispatcher(self)
|
dispatcher = commands.CommandDispatcher(self)
|
||||||
|
utils.register_object('command-dispatcher', dispatcher)
|
||||||
self.last_focused = None
|
self.last_focused = None
|
||||||
self._now_focused = None
|
self._now_focused = None
|
||||||
# FIXME adjust this to font size
|
# FIXME adjust this to font size
|
||||||
|
Loading…
Reference in New Issue
Block a user