mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Notes should be rendered the same way in the viewer highlights panel and the browse annotations details panel
This commit is contained in:
parent
eb7bdaca4e
commit
c82c7d1a27
@ -19,6 +19,19 @@ from calibre.gui2.viewer.widgets import ResultsDelegate, SearchBox
|
||||
from calibre.gui2.widgets2 import Dialog
|
||||
|
||||
|
||||
def render_notes(notes, tag='p'):
|
||||
current_lines = []
|
||||
for line in notes.splitlines():
|
||||
if line:
|
||||
current_lines.append(line)
|
||||
else:
|
||||
if current_lines:
|
||||
yield '<{0}>{1}</{0}>'.format(tag, '\n'.join(current_lines))
|
||||
current_lines = []
|
||||
if current_lines:
|
||||
yield '<{0}>{1}</{0}>'.format(tag, '\n'.join(current_lines))
|
||||
|
||||
|
||||
def friendly_username(user_type, user):
|
||||
key = user_type, user
|
||||
if key == ('web', '*'):
|
||||
@ -459,16 +472,7 @@ class DetailsPanel(QWidget):
|
||||
notes = annot.get('notes')
|
||||
if notes:
|
||||
p(_('Notes'), 'h4')
|
||||
current_lines = []
|
||||
for line in notes.splitlines():
|
||||
if line:
|
||||
current_lines.append(line)
|
||||
else:
|
||||
if current_lines:
|
||||
p('\n'.join(current_lines))
|
||||
current_lines = []
|
||||
if current_lines:
|
||||
p('\n'.join(current_lines))
|
||||
paras.extend(render_notes(notes))
|
||||
|
||||
annot_text += '\n'.join(paras)
|
||||
date = QDateTime.fromString(annot['timestamp'], Qt.ISODate).toLocalTime().toString(Qt.SystemLocaleShortDate)
|
||||
|
@ -15,7 +15,7 @@ from PyQt5.Qt import (
|
||||
from calibre.constants import plugins
|
||||
from calibre.ebooks.epub.cfi.parse import cfi_sort_key
|
||||
from calibre.gui2 import choose_save_file, error_dialog, question_dialog
|
||||
from calibre.gui2.library.annotations import Details
|
||||
from calibre.gui2.library.annotations import Details, render_notes
|
||||
from calibre.gui2.viewer.config import vprefs
|
||||
from calibre.gui2.viewer.search import SearchInput
|
||||
from calibre.gui2.viewer.shortcuts import index_to_key_sequence
|
||||
@ -226,6 +226,7 @@ class NotesDisplay(QWidget):
|
||||
h.setContentsMargins(0, 0, 0, 0)
|
||||
self.browser = nd = Details(self)
|
||||
h.addWidget(nd)
|
||||
self.current_notes = ''
|
||||
self.edit_button = eb = QToolButton(self)
|
||||
eb.setIcon(QIcon(I('modified.png')))
|
||||
eb.setToolTip(_('Edit the notes for this highlight'))
|
||||
@ -235,13 +236,14 @@ class NotesDisplay(QWidget):
|
||||
def show_notes(self, text=''):
|
||||
text = (text or '').strip()
|
||||
self.setVisible(bool(text))
|
||||
self.browser.setPlainText(text)
|
||||
self.current_notes = text
|
||||
self.browser.setHtml('\n'.join(render_notes(text)))
|
||||
h = self.browser.document().size().height() + 8
|
||||
self.browser.setMaximumHeight(h)
|
||||
self.setMaximumHeight(max(self.edit_button.sizeHint().height() + 4, h))
|
||||
|
||||
def edit_notes(self):
|
||||
current_text = self.browser.toPlainText()
|
||||
current_text = self.current_notes
|
||||
d = NotesEditDialog(current_text, self)
|
||||
if d.exec_() == d.Accepted and d.notes != current_text:
|
||||
self.notes_edited.emit(d.notes)
|
||||
|
Loading…
x
Reference in New Issue
Block a user