Fix search restriction behavior when switching libraries

This commit is contained in:
Kovid Goyal 2010-08-17 12:12:58 -06:00
commit 80a0725a0f
3 changed files with 16 additions and 14 deletions

View File

@ -382,8 +382,7 @@ class SearchBoxMixin(object):
class SavedSearchBoxMixin(object):
def __init__(self, db):
self.db = db
def __init__(self):
self.connect(self.saved_search, SIGNAL('changed()'), self.saved_searches_changed)
self.saved_searches_changed()
self.connect(self.clear_button, SIGNAL('clicked()'), self.saved_search.clear_to_help)
@ -402,10 +401,6 @@ class SavedSearchBoxMixin(object):
b = getattr(self, x+'_search_button')
b.setStatusTip(b.toolTip())
def set_database(self, db):
self.db = db
self.saved_searches_changed()
def saved_searches_changed(self):
p = saved_searches().names()
p.sort()
@ -415,13 +410,8 @@ class SavedSearchBoxMixin(object):
self.tags_view.recount()
for s in p:
self.search_restriction.addItem(s)
if t:
if t in p: # redo the current restriction, if there was one
self.search_restriction.setCurrentIndex(self.search_restriction.findText(t))
# self.tags_view.set_search_restriction(t)
else:
self.search_restriction.setCurrentIndex(0)
self.apply_search_restriction('')
if t: # redo the search restriction if there was one
self.apply_named_search_restriction(t)
def do_saved_search_edit(self, search):
d = SavedSearchEditor(self, search)

View File

@ -29,6 +29,16 @@ class SearchRestrictionMixin(object):
if self.restriction_in_effect:
self.set_number_of_books_shown()
def apply_named_search_restriction(self, name):
if not name:
r = 0
else:
r = self.search_restriction.findText(name)
if r < 0:
r = 0
self.search_restriction.setCurrentIndex(r)
self.apply_search_restriction(r)
def apply_search_restriction(self, i):
r = unicode(self.search_restriction.currentText())
if r is not None and r != '':

View File

@ -195,7 +195,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{
UpdateMixin.__init__(self, opts)
####################### Search boxes ########################
SavedSearchBoxMixin.__init__(self, db)
SavedSearchBoxMixin.__init__(self)
SearchBoxMixin.__init__(self)
####################### Library view ########################
@ -371,6 +371,8 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{
for action in self.iactions.values():
action.library_changed(db)
self.set_window_title()
self.apply_named_search_restriction('') # reset restriction to null
self.saved_searches_changed() # reload the search restrictions combo box
def set_window_title(self):
self.setWindowTitle(__appname__ + u' - ||%s||'%self.iactions['Choose Library'].library_name())