Add manual hint following

This commit is contained in:
Florian Bruhin 2014-04-27 21:59:23 +02:00
parent fd36cc16aa
commit a0f27fed61
3 changed files with 32 additions and 3 deletions

View File

@ -200,6 +200,11 @@ class CurCommandDispatcher(QObject):
else: else:
widget.hintmanager.start(frame, widget.url(), mode, target) widget.hintmanager.start(frame, widget.url(), mode, target)
@cmdutils.register(instance='mainwindow.tabs.cur', hide=True)
def follow_hint(self):
"""Follow the currently selected hint."""
self._tabs.currentWidget().hintmanager.follow_hint()
@pyqtSlot(str) @pyqtSlot(str)
def handle_hint_key(self, keystr): def handle_hint_key(self, keystr):
"""Handle a new hint keypress.""" """Handle a new hint keypress."""

View File

@ -51,6 +51,7 @@ class HintManager(QObject):
'yank'/'yank_primary': Yank to clipboard/primary selection 'yank'/'yank_primary': Yank to clipboard/primary selection
'cmd'/'cmd_tab'/'cmd_bgtab': Enter link to commandline 'cmd'/'cmd_tab'/'cmd_bgtab': Enter link to commandline
'rapid': Rapid mode with background tabs 'rapid': Rapid mode with background tabs
_to_follow: The link to follow when enter is pressed.
Signals: Signals:
hint_strings_updated: Emitted when the possible hint strings changed. hint_strings_updated: Emitted when the possible hint strings changed.
@ -91,6 +92,7 @@ class HintManager(QObject):
self._frame = None self._frame = None
self._target = None self._target = None
self._baseurl = None self._baseurl = None
self._to_follow = None
modeman.manager.left.connect(self.on_mode_left) modeman.manager.left.connect(self.on_mode_left)
def _hint_strings(self, elems): def _hint_strings(self, elems):
@ -318,9 +320,18 @@ class HintManager(QObject):
for key in delete: for key in delete:
del self._elems[key] del self._elems[key]
def fire(self, keystr): def fire(self, keystr, force=False):
"""Fire a completed hint.""" """Fire a completed hint.
Args:
keystr: The keychain string to follow.
force: When True, follow even when auto-follow is false.
"""
# Targets which require a valid link # Targets which require a valid link
if not (force or config.get('hints', 'auto-follow')):
self.handle_partial_key(keystr)
self._to_follow = keystr
return
require_link = ['yank', 'yank_primary', 'cmd', 'cmd_tab', 'cmd_bgtab'] require_link = ['yank', 'yank_primary', 'cmd', 'cmd_tab', 'cmd_bgtab']
elem = self._elems[keystr].elem elem = self._elems[keystr].elem
if self._target in require_link: if self._target in require_link:
@ -346,6 +357,11 @@ class HintManager(QObject):
if self._target != 'rapid': if self._target != 'rapid':
modeman.leave('hint') modeman.leave('hint')
def follow_hint(self):
if not self._to_follow:
message.error("No hint to follow")
self.fire(self._to_follow, force=True)
@pyqtSlot('QSize') @pyqtSlot('QSize')
def on_contents_size_changed(self, _size): def on_contents_size_changed(self, _size):
"""Reposition hints if contents size changed.""" """Reposition hints if contents size changed."""
@ -365,6 +381,7 @@ class HintManager(QObject):
self._frame.contentsSizeChanged.disconnect( self._frame.contentsSizeChanged.disconnect(
self.on_contents_size_changed) self.on_contents_size_changed)
self._elems = {} self._elems = {}
self._to_follow = None
self._target = None self._target = None
self._frame = None self._frame = None
message.clear() message.clear()

View File

@ -89,7 +89,9 @@ SECTION_DESC = {
"Keybindings for hint mode.\n" "Keybindings for hint mode.\n"
"Since normal keypresses are passed through, only special keys are " "Since normal keypresses are passed through, only special keys are "
"supported in this mode.\n" "supported in this mode.\n"
"An useful command to map here is the hidden command leave_mode."), "Useful hidden commands to map in this section:\n"
" follow_hint: Follow the currently selected hint.\n"
" leave_mode: Leave the command mode."),
'keybind.passthrough': ( 'keybind.passthrough': (
"Keybindings for hint mode.\n" "Keybindings for hint mode.\n"
"Since normal keypresses are passed through, only special keys are " "Since normal keypresses are passed through, only special keys are "
@ -384,6 +386,10 @@ DATA = OrderedDict([
('chars', ('chars',
SettingValue(types.String(minlen=2), 'asdfghjkl'), SettingValue(types.String(minlen=2), 'asdfghjkl'),
"Chars used for hint strings."), "Chars used for hint strings."),
('auto-follow',
SettingValue(types.Bool(), 'true'),
"Whether to auto-follow a hint if there's only one left."),
)), )),
('searchengines', sect.ValueList( ('searchengines', sect.ValueList(
@ -466,6 +472,7 @@ DATA = OrderedDict([
('keybind.hint', sect.ValueList( ('keybind.hint', sect.ValueList(
types.KeyBindingName(), types.KeyBinding(), types.KeyBindingName(), types.KeyBinding(),
('<Return>', 'follow_hint'),
('<Escape>', 'leave_mode'), ('<Escape>', 'leave_mode'),
('<Ctrl-C>', 'leave_mode'), ('<Ctrl-C>', 'leave_mode'),
)), )),