Content server: Use the chapter title as the base bookmark name when creating new bookmarks. Fixes #1986786 [No automatic name for bookmark in web viewer](https://bugs.launchpad.net/calibre/+bug/1986786)

This commit is contained in:
Kovid Goyal 2022-09-01 08:30:53 +05:30
parent a845c54516
commit cf03b4e45b
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 23 additions and 9 deletions

View File

@ -161,9 +161,9 @@ class AnnotationsManager: # {{{
self.sync_annots_to_server('bookmarks')
return changed
def default_bookmark_title(self):
def default_bookmark_title(self, base_default_title):
all_titles = {bm.title:True for bm in self.bookmarks if not bm.removed}
base_default_title = _('Bookmark')
base_default_title = base_default_title or _('Bookmark')
c = 0
while True:
c += 1

View File

@ -9,6 +9,7 @@ from book_list.item_list import build_list, create_item, create_side_action
from dom import ensure_id, set_css
from modals import question_dialog
from widgets import create_button
from read_book.toc import get_book_mark_title
def goto_cfi(cfi, view):
@ -49,7 +50,8 @@ def create_bookmarks_list(annotations_manager, onclick):
def create_new_bookmark(annotations_manager, data):
title = window.prompt(_('Enter title for bookmark:'), data.selected_text or annotations_manager.default_bookmark_title())
base_default_title = get_book_mark_title() or _('Bookmark')
title = window.prompt(_('Enter title for bookmark:'), data.selected_text or annotations_manager.default_bookmark_title(base_default_title))
if not title:
return False
cfi = data.cfi

View File

@ -108,7 +108,7 @@ def get_current_toc_nodes():
return r
def get_highlighted_toc_nodes(toc, parent_map, id_map):
def get_highlighted_toc_nodes(toc, parent_map, id_map, skip_parents):
data = update_visible_toc_nodes.data
ans = {}
if data.has_visible:
@ -120,11 +120,12 @@ def get_highlighted_toc_nodes(toc, parent_map, id_map):
before = get_border_nodes(toc, id_map)[0]
if before:
ans[before.id] = True
for node_id in Object.keys(ans):
p = parent_map[node_id]
while p and p.title:
ans[p.id] = True
p = parent_map[p.id]
if not skip_parents:
for node_id in Object.keys(ans):
p = parent_map[node_id]
while p and p.title:
ans[p.id] = True
p = parent_map[p.id]
return ans
def get_toc_maps(toc):
@ -141,6 +142,17 @@ def get_toc_maps(toc):
process_node(toc)
return parent_map, id_map
def get_book_mark_title():
toc = current_book().manifest.toc
parent_map, id_map = get_toc_maps(toc)
highlighted_toc_nodes = get_highlighted_toc_nodes(toc, parent_map, id_map, True)
for node_id in Object.keys(highlighted_toc_nodes):
node = id_map[node_id]
if node.title:
return node.title
return ''
def create_toc_tree(toc, onclick):
parent_map, id_map = get_toc_maps(toc)
highlighted_toc_nodes = get_highlighted_toc_nodes(toc, parent_map, id_map)