mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Viewer: handle editing of missing highlights more gracefully
Fixes #1900358 [ebook-viewer Reapplying missing annotation highlight after modifying ePub](https://bugs.launchpad.net/calibre/+bug/1900358)
This commit is contained in:
parent
9c1e6ccb03
commit
95abe9d072
@ -780,6 +780,8 @@ class IframeBoss:
|
|||||||
window.setTimeout(def():
|
window.setTimeout(def():
|
||||||
self.send_message('annotations', type='edit-highlight')
|
self.send_message('annotations', type='edit-highlight')
|
||||||
, 50)
|
, 50)
|
||||||
|
else:
|
||||||
|
self.send_message('annotations', type='edit-highlight-failed', uuid=data.uuid)
|
||||||
elif dtype is 'notes-edited':
|
elif dtype is 'notes-edited':
|
||||||
cls = 'crw-has-dot'
|
cls = 'crw-has-dot'
|
||||||
crw_ = {v: k for k, v in Object.entries(annot_id_uuid_map)}[data.uuid]
|
crw_ = {v: k for k, v in Object.entries(annot_id_uuid_map)}[data.uuid]
|
||||||
|
@ -9,11 +9,12 @@ from uuid import short_uuid
|
|||||||
from book_list.globals import get_session_data
|
from book_list.globals import get_session_data
|
||||||
from book_list.theme import get_color
|
from book_list.theme import get_color
|
||||||
from dom import change_icon_image, clear, svgicon, unique_id
|
from dom import change_icon_image, clear, svgicon, unique_id
|
||||||
from modals import error_dialog, question_dialog
|
from modals import error_dialog, question_dialog, create_custom_dialog
|
||||||
from read_book.globals import runtime, ui_operations
|
from read_book.globals import runtime, ui_operations
|
||||||
from read_book.highlights import (
|
from read_book.highlights import (
|
||||||
ICON_SIZE, EditNotesAndColors, HighlightStyle, all_styles, render_notes
|
ICON_SIZE, EditNotesAndColors, HighlightStyle, all_styles, render_notes
|
||||||
)
|
)
|
||||||
|
from widgets import create_button
|
||||||
from read_book.shortcuts import shortcut_for_key_event
|
from read_book.shortcuts import shortcut_for_key_event
|
||||||
from read_book.toc import get_toc_nodes_bordering_spine_item, family_for_toc_node
|
from read_book.toc import get_toc_nodes_bordering_spine_item, family_for_toc_node
|
||||||
|
|
||||||
@ -573,6 +574,37 @@ class SelectionBar:
|
|||||||
self.new_bookmark()
|
self.new_bookmark()
|
||||||
elif sc_name is 'toggle_highlights':
|
elif sc_name is 'toggle_highlights':
|
||||||
self.view.on_handle_shortcut({'name': sc_name})
|
self.view.on_handle_shortcut({'name': sc_name})
|
||||||
|
|
||||||
|
def report_failed_edit_highlight(self, annot_id):
|
||||||
|
notes = self.annotations_manager.notes_for_highlight(annot_id)
|
||||||
|
has_notes = bool(notes)
|
||||||
|
title = _('Highlight text missing')
|
||||||
|
text = _(
|
||||||
|
'The text associated with this highlight could not be found in the book.'
|
||||||
|
' This can happen if the book was modified. This highlight will be automatically removed.'
|
||||||
|
)
|
||||||
|
if runtime.is_standalone_viewer or not has_notes:
|
||||||
|
if has_notes:
|
||||||
|
ui_operations.copy_selection(notes)
|
||||||
|
text += ' ' + _('The notes for this highlight have been copied to the clipboard.')
|
||||||
|
error_dialog(title, text)
|
||||||
|
else:
|
||||||
|
create_custom_dialog(title, def (parent, close_modal):
|
||||||
|
parent.appendChild(E.div(
|
||||||
|
E.div(text),
|
||||||
|
E.div(
|
||||||
|
class_='button-box',
|
||||||
|
create_button(
|
||||||
|
_('Copy notes to clipboard'), None, def():
|
||||||
|
ui_operations.copy_selection(notes)
|
||||||
|
close_modal()
|
||||||
|
, highlight=True),
|
||||||
|
'\xa0',
|
||||||
|
create_button(_('OK'), None, close_modal),
|
||||||
|
)
|
||||||
|
))
|
||||||
|
)
|
||||||
|
self.remove_highlight_with_id(annot_id)
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# drag scroll {{{
|
# drag scroll {{{
|
||||||
@ -992,6 +1024,8 @@ class SelectionBar:
|
|||||||
elif msg.type is 'edit-highlight':
|
elif msg.type is 'edit-highlight':
|
||||||
if self.state is WAITING:
|
if self.state is WAITING:
|
||||||
self.create_highlight()
|
self.create_highlight()
|
||||||
|
elif msg.type is 'edit-highlight-failed':
|
||||||
|
self.report_failed_edit_highlight(msg.uuid)
|
||||||
elif msg.type is 'double-click':
|
elif msg.type is 'double-click':
|
||||||
self.last_double_click_at = window.performance.now()
|
self.last_double_click_at = window.performance.now()
|
||||||
else:
|
else:
|
||||||
|
@ -1320,6 +1320,8 @@ class View:
|
|||||||
spine = self.book.manifest.spine
|
spine = self.book.manifest.spine
|
||||||
spine_index = self.annotations_manager.spine_index_for_highlight(uuid, spine)
|
spine_index = self.annotations_manager.spine_index_for_highlight(uuid, spine)
|
||||||
if spine_index < 0 or spine_index >= spine.length:
|
if spine_index < 0 or spine_index >= spine.length:
|
||||||
|
if which is 'edit':
|
||||||
|
self.selection_bar.report_failed_edit_highlight(uuid)
|
||||||
return
|
return
|
||||||
if which is 'edit':
|
if which is 'edit':
|
||||||
if self.currently_showing.spine_index is spine_index:
|
if self.currently_showing.spine_index is spine_index:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user