Add reasons why modes are entered/left
This commit is contained in:
parent
91d1be1020
commit
59a89d31fe
@ -146,7 +146,7 @@ class QuteBrowser(QApplication):
|
|||||||
self.setQuitOnLastWindowClosed(False)
|
self.setQuitOnLastWindowClosed(False)
|
||||||
|
|
||||||
self._connect_signals()
|
self._connect_signals()
|
||||||
self.modeman.enter('normal')
|
self.modeman.enter('normal', 'init')
|
||||||
|
|
||||||
self.mainwindow.show()
|
self.mainwindow.show()
|
||||||
self._python_hacks()
|
self._python_hacks()
|
||||||
|
@ -400,7 +400,7 @@ class HintManager(QObject):
|
|||||||
self._elems[string] = ElemTuple(e, label)
|
self._elems[string] = ElemTuple(e, label)
|
||||||
frame.contentsSizeChanged.connect(self.on_contents_size_changed)
|
frame.contentsSizeChanged.connect(self.on_contents_size_changed)
|
||||||
self.hint_strings_updated.emit(strings)
|
self.hint_strings_updated.emit(strings)
|
||||||
modeman.enter('hint')
|
modeman.enter('hint', 'HintManager.start')
|
||||||
|
|
||||||
def handle_partial_key(self, keystr):
|
def handle_partial_key(self, keystr):
|
||||||
"""Handle a new partial keypress."""
|
"""Handle a new partial keypress."""
|
||||||
@ -442,7 +442,7 @@ class HintManager(QObject):
|
|||||||
visible[k] = e
|
visible[k] = e
|
||||||
if not visible:
|
if not visible:
|
||||||
# Whoops, filtered all hints
|
# Whoops, filtered all hints
|
||||||
modeman.leave('hint')
|
modeman.leave('hint', 'all filtered')
|
||||||
elif len(visible) == 1 and config.get('hints', 'auto-follow'):
|
elif len(visible) == 1 and config.get('hints', 'auto-follow'):
|
||||||
# unpacking gets us the first (and only) key in the dict.
|
# unpacking gets us the first (and only) key in the dict.
|
||||||
self.fire(*visible)
|
self.fire(*visible)
|
||||||
@ -485,7 +485,7 @@ class HintManager(QObject):
|
|||||||
else:
|
else:
|
||||||
raise ValueError("No suitable handler found!")
|
raise ValueError("No suitable handler found!")
|
||||||
if self._target != Target.rapid:
|
if self._target != Target.rapid:
|
||||||
modeman.leave('hint')
|
modeman.leave('hint', 'followed')
|
||||||
|
|
||||||
def follow_hint(self):
|
def follow_hint(self):
|
||||||
"""Follow the currently selected hint."""
|
"""Follow the currently selected hint."""
|
||||||
|
@ -37,20 +37,20 @@ def instance():
|
|||||||
return QApplication.instance().modeman
|
return QApplication.instance().modeman
|
||||||
|
|
||||||
|
|
||||||
def enter(mode):
|
def enter(mode, reason=None):
|
||||||
"""Enter the mode 'mode'."""
|
"""Enter the mode 'mode'."""
|
||||||
instance().enter(mode)
|
instance().enter(mode, reason)
|
||||||
|
|
||||||
|
|
||||||
def leave(mode):
|
def leave(mode, reason=None):
|
||||||
"""Leave the mode 'mode'."""
|
"""Leave the mode 'mode'."""
|
||||||
instance().leave(mode)
|
instance().leave(mode, reason)
|
||||||
|
|
||||||
|
|
||||||
def maybe_leave(mode):
|
def maybe_leave(mode, reason=None):
|
||||||
"""Convenience method to leave 'mode' without exceptions."""
|
"""Convenience method to leave 'mode' without exceptions."""
|
||||||
try:
|
try:
|
||||||
instance().leave(mode)
|
instance().leave(mode, reason)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -177,16 +177,18 @@ class ModeManager(QObject):
|
|||||||
self.passthrough.append(mode)
|
self.passthrough.append(mode)
|
||||||
|
|
||||||
@cmdutils.register(instance='modeman', name='enter_mode', hide=True)
|
@cmdutils.register(instance='modeman', name='enter_mode', hide=True)
|
||||||
def enter(self, mode):
|
def enter(self, mode, reason=None):
|
||||||
"""Enter a new mode.
|
"""Enter a new mode.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
mode; The name of the mode to enter.
|
mode: The name of the mode to enter.
|
||||||
|
reason: Why the mode was entered.
|
||||||
|
|
||||||
Emit:
|
Emit:
|
||||||
entered: With the new mode name.
|
entered: With the new mode name.
|
||||||
"""
|
"""
|
||||||
logging.debug("Switching mode to {}".format(mode))
|
logging.debug("Entering mode {}{}".format(
|
||||||
|
mode, '' if reason is None else ' (reason: {})'.format(reason)))
|
||||||
if mode not in self._handlers:
|
if mode not in self._handlers:
|
||||||
raise ValueError("No handler for mode {}".format(mode))
|
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:
|
||||||
@ -196,11 +198,12 @@ class ModeManager(QObject):
|
|||||||
logging.debug("New mode stack: {}".format(self._mode_stack))
|
logging.debug("New mode stack: {}".format(self._mode_stack))
|
||||||
self.entered.emit(mode)
|
self.entered.emit(mode)
|
||||||
|
|
||||||
def leave(self, mode):
|
def leave(self, mode, reason=None):
|
||||||
"""Leave a mode.
|
"""Leave a mode.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
mode; The name of the mode to leave.
|
mode: The name of the mode to leave.
|
||||||
|
reason: Why the mode was left.
|
||||||
|
|
||||||
Emit:
|
Emit:
|
||||||
left: With the old mode name.
|
left: With the old mode name.
|
||||||
@ -209,8 +212,9 @@ class ModeManager(QObject):
|
|||||||
self._mode_stack.remove(mode)
|
self._mode_stack.remove(mode)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise ValueError("Mode {} not on mode stack!".format(mode))
|
raise ValueError("Mode {} not on mode stack!".format(mode))
|
||||||
logging.debug("Leaving mode {}".format(mode))
|
logging.debug("Leaving mode {}{}, new mode stack {}".format(
|
||||||
logging.debug("New mode stack: {}".format(self._mode_stack))
|
mode, '' if reason is None else ' (reason: {})'.format(reason),
|
||||||
|
self._mode_stack))
|
||||||
self.left.emit(mode)
|
self.left.emit(mode)
|
||||||
|
|
||||||
@cmdutils.register(instance='modeman', name='leave_mode',
|
@cmdutils.register(instance='modeman', name='leave_mode',
|
||||||
@ -219,7 +223,7 @@ class ModeManager(QObject):
|
|||||||
"""Leave the mode we're currently in."""
|
"""Leave the mode we're currently in."""
|
||||||
if self.mode == 'normal':
|
if self.mode == 'normal':
|
||||||
raise ValueError("Can't leave normal mode!")
|
raise ValueError("Can't leave normal mode!")
|
||||||
self.leave(self.mode)
|
self.leave(self.mode, 'leave current')
|
||||||
|
|
||||||
@pyqtSlot(str, str)
|
@pyqtSlot(str, str)
|
||||||
def on_config_changed(self, section, option):
|
def on_config_changed(self, section, option):
|
||||||
|
@ -344,7 +344,7 @@ class _Command(QLineEdit):
|
|||||||
}
|
}
|
||||||
text = self.text()
|
text = self.text()
|
||||||
self.history.append(text)
|
self.history.append(text)
|
||||||
modeman.leave("command")
|
modeman.leave('command', 'cmd accept')
|
||||||
if text[0] in signals:
|
if text[0] in signals:
|
||||||
signals[text[0]].emit(text.lstrip(text[0]))
|
signals[text[0]].emit(text.lstrip(text[0]))
|
||||||
|
|
||||||
@ -371,7 +371,7 @@ class _Command(QLineEdit):
|
|||||||
|
|
||||||
def focusInEvent(self, e):
|
def focusInEvent(self, e):
|
||||||
"""Extend focusInEvent to enter command mode."""
|
"""Extend focusInEvent to enter command mode."""
|
||||||
modeman.enter("command")
|
modeman.enter('command', 'cmd focus')
|
||||||
super().focusInEvent(e)
|
super().focusInEvent(e)
|
||||||
|
|
||||||
|
|
||||||
|
@ -89,7 +89,8 @@ class WebView(QWebView):
|
|||||||
self.page_.setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
|
self.page_.setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
|
||||||
self.page_.linkHovered.connect(self.linkHovered)
|
self.page_.linkHovered.connect(self.linkHovered)
|
||||||
self.linkClicked.connect(self.on_link_clicked)
|
self.linkClicked.connect(self.on_link_clicked)
|
||||||
self.loadStarted.connect(lambda: modeman.maybe_leave('insert'))
|
self.loadStarted.connect(
|
||||||
|
lambda: modeman.maybe_leave('insert', 'load started'))
|
||||||
self.loadFinished.connect(self.on_load_finished)
|
self.loadFinished.connect(self.on_load_finished)
|
||||||
# FIXME find some way to hide scrollbars without setScrollBarPolicy
|
# FIXME find some way to hide scrollbars without setScrollBarPolicy
|
||||||
|
|
||||||
@ -260,9 +261,9 @@ class WebView(QWebView):
|
|||||||
webelem.SELECTORS[webelem.Group.editable_focused])
|
webelem.SELECTORS[webelem.Group.editable_focused])
|
||||||
logging.debug("focus element: {}".format(not elem.isNull()))
|
logging.debug("focus element: {}".format(not elem.isNull()))
|
||||||
if elem.isNull():
|
if elem.isNull():
|
||||||
modeman.maybe_leave("insert")
|
modeman.maybe_leave('insert', 'load finished')
|
||||||
else:
|
else:
|
||||||
modeman.enter("insert")
|
modeman.enter('insert', 'load finished')
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def set_force_open_target(self, target):
|
def set_force_open_target(self, target):
|
||||||
@ -361,11 +362,11 @@ class WebView(QWebView):
|
|||||||
hitresult = frame.hitTestContent(pos)
|
hitresult = frame.hitTestContent(pos)
|
||||||
if self._is_editable(hitresult):
|
if self._is_editable(hitresult):
|
||||||
logging.debug("Clicked editable element!")
|
logging.debug("Clicked editable element!")
|
||||||
modeman.enter("insert")
|
modeman.enter('insert', 'click')
|
||||||
else:
|
else:
|
||||||
logging.debug("Clicked non-editable element!")
|
logging.debug("Clicked non-editable element!")
|
||||||
try:
|
try:
|
||||||
modeman.leave("insert")
|
modeman.leave('insert', 'click')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user