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,12 +55,13 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
hide_cmd = pyqtSignal()
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)
self._win_id = win_id
command_history = objreg.get('command-history')
self.history.history = command_history.data
self.history.changed.connect(command_history.changed)
if not private:
command_history = objreg.get('command-history')
self.history.history = command_history.data
self.history.changed.connect(command_history.changed)
self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Ignored)
self.cursorPositionChanged.connect(self.update_completion)
self.textChanged.connect(self.update_completion)

View File

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

View File

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