Fix first added saved search not appearing in Tag browser until calibre restart. Fixes #1733151 [Suggestions to the Configure menu of the Tag browser](https://bugs.launchpad.net/calibre/+bug/1733151)

This commit is contained in:
Kovid Goyal 2017-11-29 17:44:02 +05:30
parent 043ea2d905
commit 5704585544
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 10 additions and 4 deletions

View File

@ -161,6 +161,11 @@ class Cache(object):
will happen.'''
return SafeReadLock(self.read_lock)
@write_api
def ensure_has_search_category(self, fail_on_existing=True):
if len(self._search_api.saved_searches.names()) > 0:
self.field_metadata.add_search_category(label='search', name=_('Searches'), fail_on_existing=fail_on_existing)
def _initialize_dynamic_categories(self):
# Reconstruct the user categories, putting them into field_metadata
fm = self.field_metadata
@ -184,9 +189,7 @@ class Cache(object):
self.field_metadata.add_user_category(label=u'@' + cat, name=cat)
except ValueError:
traceback.print_exc()
if len(self._search_api.saved_searches.names()) > 0:
self.field_metadata.add_search_category(label='search', name=_('Searches'))
self._ensure_has_search_category()
self.field_metadata.add_grouped_search_terms(
self._pref('grouped_search_terms', {}))

View File

@ -605,6 +605,7 @@ class SavedSearchBoxMixin(object): # {{{
from calibre.gui2.dialogs.saved_search_editor import AddSavedSearch
d = AddSavedSearch(parent=self, search=self.search.current_text)
if d.exec_() == d.Accepted:
self.current_db.new_api.ensure_has_search_category(fail_on_existing=False)
self.do_rebuild_saved_searches()
def get_saved_search_text(self):

View File

@ -628,8 +628,10 @@ class FieldMetadata(object):
'is_category':True, 'is_csp': False}
self._add_search_terms_to_map(label, st)
def add_search_category(self, label, name):
def add_search_category(self, label, name, fail_on_existing=True):
if label in self._tb_cats:
if not fail_on_existing:
return
raise ValueError('Duplicate user field [%s]'%(label))
self._tb_cats[label] = {'table':None, 'column':None,
'datatype':None, 'is_multiple':{},