Simplify :hint by adding a 'fill' target.
This commit is contained in:
parent
40aa387fb2
commit
acfc95e19d
@ -277,7 +277,8 @@ class CommandDispatcher:
|
||||
- `tab-bg`: Open the link in a new background tab.
|
||||
- `yank`: Yank the link to the clipboard.
|
||||
- `yank-primary`: Yank the link to the primary selection.
|
||||
- `cmd`: Fill the commandline with `:open` and the link.
|
||||
- `fill`: Fill the commandline with the command given as
|
||||
argument.
|
||||
- `cmd-tab`: Fill the commandline with `:open-tab` and the
|
||||
link.
|
||||
- `cmd-tag-bg`: Fill the commandline with `:open-tab-bg` and
|
||||
@ -286,10 +287,18 @@ class CommandDispatcher:
|
||||
- `download`: Download the link.
|
||||
- `userscript`: Call an userscript with `$QUTE_URL` set to the
|
||||
link.
|
||||
- `spawn`: Spawn a command, with the argument `{hint-url}`
|
||||
replaced by the link.
|
||||
- `spawn`: Spawn a command.
|
||||
|
||||
*args: Arguments for spawn/userscript.
|
||||
*args: Arguments for spawn/userscript/fill.
|
||||
|
||||
|
||||
- With `spawn`: The executable and arguments to spawn.
|
||||
`{hint-url}` will get replaced by the selected
|
||||
URL.
|
||||
- With `userscript`: The userscript to execute.
|
||||
- With `fill`: The command to fill the statusbar with.
|
||||
`{hint-url}` will get replaced by the selected
|
||||
URL.
|
||||
"""
|
||||
widget = self._tabs.currentWidget()
|
||||
frame = widget.page().mainFrame()
|
||||
@ -297,11 +306,11 @@ class CommandDispatcher:
|
||||
raise CommandError("No frame focused!")
|
||||
try:
|
||||
group_enum = webelem.Group[group.replace('-', '_')]
|
||||
except AttributeError:
|
||||
except KeyError:
|
||||
raise CommandError("Unknown hinting group {}!".format(group))
|
||||
try:
|
||||
target_enum = hints.Target[target.replace('-', '_')]
|
||||
except AttributeError:
|
||||
except KeyError:
|
||||
raise CommandError("Unknown hinting target {}!".format(target))
|
||||
widget.hintmanager.start(frame, self._tabs.current_url(), group_enum,
|
||||
target_enum, *args)
|
||||
|
@ -42,8 +42,7 @@ ElemTuple = namedtuple('ElemTuple', 'elem, label')
|
||||
|
||||
|
||||
Target = enum('Target', 'normal', 'tab', 'tab_bg', 'yank', 'yank_primary',
|
||||
'cmd', 'cmd_tab', 'cmd_tab_bg', 'rapid', 'download',
|
||||
'userscript', 'spawn')
|
||||
'fill', 'rapid', 'download', 'userscript', 'spawn')
|
||||
|
||||
|
||||
class HintContext:
|
||||
@ -57,7 +56,7 @@ class HintContext:
|
||||
target: What to do with the opened links.
|
||||
normal/tab/tab_bg: Get passed to BrowserTab.
|
||||
yank/yank_primary: Yank to clipboard/primary selection
|
||||
cmd/cmd_tab/cmd_tab_bg: Enter link to commandline
|
||||
fill: Fill commandline with link.
|
||||
rapid: Rapid mode with background tabs
|
||||
download: Download the link.
|
||||
userscript: Call a custom userscript.
|
||||
@ -88,6 +87,16 @@ class HintContext:
|
||||
raise TypeError("Target {} is no Target member!".format(val))
|
||||
self._target = val
|
||||
|
||||
def get_args(self, urlstr):
|
||||
"""Get the arguments, with {hint-url} replaced by the given URL."""
|
||||
args = []
|
||||
for arg in self.args:
|
||||
if arg == '{hint-url}':
|
||||
args.append(urlstr)
|
||||
else:
|
||||
args.append(arg)
|
||||
return args
|
||||
|
||||
|
||||
class HintManager(QObject):
|
||||
|
||||
@ -134,9 +143,7 @@ class HintManager(QObject):
|
||||
Target.tab_bg: "Follow hint in background tab...",
|
||||
Target.yank: "Yank hint to clipboard...",
|
||||
Target.yank_primary: "Yank hint to primary selection...",
|
||||
Target.cmd: "Set hint in commandline...",
|
||||
Target.cmd_tab: "Set hint in commandline as new tab...",
|
||||
Target.cmd_tab_bg: "Set hint in commandline as background tab...",
|
||||
Target.fill: "Set hint in commandline...",
|
||||
Target.rapid: "Follow hint (rapid mode)...",
|
||||
Target.download: "Download hint...",
|
||||
Target.userscript: "Call userscript via hint...",
|
||||
@ -340,14 +347,10 @@ class HintManager(QObject):
|
||||
url: The URL to open as a QUrl.
|
||||
"""
|
||||
qt_ensure_valid(url)
|
||||
commands = {
|
||||
Target.cmd: 'open',
|
||||
Target.cmd_tab: 'open-tab',
|
||||
Target.cmd_tab_bg: 'open-tab-bg',
|
||||
}
|
||||
command = self._context.args[0]
|
||||
urlstr = url.toDisplayString(QUrl.FullyEncoded)
|
||||
message.set_cmd_text(':{} {}'.format(commands[self._context.target],
|
||||
urlstr))
|
||||
args = self._context.get_args(urlstr)
|
||||
message.set_cmd_text(' '.join(args))
|
||||
|
||||
def _download(self, elem):
|
||||
"""Download a hint URL.
|
||||
@ -374,12 +377,7 @@ class HintManager(QObject):
|
||||
"""Spawn a simple command from a hint."""
|
||||
qt_ensure_valid(url)
|
||||
urlstr = url.toString(QUrl.FullyEncoded | QUrl.RemovePassword)
|
||||
args = []
|
||||
for arg in self._context.args:
|
||||
if arg == '{hint-url}':
|
||||
args.append(urlstr)
|
||||
else:
|
||||
args.append(arg)
|
||||
args = self._context.get_args(urlstr)
|
||||
subprocess.Popen(args)
|
||||
|
||||
def _resolve_url(self, elem, baseurl=None):
|
||||
@ -481,10 +479,10 @@ class HintManager(QObject):
|
||||
# start. But since we had a bug where frame is None in
|
||||
# on_mode_left, we are extra careful here.
|
||||
raise ValueError("start() was called with frame=None")
|
||||
if target in (Target.userscript, Target.spawn):
|
||||
if target in (Target.userscript, Target.spawn, Target.fill):
|
||||
if not args:
|
||||
raise CommandError("Additional arguments are required with "
|
||||
"target userscript/spawn.")
|
||||
"target userscript/spawn/fill.")
|
||||
else:
|
||||
if args:
|
||||
raise CommandError("Arguments are only allowed with target "
|
||||
@ -581,9 +579,7 @@ class HintManager(QObject):
|
||||
url_handlers = {
|
||||
Target.yank: self._yank,
|
||||
Target.yank_primary: self._yank,
|
||||
Target.cmd: self._preset_cmd_text,
|
||||
Target.cmd_tab: self._preset_cmd_text,
|
||||
Target.cmd_tab_bg: self._preset_cmd_text,
|
||||
Target.fill: self._preset_cmd_text,
|
||||
Target.userscript: self._call_userscript,
|
||||
Target.spawn: self._spawn,
|
||||
}
|
||||
|
@ -607,9 +607,9 @@ DATA = OrderedDict([
|
||||
(';i', 'hint images'),
|
||||
(';I', 'hint images tab'),
|
||||
('.i', 'hint images tab-bg'),
|
||||
(';o', 'hint links cmd'),
|
||||
(';O', 'hint links cmd-tab'),
|
||||
('.o', 'hint links cmd-tab-bg'),
|
||||
(';o', 'hint links fill :open {hint-url}'),
|
||||
(';O', 'hint links fill :open-tab {hint-url}'),
|
||||
('.o', 'hint links fill :open-tab-bg {hint-url}'),
|
||||
(';y', 'hint links yank'),
|
||||
(';Y', 'hint links yank-primary'),
|
||||
(';r', 'hint links rapid'),
|
||||
|
Loading…
Reference in New Issue
Block a user