mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
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:
parent
a845c54516
commit
cf03b4e45b
@ -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
|
||||
|
@ -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
|
||||
|
@ -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,6 +120,7 @@ def get_highlighted_toc_nodes(toc, parent_map, id_map):
|
||||
before = get_border_nodes(toc, id_map)[0]
|
||||
if before:
|
||||
ans[before.id] = True
|
||||
if not skip_parents:
|
||||
for node_id in Object.keys(ans):
|
||||
p = parent_map[node_id]
|
||||
while p and p.title:
|
||||
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user