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')
|
self.sync_annots_to_server('bookmarks')
|
||||||
return changed
|
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}
|
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
|
c = 0
|
||||||
while True:
|
while True:
|
||||||
c += 1
|
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 dom import ensure_id, set_css
|
||||||
from modals import question_dialog
|
from modals import question_dialog
|
||||||
from widgets import create_button
|
from widgets import create_button
|
||||||
|
from read_book.toc import get_book_mark_title
|
||||||
|
|
||||||
|
|
||||||
def goto_cfi(cfi, view):
|
def goto_cfi(cfi, view):
|
||||||
@ -49,7 +50,8 @@ def create_bookmarks_list(annotations_manager, onclick):
|
|||||||
|
|
||||||
|
|
||||||
def create_new_bookmark(annotations_manager, data):
|
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:
|
if not title:
|
||||||
return False
|
return False
|
||||||
cfi = data.cfi
|
cfi = data.cfi
|
||||||
|
@ -108,7 +108,7 @@ def get_current_toc_nodes():
|
|||||||
return r
|
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
|
data = update_visible_toc_nodes.data
|
||||||
ans = {}
|
ans = {}
|
||||||
if data.has_visible:
|
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]
|
before = get_border_nodes(toc, id_map)[0]
|
||||||
if before:
|
if before:
|
||||||
ans[before.id] = True
|
ans[before.id] = True
|
||||||
for node_id in Object.keys(ans):
|
if not skip_parents:
|
||||||
p = parent_map[node_id]
|
for node_id in Object.keys(ans):
|
||||||
while p and p.title:
|
p = parent_map[node_id]
|
||||||
ans[p.id] = True
|
while p and p.title:
|
||||||
p = parent_map[p.id]
|
ans[p.id] = True
|
||||||
|
p = parent_map[p.id]
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
def get_toc_maps(toc):
|
def get_toc_maps(toc):
|
||||||
@ -141,6 +142,17 @@ def get_toc_maps(toc):
|
|||||||
process_node(toc)
|
process_node(toc)
|
||||||
return parent_map, id_map
|
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):
|
def create_toc_tree(toc, onclick):
|
||||||
parent_map, id_map = get_toc_maps(toc)
|
parent_map, id_map = get_toc_maps(toc)
|
||||||
highlighted_toc_nodes = get_highlighted_toc_nodes(toc, parent_map, id_map)
|
highlighted_toc_nodes = get_highlighted_toc_nodes(toc, parent_map, id_map)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user