From 926194849c048a704a0885156f7f48d5e0925d6b Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 24 Apr 2014 23:47:02 +0200 Subject: [PATCH] Use normal commands for hint mode --- qutebrowser/app.py | 1 - qutebrowser/browser/curcommand.py | 5 ----- qutebrowser/browser/hints.py | 29 ++++++++++++++++------------- qutebrowser/config/configdata.py | 11 +++++++++++ qutebrowser/keyinput/hintmode.py | 31 ++++++++++--------------------- 5 files changed, 37 insertions(+), 40 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 188efbd81..6c4341b54 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -272,7 +272,6 @@ class QuteBrowser(QApplication): # hints 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) tabs.hint_strings_updated.connect(kp["hint"].on_hint_strings_updated) diff --git a/qutebrowser/browser/curcommand.py b/qutebrowser/browser/curcommand.py index c74704d42..e3eb9f325 100644 --- a/qutebrowser/browser/curcommand.py +++ b/qutebrowser/browser/curcommand.py @@ -207,11 +207,6 @@ class CurCommandDispatcher(QObject): """Fire a completed hint.""" self._tabs.currentWidget().hintmanager.fire(keystr) - @pyqtSlot() - def abort_hinting(self): - """Abort hinting.""" - self._tabs.currentWidget().hintmanager.stop() - @pyqtSlot(str, int) def search(self, text, flags): """Search for text in the current page. diff --git a/qutebrowser/browser/hints.py b/qutebrowser/browser/hints.py index 58f36e295..eb6f3e887 100644 --- a/qutebrowser/browser/hints.py +++ b/qutebrowser/browser/hints.py @@ -91,6 +91,7 @@ class HintManager(QObject): self._frame = None self._target = None self._baseurl = None + modes.manager.left.connect(self.on_mode_left) def _hint_strings(self, elems): """Calculate the hint strings for elems. @@ -302,18 +303,6 @@ class HintManager(QObject): self.hint_strings_updated.emit(strings) 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): """Handle a new partial keypress.""" delete = [] @@ -355,7 +344,7 @@ class HintManager(QObject): message.set_cmd_text(':{} {}'.format(commands[self._target], urlutils.urlstring(link))) if self._target != 'rapid': - self.stop() + modes.leave("hint") @pyqtSlot('QSize') 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(), config=config.instance) 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() diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index cea2e9d92..b795316bd 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -83,6 +83,11 @@ SECTION_DESC = { "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."), + '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 for commands.\n" "By default, no aliases are defined. Example which adds a new command " @@ -431,6 +436,12 @@ DATA = OrderedDict([ ('', 'leave_mode'), )), + ('keybind.hint', sect.ValueList( + types.KeyBindingName(), types.KeyBinding(), + ('', 'leave_mode'), + ('', 'leave_mode'), + )), + ('aliases', sect.ValueList( types.Command(), types.Command(), )), diff --git a/qutebrowser/keyinput/hintmode.py b/qutebrowser/keyinput/hintmode.py index 60ff8f3bb..615c524b1 100644 --- a/qutebrowser/keyinput/hintmode.py +++ b/qutebrowser/keyinput/hintmode.py @@ -19,46 +19,35 @@ 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. Signals: fire_hint: When a hint keybinding was completed. Arg: the keystring/hint string pressed. - abort_hinting: Esc pressed, so abort hinting. """ fire_hint = pyqtSignal(str) - abort_hinting = pyqtSignal() def __init__(self, parent=None): super().__init__(parent, supports_count=False, supports_chains=True) + self.read_config('keybind.hint') - def _handle_special_key(self, e): - """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): + def execute(self, cmdstr, keytype, count=None): """Handle a completed keychain. 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): """Handler for HintManager's hint_strings_updated.