From c0d4fe0ab541c334e742816a1c0689d3c839812a Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 30 Nov 2018 13:14:58 +0100 Subject: [PATCH] Make it possible to inject tab via cmdutils.Value --- doc/contributing.asciidoc | 1 + qutebrowser/commands/command.py | 7 ++++++- qutebrowser/utils/usertypes.py | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/contributing.asciidoc b/doc/contributing.asciidoc index 399633257..b11014ca1 100644 --- a/doc/contributing.asciidoc +++ b/doc/contributing.asciidoc @@ -483,6 +483,7 @@ The following arguments are supported for `@cmdutils.argument`: - `value`: Tell qutebrowser to fill the argument with special values: - `value=cmdutils.Value.count`: The `count` given by the user to the command. - `value=cmdutils.Value.win_id`: The window ID of the current window. + - `value=cmdutils.Value.tab`: The tab object which is currently focused. - `completion`: A completion function (see `qutebrowser.completions.models.*`) to use when completing arguments for the given command. - `choices`: The allowed string choices for the argument. diff --git a/qutebrowser/commands/command.py b/qutebrowser/commands/command.py index 51fe6cceb..631ecc354 100644 --- a/qutebrowser/commands/command.py +++ b/qutebrowser/commands/command.py @@ -193,7 +193,7 @@ class Command: raise TypeError("{}: handler has count parameter " "without default!".format(self.name)) return True - elif arg_info.value == usertypes.CommandValue.win_id: + elif isinstance(arg_info.value, usertypes.CommandValue): return True else: raise TypeError("{}: Invalid value={!r} for argument '{}'!" @@ -441,6 +441,11 @@ class Command: self._add_special_arg(value=win_id, param=param, args=args, kwargs=kwargs) continue + elif arg_info.value == usertypes.CommandValue.tab: + tab = self._get_objreg(win_id=win_id, name='tab', scope='tab') + self._add_special_arg(value=tab, param=param, + args=args, kwargs=kwargs) + continue elif arg_info.value is None: pass else: diff --git a/qutebrowser/utils/usertypes.py b/qutebrowser/utils/usertypes.py index d8f46ded8..c6fddb039 100644 --- a/qutebrowser/utils/usertypes.py +++ b/qutebrowser/utils/usertypes.py @@ -262,6 +262,7 @@ class CommandValue(enum.Enum): count = 1 win_id = 2 + tab = 3 class Question(QObject):