E-book viewer: When suggesting a default bookmark title, use the name of the current chapter. Fixes #1851908 [Suggest a name for the bookmark](https://bugs.launchpad.net/calibre/+bug/1851908)

This commit is contained in:
Kovid Goyal 2021-04-25 20:56:46 +05:30
parent 281ff268f8
commit 5f927e2ea0
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 8 additions and 2 deletions

View File

@ -92,6 +92,7 @@ class BookmarkManager(QWidget):
self.l = l = QGridLayout(self)
l.setContentsMargins(0, 0, 0, 0)
self.setLayout(l)
self.toc = parent.toc
self.bookmarks_list = bl = BookmarksList(self)
bl.itemChanged.connect(self.item_changed)
@ -340,7 +341,7 @@ class BookmarkManager(QWidget):
import_current_bookmarks(imported)
def create_new_bookmark(self, pos_data):
base_default_title = _('Bookmark')
base_default_title = self.toc.model().title_for_current_node or _('Bookmark')
all_titles = {bm['title'] for bm in self.get_bookmarks()}
c = 0
while True:

View File

@ -227,7 +227,6 @@ class TOC(QStandardItemModel):
for t in toc['children']:
self.appendRow(TOCItem(t, 0, depth_first, normal_font, emphasis_font))
self.node_id_map = {x.node_id: x for x in self.all_items}
self.currently_viewed_entry = None
def find_items(self, query):
for item in self.all_items:
@ -284,6 +283,12 @@ class TOC(QStandardItemModel):
def viewed_nodes(self):
return tuple(node for node in self.all_items if node.is_being_viewed)
@property
def title_for_current_node(self):
for node in reversed(self.all_items):
if node.is_being_viewed:
return node.title
@property
def as_plain_text(self):
lines = []