Remember no more than 100 search expressions in the history

This commit is contained in:
Kovid Goyal 2014-03-18 09:37:42 +05:30
parent 0301890d59
commit 16c3101490
2 changed files with 6 additions and 0 deletions

View File

@ -27,6 +27,8 @@ class PushButton(QPushButton):
class HistoryLineEdit(HistoryLineEdit2): class HistoryLineEdit(HistoryLineEdit2):
max_history_items = 100
def __init__(self, parent, clear_msg): def __init__(self, parent, clear_msg):
HistoryLineEdit2.__init__(self, parent) HistoryLineEdit2.__init__(self, parent)
self.disable_popup = tprefs['disable_completion_popup_for_search'] self.disable_popup = tprefs['disable_completion_popup_for_search']

View File

@ -11,6 +11,8 @@ from calibre.gui2.widgets import history
class HistoryLineEdit2(LineEdit): class HistoryLineEdit2(LineEdit):
max_history_items = None
@property @property
def store_name(self): def store_name(self):
return 'lineedit_history_'+self._name return 'lineedit_history_'+self._name
@ -31,6 +33,8 @@ class HistoryLineEdit2(LineEdit):
except ValueError: except ValueError:
pass pass
self.history.insert(0, ct) self.history.insert(0, ct)
if self.max_history_items is not None:
del self.history[self.max_history_items:]
history.set(self.store_name, self.history) history.set(self.store_name, self.history)
self.update_items_cache(self.history) self.update_items_cache(self.history)