mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Minor cleanup for previous PR
This commit is contained in:
parent
6895571de7
commit
cbf8ddd9e3
@ -451,33 +451,35 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
def _cached_notes_map(self, category):
|
def _cached_notes_map(self, category):
|
||||||
if self.notes_map is None:
|
if self.notes_map is None:
|
||||||
self.notes_map = {}
|
self.notes_map = {}
|
||||||
if category not in self.notes_map:
|
ans = self.notes_map.get(category)
|
||||||
|
if ans is None:
|
||||||
try:
|
try:
|
||||||
self.notes_map[category] = (self.db.new_api.get_all_items_that_have_notes(category),
|
self.notes_map[category] = ans = (self.db.new_api.get_all_items_that_have_notes(category),
|
||||||
self.db.new_api.get_item_name_map(category))
|
self.db.new_api.get_item_name_map(category))
|
||||||
except:
|
except Exception:
|
||||||
self.notes_map[category] = (frozenset(), {})
|
self.notes_map[category] = ans = (frozenset(), {})
|
||||||
return self.notes_map[category]
|
return ans
|
||||||
|
|
||||||
def _cached_link_map(self, category):
|
def _cached_link_map(self, category):
|
||||||
if self.link_map is None:
|
if self.link_map is None:
|
||||||
self.link_map = {}
|
self.link_map = {}
|
||||||
if category not in self.link_map:
|
ans = self.link_map.get(category)
|
||||||
|
if ans is None:
|
||||||
try:
|
try:
|
||||||
self.link_map[category] = self.db.new_api.get_link_map(category)
|
self.link_map[category] = ans = self.db.new_api.get_link_map(category)
|
||||||
except Exception:
|
except Exception:
|
||||||
self.link_map[category] = {}
|
self.link_map[category] = ans = {}
|
||||||
return self.link_map[category]
|
return ans
|
||||||
|
|
||||||
def category_has_notes(self, category):
|
def category_has_notes(self, category):
|
||||||
return len(self._cached_notes_map(category)[0]) > 0
|
return bool(self._cached_notes_map(category)[0])
|
||||||
|
|
||||||
def item_has_note(self, category, item_name):
|
def item_has_note(self, category, item_name):
|
||||||
notes_map, item_id_map = self._cached_notes_map(category)
|
notes_map, item_id_map = self._cached_notes_map(category)
|
||||||
return item_id_map.get(item_name) in notes_map
|
return item_id_map.get(item_name) in notes_map
|
||||||
|
|
||||||
def category_has_links(self, category):
|
def category_has_links(self, category):
|
||||||
return len(self._cached_link_map(category)) > 0
|
return bool(self._cached_link_map(category))
|
||||||
|
|
||||||
def item_has_link(self, category, item_name):
|
def item_has_link(self, category, item_name):
|
||||||
return item_name in self._cached_link_map(category)
|
return item_name in self._cached_link_map(category)
|
||||||
|
@ -881,7 +881,7 @@ class TagsView(QTreeView): # {{{
|
|||||||
|
|
||||||
if self.db.new_api.field_supports_notes(key):
|
if self.db.new_api.field_supports_notes(key):
|
||||||
item_id = self.db.new_api.get_item_id(tag.category, tag.original_name)
|
item_id = self.db.new_api.get_item_id(tag.category, tag.original_name)
|
||||||
has_note = self._model.item_has_note(key, tag.original_name) #bool(self.db.new_api.notes_for(tag.category, item_id))
|
has_note = self._model.item_has_note(key, tag.original_name)
|
||||||
self.context_menu.addAction(self.edit_metadata_icon,
|
self.context_menu.addAction(self.edit_metadata_icon,
|
||||||
(_('Edit note for %s') if has_note else _('Create note for %s'))%display_name(tag),
|
(_('Edit note for %s') if has_note else _('Create note for %s'))%display_name(tag),
|
||||||
partial(self.context_menu_handler, action='edit_note',
|
partial(self.context_menu_handler, action='edit_note',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user