From a32a1e6f794565f6c4cc046ae08165f5db2e229c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 13 Mar 2014 08:30:00 +0530 Subject: [PATCH] Add an action to clear search history as well as disabling the popup --- src/calibre/gui2/tweak_book/search.py | 12 +++++++----- src/calibre/gui2/widgets2.py | 5 +++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/tweak_book/search.py b/src/calibre/gui2/tweak_book/search.py index 6988aa5912..ca29189046 100644 --- a/src/calibre/gui2/tweak_book/search.py +++ b/src/calibre/gui2/tweak_book/search.py @@ -27,15 +27,17 @@ class PushButton(QPushButton): class HistoryLineEdit(HistoryLineEdit2): - def __init__(self, parent): + def __init__(self, parent, clear_msg): HistoryLineEdit2.__init__(self, parent) self.disable_popup = tprefs['disable_completion_popup_for_search'] + self.clear_msg = clear_msg def contextMenuEvent(self, event): menu = self.createStandardContextMenu() menu.addSeparator() - menu.addAction((_('Show completion based on search history') if self.disable_popup else _( - 'Hide completion based on search history')), self.toggle_popups) + menu.addAction(self.clear_msg, self.clear_history) + menu.addAction((_('Enable completion based on search history') if self.disable_popup else _( + 'Disable completion based on search history')), self.toggle_popups) menu.exec_(event.globalPos()) def toggle_popups(self): @@ -63,7 +65,7 @@ class SearchWidget(QWidget): self.fl = fl = QLabel(_('&Find:')) fl.setAlignment(Qt.AlignRight | Qt.AlignCenter) - self.find_text = ft = HistoryLineEdit(self) + self.find_text = ft = HistoryLineEdit(self, _('Clear search history')) ft.initialize('tweak_book_find_edit') ft.returnPressed.connect(lambda : self.search_triggered.emit('find')) fl.setBuddy(ft) @@ -72,7 +74,7 @@ class SearchWidget(QWidget): self.rl = rl = QLabel(_('&Replace:')) rl.setAlignment(Qt.AlignRight | Qt.AlignCenter) - self.replace_text = rt = HistoryLineEdit(self) + self.replace_text = rt = HistoryLineEdit(self, _('Clear replace history')) rt.initialize('tweak_book_replace_edit') rl.setBuddy(rt) l.addWidget(rl, 1, 0) diff --git a/src/calibre/gui2/widgets2.py b/src/calibre/gui2/widgets2.py index c53ae2e93f..3a52d72078 100644 --- a/src/calibre/gui2/widgets2.py +++ b/src/calibre/gui2/widgets2.py @@ -34,3 +34,8 @@ class HistoryLineEdit2(LineEdit): history.set(self.store_name, self.history) self.update_items_cache(self.history) + def clear_history(self): + self.history = [] + history.set(self.store_name, self.history) + self.update_items_cache(self.history) +