Add a button ot the search preferences to clear search history. Fixes #8953 (Clear search items)

This commit is contained in:
Kovid Goyal 2011-02-13 10:09:21 -07:00
parent e7ba694110
commit 3cc6dc480a
3 changed files with 20 additions and 0 deletions

View File

@ -26,12 +26,19 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
r('limit_search_columns_to', prefs, setting=CommaSeparatedList) r('limit_search_columns_to', prefs, setting=CommaSeparatedList)
fl = gui.library_view.model().db.field_metadata.get_search_terms() fl = gui.library_view.model().db.field_metadata.get_search_terms()
self.opt_limit_search_columns_to.update_items_cache(fl) self.opt_limit_search_columns_to.update_items_cache(fl)
self.clear_history_button.clicked.connect(self.clear_histories)
def refresh_gui(self, gui): def refresh_gui(self, gui):
gui.search.search_as_you_type(config['search_as_you_type']) gui.search.search_as_you_type(config['search_as_you_type'])
gui.library_view.model().set_highlight_only(config['highlight_search_matches']) gui.library_view.model().set_highlight_only(config['highlight_search_matches'])
gui.search.do_search() gui.search.do_search()
def clear_histories(self, *args):
for key, val in config.defaults.iteritems():
if key.endswith('_search_history') and isinstance(val, list):
config[key] = []
self.gui.search.clear_history()
if __name__ == '__main__': if __name__ == '__main__':
app = QApplication([]) app = QApplication([])
test_widget('Interface', 'Search') test_widget('Interface', 'Search')

View File

@ -90,6 +90,16 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="4" column="0">
<widget class="QPushButton" name="clear_history_button">
<property name="toolTip">
<string>Clear search histories from all over calibre. Including the book list, e-book viewer, fetch news dialog, etc.</string>
</property>
<property name="text">
<string>Clear search &amp;histories</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>

View File

@ -114,6 +114,9 @@ class SearchBox2(QComboBox): # {{{
def text(self): def text(self):
return self.currentText() return self.currentText()
def clear_history(self, *args):
QComboBox.clear(self)
def clear(self, emit_search=True): def clear(self, emit_search=True):
self.normalize_state() self.normalize_state()
self.setEditText('') self.setEditText('')