From 580a6856330137114591e57fb28d881f5dba4112 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 22 Jan 2020 10:44:38 +0530 Subject: [PATCH] Save bookmarks in config folder when edited so they are not lost on crash --- src/calibre/gui2/viewer/ui.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/viewer/ui.py b/src/calibre/gui2/viewer/ui.py index 332e13727a..17586dca85 100644 --- a/src/calibre/gui2/viewer/ui.py +++ b/src/calibre/gui2/viewer/ui.py @@ -279,6 +279,8 @@ class EbookViewer(MainWindow): def bookmarks_edited(self, bookmarks): self.current_book_data['annotations_map']['bookmark'] = bookmarks + # annotations will be saved in book file on exit + self.save_annotations(in_book_file=False) def bookmark_activated(self, cfi): self.web_view.goto_cfi(cfi) @@ -507,14 +509,14 @@ class EbookViewer(MainWindow): # }}} # State serialization {{{ - def save_annotations(self): + def save_annotations(self, in_book_file=True): if not self.current_book_data: return amap = self.current_book_data['annotations_map'] annots = as_bytes(serialize_annotations(amap)) with open(os.path.join(annotations_dir, self.current_book_data['annotations_path_key']), 'wb') as f: f.write(annots) - if self.current_book_data.get('pathtoebook', '').lower().endswith( + if in_book_file and self.current_book_data.get('pathtoebook', '').lower().endswith( '.epub') and get_session_pref('save_annotations_in_ebook', default=True): path = self.current_book_data['pathtoebook'] if os.access(path, os.W_OK):