Improve the highlight deletion confirmation message to show some text from the highlight and mention if the highlight has associated notes

This commit is contained in:
Kovid Goyal 2023-02-02 15:23:20 +05:30
parent 3b9fd595b4
commit be4e875706
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 16 additions and 1 deletions

View File

@ -215,6 +215,11 @@ class AnnotationsManager: # {{{
if h: if h:
return h.notes return h.notes
def text_for_highlight(self, uuid):
h = self.highlights[uuid] if uuid else None
if h:
return h.highlighted_text
def set_notes_for_highlight(self, uuid, notes): def set_notes_for_highlight(self, uuid, notes):
h = self.highlights[uuid] h = self.highlights[uuid]
if h: if h:

View File

@ -1074,8 +1074,18 @@ class SelectionBar:
def remove_highlight(self): def remove_highlight(self):
annot_id = self.view.currently_showing.selection.annot_id annot_id = self.view.currently_showing.selection.annot_id
if annot_id: if annot_id:
q = _('Are you sure you want to delete this highlight permanently?')
text = self.annotations_manager.text_for_highlight(annot_id)
if text and text.length:
if text.length > 20:
text = text[:20] + '…'
notes = self.annotations_manager.notes_for_highlight(annot_id)
if notes and notes.length:
q = _('Are you sure you want to delete the highlighting of "{}" and the associated notes permanently?').format(text)
else:
q = _('Are you sure you want to delete the highlighting of "{}" permanently?').format(text)
question_dialog( question_dialog(
_('Are you sure?'), _('Are you sure you want to delete this highlight permanently?'), _('Are you sure?'), q,
def (yes): def (yes):
if yes: if yes:
self.remove_highlight_with_id(annot_id) self.remove_highlight_with_id(annot_id)