remember search history

This commit is contained in:
Damien Elmes 2011-04-18 03:59:40 +09:00
parent dd0a6563e7
commit 612fefc347
2 changed files with 13 additions and 0 deletions

View file

@ -424,10 +424,22 @@ class Browser(QMainWindow):
SIGNAL("returnPressed()"), SIGNAL("returnPressed()"),
self.onSearch) self.onSearch)
self.setTabOrder(self.form.searchEdit, self.form.tableView) self.setTabOrder(self.form.searchEdit, self.form.tableView)
self.compModel = QStringListModel()
self.compModel.setStringList(QStringList(self.mw.config['searchHistory']))
self.searchComp = QCompleter(self.compModel, self.form.searchEdit)
self.searchComp.setCompletionMode(QCompleter.UnfilteredPopupCompletion)
self.searchComp.setCaseSensitivity(Qt.CaseInsensitive)
self.form.searchEdit.setCompleter(self.searchComp)
def onSearch(self, reset=True): def onSearch(self, reset=True):
"Careful: if reset is true, the current fact is saved." "Careful: if reset is true, the current fact is saved."
txt = unicode(self.form.searchEdit.text()).strip() txt = unicode(self.form.searchEdit.text()).strip()
sh = self.mw.config['searchHistory']
if txt not in sh:
sh.insert(0, txt)
sh = sh[:30]
self.compModel.setStringList(QStringList(sh))
self.mw.config['searchHistory'] = sh
self.model.search(txt, reset) self.model.search(txt, reset)
if not self.model.cards: if not self.model.cards:
# no row change will fire # no row change will fire

View file

@ -24,6 +24,7 @@ defaultConf = {
'fullSearch': False, 'fullSearch': False,
'autoplaySounds': True, 'autoplaySounds': True,
'searchHistory': [],
'checkForUpdates': True, 'checkForUpdates': True,
'created': time.time(), 'created': time.time(),
'deleteMedia': False, 'deleteMedia': False,