Have an isolated command history for private windows

This commit is contained in:
Florian Bruhin 2017-04-30 00:21:22 +02:00
parent c6e31391de
commit f907b6b6b0
3 changed files with 8 additions and 11 deletions

View File

@ -55,9 +55,10 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
hide_cmd = pyqtSignal() hide_cmd = pyqtSignal()
def __init__(self, *, win_id, private, parent=None): def __init__(self, *, win_id, private, parent=None):
misc.CommandLineEdit.__init__(self, private=private, parent=parent) misc.CommandLineEdit.__init__(self, parent=parent)
misc.MinimalLineEditMixin.__init__(self) misc.MinimalLineEditMixin.__init__(self)
self._win_id = win_id self._win_id = win_id
if not private:
command_history = objreg.get('command-history') command_history = objreg.get('command-history')
self.history.history = command_history.data self.history.history = command_history.data
self.history.changed.connect(command_history.changed) self.history.changed.connect(command_history.changed)

View File

@ -45,7 +45,6 @@ class History(QObject):
Attributes: Attributes:
history: A list of executed commands, with newer commands at the end. history: A list of executed commands, with newer commands at the end.
_tmphist: Temporary history for history browsing (as NeighborList) _tmphist: Temporary history for history browsing (as NeighborList)
_private: Whether this history is in private browsing mode.
Signals: Signals:
changed: Emitted when an entry was added to the history. changed: Emitted when an entry was added to the history.
@ -53,7 +52,7 @@ class History(QObject):
changed = pyqtSignal() changed = pyqtSignal()
def __init__(self, *, private=False, history=None, parent=None): def __init__(self, *, history=None, parent=None):
"""Constructor. """Constructor.
Args: Args:
@ -61,7 +60,6 @@ class History(QObject):
""" """
super().__init__(parent) super().__init__(parent)
self._tmphist = None self._tmphist = None
self._private = private
if history is None: if history is None:
self.history = [] self.history = []
else: else:
@ -128,8 +126,6 @@ class History(QObject):
Args: Args:
text: The text to append. text: The text to append.
""" """
if self._private:
return
if not self.history or text != self.history[-1]: if not self.history or text != self.history[-1]:
self.history.append(text) self.history.append(text)
self.changed.emit() self.changed.emit()

View File

@ -69,9 +69,9 @@ class CommandLineEdit(QLineEdit):
_promptlen: The length of the current prompt. _promptlen: The length of the current prompt.
""" """
def __init__(self, *, private=False, parent=None): def __init__(self, *, parent=None):
super().__init__(parent) super().__init__(parent)
self.history = cmdhistory.History(private=private, parent=self) self.history = cmdhistory.History(parent=self)
self._validator = _CommandValidator(self) self._validator = _CommandValidator(self)
self.setValidator(self._validator) self.setValidator(self._validator)
self.textEdited.connect(self.on_text_edited) self.textEdited.connect(self.on_text_edited)