Fix statusbar text when entering insert mode via hints.

Before, hints cleaned the statusbar text delayed, clearing the "==== INSERT
MODE ====" in the statusbar.

Now we only reset the text if it wasn't changed.
This commit is contained in:
Florian Bruhin 2014-09-03 11:51:24 +02:00
parent 3e904f4c52
commit 71796e9528
4 changed files with 27 additions and 2 deletions

View File

@ -392,6 +392,8 @@ class Application(QApplication):
self.messagebridge.s_error.connect(status.disp_error) self.messagebridge.s_error.connect(status.disp_error)
self.messagebridge.s_info.connect(status.disp_temp_text) self.messagebridge.s_info.connect(status.disp_temp_text)
self.messagebridge.s_set_text.connect(status.set_text) self.messagebridge.s_set_text.connect(status.set_text)
self.messagebridge.s_maybe_reset_text.connect(
status.txt.maybe_reset_text)
self.messagebridge.s_set_cmd_text.connect(cmd.set_cmd_text) self.messagebridge.s_set_cmd_text.connect(cmd.set_cmd_text)
self.messagebridge.s_question.connect( self.messagebridge.s_question.connect(
status.prompt.prompter.ask_question, Qt.DirectConnection) status.prompt.prompter.ask_question, Qt.DirectConnection)

View File

@ -157,8 +157,9 @@ class HintManager(QObject):
for elem in self._context.elems.values(): for elem in self._context.elems.values():
if not elem.label.isNull(): if not elem.label.isNull():
elem.label.removeFromDocument() elem.label.removeFromDocument()
text = self.HINT_TEXTS[self._context.target]
message.instance().maybe_reset_text(text)
self._context = None self._context = None
message.instance().set_text('')
def _hint_strings(self, elems): def _hint_strings(self, elems):
"""Calculate the hint strings for elems. """Calculate the hint strings for elems.

View File

@ -136,6 +136,8 @@ class MessageBridge(QObject):
args: See s_error. args: See s_error.
s_set_text: Set a persistent text in the statusbar. s_set_text: Set a persistent text in the statusbar.
arg: The text to set. arg: The text to set.
s_maybe_reset_text: Reset the text if it hasn't been changed yet.
arg: The expected text.
s_set_cmd_text: Pre-set a text for the commandline prompt. s_set_cmd_text: Pre-set a text for the commandline prompt.
arg: The text to set. arg: The text to set.
@ -150,6 +152,7 @@ class MessageBridge(QObject):
s_error = pyqtSignal(str, bool) s_error = pyqtSignal(str, bool)
s_info = pyqtSignal(str, bool) s_info = pyqtSignal(str, bool)
s_set_text = pyqtSignal(str) s_set_text = pyqtSignal(str)
s_maybe_reset_text = pyqtSignal(str)
s_set_cmd_text = pyqtSignal(str) s_set_cmd_text = pyqtSignal(str)
s_question = pyqtSignal(usertypes.Question, bool) s_question = pyqtSignal(usertypes.Question, bool)
@ -215,6 +218,14 @@ class MessageBridge(QObject):
log.misc.debug(text) log.misc.debug(text)
self._emit_later(self.s_set_text, text) self._emit_later(self.s_set_text, text)
def maybe_reset_text(self, text):
"""Reset the text in the statusbar if it matches an expected text.
Args:
text: The expected text.
"""
self._emit_later(self.s_maybe_reset_text, str(text))
def ask(self, question, blocking): def ask(self, question, blocking):
"""Ask a question to the user. """Ask a question to the user.

View File

@ -23,7 +23,7 @@ from PyQt5.QtCore import pyqtSlot
from qutebrowser.config import config from qutebrowser.config import config
from qutebrowser.widgets.statusbar import textbase from qutebrowser.widgets.statusbar import textbase
from qutebrowser.utils import usertypes from qutebrowser.utils import usertypes, log
class Text(textbase.TextBase): class Text(textbase.TextBase):
@ -54,6 +54,8 @@ class Text(textbase.TextBase):
which: Which text to set, a self.Text instance. which: Which text to set, a self.Text instance.
text: The text to set. text: The text to set.
""" """
log.statusbar.debug("Setting {} text to '{}'.".format(
which.name, text))
if which is self.Text.normal: if which is self.Text.normal:
self._normaltext = text self._normaltext = text
elif which is self.Text.temp: elif which is self.Text.temp:
@ -64,6 +66,15 @@ class Text(textbase.TextBase):
raise ValueError("Invalid value {} for which!".format(which)) raise ValueError("Invalid value {} for which!".format(which))
self._update_text() self._update_text()
@pyqtSlot(str)
def maybe_reset_text(self, text):
"""Clear a normal text if it still matches an expected text."""
if self._normaltext == text:
log.misc.debug("Resetting: '{}'".format(text))
self.set_text(self.Text.normal, '')
else:
log.misc.debug("Ignoring reset: '{}'".format(text))
def _update_text(self): def _update_text(self):
"""Update QLabel text when needed.""" """Update QLabel text when needed."""
if self._temptext: if self._temptext: