Use normal commands for hint mode

This commit is contained in:
Florian Bruhin 2014-04-24 23:47:02 +02:00
parent 540c134f06
commit 926194849c
5 changed files with 37 additions and 40 deletions

View File

@ -272,7 +272,6 @@ class QuteBrowser(QApplication):
# hints # hints
kp["hint"].fire_hint.connect(tabs.cur.fire_hint) kp["hint"].fire_hint.connect(tabs.cur.fire_hint)
kp["hint"].abort_hinting.connect(tabs.cur.abort_hinting)
kp["hint"].keystring_updated.connect(tabs.cur.handle_hint_key) kp["hint"].keystring_updated.connect(tabs.cur.handle_hint_key)
tabs.hint_strings_updated.connect(kp["hint"].on_hint_strings_updated) tabs.hint_strings_updated.connect(kp["hint"].on_hint_strings_updated)

View File

@ -207,11 +207,6 @@ class CurCommandDispatcher(QObject):
"""Fire a completed hint.""" """Fire a completed hint."""
self._tabs.currentWidget().hintmanager.fire(keystr) self._tabs.currentWidget().hintmanager.fire(keystr)
@pyqtSlot()
def abort_hinting(self):
"""Abort hinting."""
self._tabs.currentWidget().hintmanager.stop()
@pyqtSlot(str, int) @pyqtSlot(str, int)
def search(self, text, flags): def search(self, text, flags):
"""Search for text in the current page. """Search for text in the current page.

View File

@ -91,6 +91,7 @@ class HintManager(QObject):
self._frame = None self._frame = None
self._target = None self._target = None
self._baseurl = None self._baseurl = None
modes.manager.left.connect(self.on_mode_left)
def _hint_strings(self, elems): def _hint_strings(self, elems):
"""Calculate the hint strings for elems. """Calculate the hint strings for elems.
@ -302,18 +303,6 @@ class HintManager(QObject):
self.hint_strings_updated.emit(strings) self.hint_strings_updated.emit(strings)
modes.enter("hint") modes.enter("hint")
def stop(self):
"""Stop hinting."""
for elem in self._elems.values():
elem.label.removeFromDocument()
self._frame.contentsSizeChanged.disconnect(
self.on_contents_size_changed)
self._elems = {}
self._target = None
self._frame = None
modes.leave("hint")
message.clear()
def handle_partial_key(self, keystr): def handle_partial_key(self, keystr):
"""Handle a new partial keypress.""" """Handle a new partial keypress."""
delete = [] delete = []
@ -355,7 +344,7 @@ class HintManager(QObject):
message.set_cmd_text(':{} {}'.format(commands[self._target], message.set_cmd_text(':{} {}'.format(commands[self._target],
urlutils.urlstring(link))) urlutils.urlstring(link)))
if self._target != 'rapid': if self._target != 'rapid':
self.stop() modes.leave("hint")
@pyqtSlot('QSize') @pyqtSlot('QSize')
def on_contents_size_changed(self, _size): def on_contents_size_changed(self, _size):
@ -365,3 +354,17 @@ class HintManager(QObject):
css = self.HINT_CSS.format(left=rect.x(), top=rect.y(), css = self.HINT_CSS.format(left=rect.x(), top=rect.y(),
config=config.instance) config=config.instance)
elems.label.setAttribute("style", css) elems.label.setAttribute("style", css)
@pyqtSlot(str)
def on_mode_left(self, mode):
"""Stop hinting when hinting mode was left."""
if mode != "hint":
return
for elem in self._elems.values():
elem.label.removeFromDocument()
self._frame.contentsSizeChanged.disconnect(
self.on_contents_size_changed)
self._elems = {}
self._target = None
self._frame = None
message.clear()

View File

@ -83,6 +83,11 @@ SECTION_DESC = {
"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."), "An useful command to map here is the hidden command leave_mode."),
'keybind.hint': (
"Keybindings for hint mode.\n"
"Since normal keypresses are passed through, only special keys are "
"supported in this mode.\n"
"An useful command to map here is the hidden command leave_mode."),
'aliases': ( 'aliases': (
"Aliases for commands.\n" "Aliases for commands.\n"
"By default, no aliases are defined. Example which adds a new command " "By default, no aliases are defined. Example which adds a new command "
@ -431,6 +436,12 @@ DATA = OrderedDict([
('<Ctrl-C>', 'leave_mode'), ('<Ctrl-C>', 'leave_mode'),
)), )),
('keybind.hint', sect.ValueList(
types.KeyBindingName(), types.KeyBinding(),
('<Escape>', 'leave_mode'),
('<Ctrl-C>', 'leave_mode'),
)),
('aliases', sect.ValueList( ('aliases', sect.ValueList(
types.Command(), types.Command(), types.Command(), types.Command(),
)), )),

View File

@ -19,46 +19,35 @@
from PyQt5.QtCore import pyqtSignal, Qt from PyQt5.QtCore import pyqtSignal, Qt
from qutebrowser.keyinput.keyparser import KeyParser from qutebrowser.keyinput.keyparser import CommandKeyParser
class HintKeyParser(KeyParser): class HintKeyParser(CommandKeyParser):
"""KeyChainParser for hints. """KeyChainParser for hints.
Signals: Signals:
fire_hint: When a hint keybinding was completed. fire_hint: When a hint keybinding was completed.
Arg: the keystring/hint string pressed. Arg: the keystring/hint string pressed.
abort_hinting: Esc pressed, so abort hinting.
""" """
fire_hint = pyqtSignal(str) fire_hint = pyqtSignal(str)
abort_hinting = pyqtSignal()
def __init__(self, parent=None): def __init__(self, parent=None):
super().__init__(parent, supports_count=False, supports_chains=True) super().__init__(parent, supports_count=False, supports_chains=True)
self.read_config('keybind.hint')
def _handle_special_key(self, e): def execute(self, cmdstr, keytype, count=None):
"""Handle the escape key.
FIXME make this more generic
Emit:
abort_hinting: Emitted if hinting was aborted.
"""
if e.key() == Qt.Key_Escape:
self._keystring = ''
self.abort_hinting.emit()
return True
return False
def execute(self, cmdstr, _count=None):
"""Handle a completed keychain. """Handle a completed keychain.
Emit: Emit:
fire_hint: Always emitted. fire_hint: Emitted if keytype is TYPE_CHAIN
""" """
self.fire_hint.emit(cmdstr) if keytype == self.TYPE_CHAIN:
self.fire_hint.emit(cmdstr)
else:
# execute as command
super().execute(cmdstr, keytype, count)
def on_hint_strings_updated(self, strings): def on_hint_strings_updated(self, strings):
"""Handler for HintManager's hint_strings_updated. """Handler for HintManager's hint_strings_updated.