Make it possible to limit commands to backends
This commit is contained in:
parent
11cd5f8653
commit
0ab601aaf3
@ -452,7 +452,8 @@ class CommandDispatcher:
|
||||
url.setPath(new_path)
|
||||
self._open(url, tab, background, window)
|
||||
|
||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||
@cmdutils.register(instance='command-dispatcher', scope='window',
|
||||
backend=tabmod.Backend.QtWebKit)
|
||||
@cmdutils.argument('where', choices=['prev', 'next', 'up', 'increment',
|
||||
'decrement'])
|
||||
def navigate(self, where: str, tab=False, bg=False, window=False):
|
||||
@ -485,6 +486,9 @@ class CommandDispatcher:
|
||||
|
||||
if where in ['prev', 'next']:
|
||||
# FIXME:qtwebengine have a proper API for this
|
||||
if widget.backend == tabmod.Backend.QtWebEngine:
|
||||
raise cmdexc.CommandError(":navigate prev/next is not "
|
||||
"supported yet with QtWebEngine")
|
||||
page = widget._widget.page() # pylint: disable=protected-access
|
||||
frame = page.currentFrame()
|
||||
if frame is None:
|
||||
@ -1122,7 +1126,7 @@ class CommandDispatcher:
|
||||
raise cmdexc.CommandError(str(e))
|
||||
|
||||
@cmdutils.register(instance='command-dispatcher', name='inspector',
|
||||
scope='window')
|
||||
scope='window', backend=tabmod.Backend.QtWebKit)
|
||||
def toggle_inspector(self):
|
||||
"""Toggle the web inspector.
|
||||
|
||||
@ -1150,7 +1154,8 @@ class CommandDispatcher:
|
||||
else:
|
||||
tab.data.inspector.show()
|
||||
|
||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||
@cmdutils.register(instance='command-dispatcher', scope='window',
|
||||
backend=tabmod.Backend.QtWebKit)
|
||||
@cmdutils.argument('dest_old', hide=True)
|
||||
def download(self, url=None, dest_old=None, *, mhtml_=False, dest=None):
|
||||
"""Download a given URL, or current page if no URL given.
|
||||
@ -1323,7 +1328,8 @@ class CommandDispatcher:
|
||||
self._open(url, tab, bg, window)
|
||||
|
||||
@cmdutils.register(instance='command-dispatcher',
|
||||
modes=[KeyMode.insert], hide=True, scope='window')
|
||||
modes=[KeyMode.insert], hide=True, scope='window',
|
||||
backend=tabmod.Backend.QtWebKit)
|
||||
def open_editor(self):
|
||||
"""Open an external editor with the currently selected form field.
|
||||
|
||||
@ -1372,7 +1378,7 @@ class CommandDispatcher:
|
||||
|
||||
@cmdutils.register(instance='command-dispatcher',
|
||||
modes=[KeyMode.insert], hide=True, scope='window',
|
||||
needs_js=True)
|
||||
needs_js=True, backend=tabmod.Backend.QtWebKit)
|
||||
def paste_primary(self):
|
||||
"""Paste the primary selection at cursor position."""
|
||||
# FIXME:qtwebengine have a proper API for this
|
||||
|
@ -31,6 +31,7 @@ from PyQt5.QtGui import QMouseEvent
|
||||
from PyQt5.QtWebKit import QWebElement
|
||||
from PyQt5.QtWebKitWidgets import QWebPage
|
||||
|
||||
from qutebrowser.browser import tab as tabmod
|
||||
from qutebrowser.config import config
|
||||
from qutebrowser.keyinput import modeman, modeparsers
|
||||
from qutebrowser.browser.webkit import webelem
|
||||
@ -762,7 +763,8 @@ class HintManager(QObject):
|
||||
tab.openurl(url)
|
||||
|
||||
@cmdutils.register(instance='hintmanager', scope='tab', name='hint',
|
||||
star_args_optional=True, maxsplit=2)
|
||||
star_args_optional=True, maxsplit=2,
|
||||
backend=tabmod.Backend.QtWebKit)
|
||||
@cmdutils.argument('win_id', win_id=True)
|
||||
def start(self, rapid=False, group=webelem.Group.all, target=Target.normal,
|
||||
*args, win_id):
|
||||
|
@ -29,6 +29,7 @@ from qutebrowser.commands import cmdexc, argparser
|
||||
from qutebrowser.utils import (log, utils, message, docutils, objreg,
|
||||
usertypes, typing)
|
||||
from qutebrowser.utils import debug as debug_utils
|
||||
from qutebrowser.browser import tab as tabmod
|
||||
|
||||
|
||||
class ArgInfo:
|
||||
@ -80,6 +81,8 @@ class Command:
|
||||
parser: The ArgumentParser to use to parse this command.
|
||||
flags_with_args: A list of flags which take an argument.
|
||||
no_cmd_split: If true, ';;' to split sub-commands is ignored.
|
||||
backend: Which backend the command works with (or None if it works with
|
||||
both)
|
||||
_qute_args: The saved data from @cmdutils.argument
|
||||
_needs_js: Whether the command needs javascript enabled
|
||||
_modes: The modes the command can be executed in.
|
||||
@ -92,7 +95,8 @@ class Command:
|
||||
def __init__(self, *, handler, name, instance=None, maxsplit=None,
|
||||
hide=False, modes=None, not_modes=None, needs_js=False,
|
||||
debug=False, ignore_args=False, deprecated=False,
|
||||
no_cmd_split=False, star_args_optional=False, scope='global'):
|
||||
no_cmd_split=False, star_args_optional=False, scope='global',
|
||||
backend=None):
|
||||
# I really don't know how to solve this in a better way, I tried.
|
||||
# pylint: disable=too-many-locals
|
||||
if modes is not None and not_modes is not None:
|
||||
@ -123,6 +127,8 @@ class Command:
|
||||
self.ignore_args = ignore_args
|
||||
self.handler = handler
|
||||
self.no_cmd_split = no_cmd_split
|
||||
self.backend = backend
|
||||
|
||||
self.docparser = docutils.DocstringParser(handler)
|
||||
self.parser = argparser.ArgumentParser(
|
||||
name, description=self.docparser.short_desc,
|
||||
@ -170,10 +176,22 @@ class Command:
|
||||
raise cmdexc.PrerequisitesError(
|
||||
"{}: This command is not allowed in {} mode.".format(
|
||||
self.name, mode_names))
|
||||
|
||||
if self._needs_js and not QWebSettings.globalSettings().testAttribute(
|
||||
QWebSettings.JavascriptEnabled):
|
||||
raise cmdexc.PrerequisitesError(
|
||||
"{}: This command needs javascript enabled.".format(self.name))
|
||||
|
||||
backend_mapping = {
|
||||
'webkit': tabmod.Backend.QtWebKit,
|
||||
'webengine': tabmod.Backend.QtWebEngine,
|
||||
}
|
||||
used_backend = backend_mapping[objreg.get('args').backend]
|
||||
if self.backend is not None and used_backend != self.backend:
|
||||
raise cmdexc.PrerequisitesError(
|
||||
"{}: Only available with {} "
|
||||
"backend.".format(self.name, self.backend.name))
|
||||
|
||||
if self.deprecated:
|
||||
message.warning(win_id, '{} is deprecated - {}'.format(
|
||||
self.name, self.deprecated))
|
||||
@ -497,8 +515,9 @@ class Command:
|
||||
e.status, e))
|
||||
return
|
||||
self._count = count
|
||||
posargs, kwargs = self._get_call_args(win_id)
|
||||
# FIXME add tests for the _check_prerequisites move!
|
||||
self._check_prerequisites(win_id)
|
||||
posargs, kwargs = self._get_call_args(win_id)
|
||||
log.commands.debug('Calling {}'.format(
|
||||
debug_utils.format_call(self.handler, posargs, kwargs)))
|
||||
self.handler(*posargs, **kwargs)
|
||||
|
Loading…
Reference in New Issue
Block a user