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