Removing of highlights works

This commit is contained in:
Kovid Goyal 2020-05-12 17:07:39 +05:30
parent 2c45544a16
commit 501ee2252c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 34 additions and 3 deletions

View File

@ -44,12 +44,25 @@ class Highlights(QListWidget):
pi = plugins['progress_indicator'][0]
pi.set_no_activate_on_click(self)
self.itemActivated.connect(self.item_activated)
self.uuid_map = {}
def load(self, highlights):
self.clear()
self.uuid_map = {}
for h in highlights or ():
i = QListWidgetItem(h['highlighted_text'], self)
i.setData(Qt.UserRole, h)
txt = h.get('highlighted_text')
if not h.get('removed') and txt:
i = QListWidgetItem(txt, self)
i.setData(Qt.UserRole, h)
self.uuid_map[h['uuid']] = self.count() - 1
def refresh(self, highlights):
h = self.current_highlight
self.load(highlights)
if h is not None:
idx = self.uuid_map.get(h['uuid'])
if idx is not None:
self.set_current_row(idx)
def find_query(self, query):
cr = self.currentRow()
@ -106,6 +119,7 @@ class HighlightsPanel(QWidget):
l.addWidget(h)
h.jump_to_highlight.connect(self.jump_to_highlight)
self.load = h.load
self.refresh = h.refresh
self.h = h = QHBoxLayout()
l.addLayout(h)

View File

@ -595,6 +595,7 @@ class EbookViewer(MainWindow):
h['timestamp'] = parse_iso8601(h['timestamp'], assume_utc=True)
amap = self.current_book_data['annotations_map']
amap['highlight'] = highlights
self.highlights_widget.refresh(highlights)
self.save_annotations()
def save_state(self):

View File

@ -36,6 +36,12 @@ class AnnotationsManager:
v'delete h.notes'
v'delete h.spine_name'
v'delete h.spine_index'
return True
def delete_highlight(self, uuid):
if self.remove_highlight(uuid):
if ui_operations.highlights_changed:
ui_operations.highlights_changed(Object.values(self.highlights))
def notes_for_highlight(self, uuid):
h = self.highlights[uuid]
@ -552,6 +558,11 @@ class CreateAnnotation:
self.send_message('edit-highlight', uuid=uuid)
self.show()
def remove_highlight(self, uuid):
self.send_message('remove-highlight', uuid=uuid)
self.annotations_manager.delete_highlight(uuid)
self.hide()
def handle_message(self, msg):
if msg.type is 'create-annotation':
self.editing_annot_uuid = None

View File

@ -704,6 +704,11 @@ class IframeBoss:
select_crw(crw_)
self.ensure_selection_visible()
self.initiate_creation_of_annotation(data.uuid)
elif data.type is 'remove-highlight':
crw_ = {v: k for k, v in Object.entries(annot_id_uuid_map)}[data.uuid]
if crw_:
unwrap_crw(crw_)
v'delete annot_id_uuid_map[crw_]'
elif data.type is 'apply-highlight':
sel = window.getSelection()
text = sel.toString()

View File

@ -1198,4 +1198,4 @@ class View:
name = self.book.manifest.spine[spine_index]
self.show_name(name, initial_position={'type':'edit_annotation', 'uuid': uuid, 'replace_history':True})
elif which is 'delete':
pass
self.create_annotation.remove_highlight(uuid)