Prevent double-entering hint mode. Fixes #160.

This commit is contained in:
Florian Bruhin 2014-10-08 22:19:24 +02:00
parent cbdade6518
commit d9213ecf17
2 changed files with 14 additions and 10 deletions

View File

@ -579,6 +579,10 @@ class HintManager(QObject):
mainframe = widget.page().mainFrame()
if mainframe is None:
raise cmdexc.CommandError("No frame focused!")
mode_manager = objreg.get('mode-manager', scope='window',
window=self._win_id)
if usertypes.KeyMode.hint in mode_manager.mode_stack:
raise cmdexc.CommandError("Already hinting!")
self._check_args(target, *args)
self._context = HintContext()
self._context.target = target

View File

@ -144,10 +144,10 @@ class ModeManager(QObject):
locked: Whether current mode is locked. This means the current mode can
still be left (then locked will be reset), but no new mode can
be entered while the current mode is active.
mode_stack: A list of the modes we're currently in, with the active
one on the right.
_win_id: The window ID of this ModeManager
_handlers: A dictionary of modes and their handlers.
_mode_stack: A list of the modes we're currently in, with the active
one on the right.
_forward_unbound_keys: If we should forward unbound keys.
_releaseevents_to_pass: A list of keys where the keyPressEvent was
passed through, so the release event should as
@ -171,7 +171,7 @@ class ModeManager(QObject):
self.locked = False
self._handlers = {}
self.passthrough = []
self._mode_stack = []
self.mode_stack = []
self._releaseevents_to_pass = []
self._forward_unbound_keys = config.get(
'input', 'forward-unbound-keys')
@ -184,9 +184,9 @@ class ModeManager(QObject):
def mode(self):
"""Get the current mode.."""
if not self._mode_stack:
if not self.mode_stack:
return None
return self._mode_stack[-1]
return self.mode_stack[-1]
def _eventFilter_keypress(self, event):
"""Handle filtering of KeyPress events.
@ -285,11 +285,11 @@ class ModeManager(QObject):
mode, '' if reason is None else ' (reason: {})'.format(reason)))
if mode not in self._handlers:
raise ValueError("No handler for mode {}".format(mode))
if self._mode_stack and self._mode_stack[-1] == mode:
if self.mode_stack and self.mode_stack[-1] == mode:
log.modes.debug("Already at end of stack, doing nothing")
return
self._mode_stack.append(mode)
log.modes.debug("New mode stack: {}".format(self._mode_stack))
self.mode_stack.append(mode)
log.modes.debug("New mode stack: {}".format(self.mode_stack))
self.entered.emit(mode, self._win_id)
@cmdutils.register(instance='mode-manager', hide=True, scope='window')
@ -313,13 +313,13 @@ class ModeManager(QObject):
reason: Why the mode was left.
"""
try:
self._mode_stack.remove(mode)
self.mode_stack.remove(mode)
except ValueError:
raise NotInModeError("Mode {} not on mode stack!".format(mode))
self.locked = False
log.modes.debug("Leaving mode {}{}, new mode stack {}".format(
mode, '' if reason is None else ' (reason: {})'.format(reason),
self._mode_stack))
self.mode_stack))
self.left.emit(mode, self._win_id)
@cmdutils.register(instance='mode-manager', name='leave-mode',