Content server viewer: Allow editing bookmarks. Fixes #1966872 [[Enhancement] - Edit bookmarks](https://bugs.launchpad.net/calibre/+bug/1966872)

This commit is contained in:
Kovid Goyal 2022-03-29 13:41:45 +05:30
parent 19a9346296
commit 49fb93a5ff
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 20 additions and 1 deletions

View File

@ -150,6 +150,17 @@ class AnnotationsManager: # {{{
self.sync_annots_to_server('bookmarks') self.sync_annots_to_server('bookmarks')
return changed return changed
def edit_bookmark(self, title, new_title):
changed = False
for b in self.bookmarks:
if b.title is title:
b.title = new_title
b.timestamp = Date().toISOString()
changed = True
if changed:
self.sync_annots_to_server('bookmarks')
return changed
def default_bookmark_title(self): def default_bookmark_title(self):
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 = _('Bookmark')

View File

@ -23,6 +23,13 @@ def remove_bookmark(annotations_manager, title, list_dom_node):
) )
def edit_bookmark(annotations_manager, title, list_dom_node):
new_title = window.prompt(_('Enter new title for bookmark:'), title)
if new_title:
if annotations_manager.edit_bookmark(title, new_title):
console.log(list_dom_node)
list_dom_node.querySelector('.item-title').textContent = new_title
def create_bookmarks_list(annotations_manager, onclick): def create_bookmarks_list(annotations_manager, onclick):
bookmarks = sorted(annotations_manager.all_bookmarks(), key=def(x): return x.title.toLowerCase();) bookmarks = sorted(annotations_manager.all_bookmarks(), key=def(x): return x.title.toLowerCase();)
@ -30,10 +37,11 @@ def create_bookmarks_list(annotations_manager, onclick):
for bookmark in bookmarks: for bookmark in bookmarks:
if not bookmark.removed: if not bookmark.removed:
sa = create_side_action('trash', remove_bookmark.bind(None, annotations_manager, bookmark.title), _('Remove this bookmark')) sa = create_side_action('trash', remove_bookmark.bind(None, annotations_manager, bookmark.title), _('Remove this bookmark'))
ea = create_side_action('edit', edit_bookmark.bind(None, annotations_manager, bookmark.title), _('Edit this bookmark'))
items.push(create_item( items.push(create_item(
bookmark.title, data=bookmark.pos, bookmark.title, data=bookmark.pos,
action=onclick.bind(None, goto_cfi.bind(None, bookmark.pos)), action=onclick.bind(None, goto_cfi.bind(None, bookmark.pos)),
side_actions=[sa] side_actions=[sa, ea]
)) ))
c = E.div(style='margin-top: 1ex') c = E.div(style='margin-top: 1ex')
build_list(c, items) build_list(c, items)