mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Implement #6450 (Bookmarks in Calibre's Viewer)
This commit is contained in:
parent
5b1d98aba9
commit
31db5a16dd
@ -173,6 +173,7 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
||||
self.pending_anchor = None
|
||||
self.pending_reference = None
|
||||
self.pending_bookmark = None
|
||||
self.existing_bookmarks= []
|
||||
self.selected_text = None
|
||||
self.read_settings()
|
||||
self.dictionary_box.hide()
|
||||
@ -415,15 +416,6 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
||||
self.action_font_size_smaller.setEnabled(self.view.multiplier() > 0.2)
|
||||
self.set_page_number(frac)
|
||||
|
||||
def bookmark(self, *args):
|
||||
title, ok = QInputDialog.getText(self, _('Add bookmark'), _('Enter title for bookmark:'))
|
||||
title = unicode(title).strip()
|
||||
if ok and title:
|
||||
pos = self.view.bookmark()
|
||||
bookmark = '%d#%s'%(self.current_index, pos)
|
||||
self.iterator.add_bookmark((title, bookmark))
|
||||
self.set_bookmarks(self.iterator.bookmarks)
|
||||
|
||||
|
||||
def find(self, text, repeat=False, backwards=False):
|
||||
if not text:
|
||||
@ -539,15 +531,34 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
||||
getattr(self, o).setEnabled(False)
|
||||
self.setCursor(Qt.BusyCursor)
|
||||
|
||||
def bookmark(self, *args):
|
||||
num = 1
|
||||
bm = None
|
||||
while True:
|
||||
bm = _('Bookmark #%d')%num
|
||||
if bm not in self.existing_bookmarks:
|
||||
break
|
||||
num += 1
|
||||
title, ok = QInputDialog.getText(self, _('Add bookmark'),
|
||||
_('Enter title for bookmark:'), text=bm)
|
||||
title = unicode(title).strip()
|
||||
if ok and title:
|
||||
pos = self.view.bookmark()
|
||||
bookmark = '%d#%s'%(self.current_index, pos)
|
||||
self.iterator.add_bookmark((title, bookmark))
|
||||
self.set_bookmarks(self.iterator.bookmarks)
|
||||
|
||||
def set_bookmarks(self, bookmarks):
|
||||
self.bookmarks_menu.clear()
|
||||
self.bookmarks_menu.addAction(_("Manage Bookmarks"), self.manage_bookmarks)
|
||||
self.bookmarks_menu.addSeparator()
|
||||
current_page = None
|
||||
self.existing_bookmarks = []
|
||||
for bm in bookmarks:
|
||||
if bm[0] == 'calibre_current_page_bookmark':
|
||||
current_page = bm
|
||||
else:
|
||||
self.existing_bookmarks.append(bm[0])
|
||||
self.bookmarks_menu.addAction(bm[0], partial(self.goto_bookmark, bm))
|
||||
return current_page
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user