Add a highlight button to the selection bar

This commit is contained in:
Kovid Goyal 2020-07-22 17:12:31 +05:30
parent 1c38d64b1a
commit 106c84e8b7
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 14 additions and 6 deletions

View File

@ -683,6 +683,8 @@ class CreateAnnotation:
self.place_handles(msg.extents)
self.in_flow_mode = msg.in_flow_mode
self.send_message('set-highlight-style', style=self.current_highlight_style)
if msg.start_in_notes_edit:
self.add_notes()
elif msg.type is 'position-handles':
if self.state is WAITING_FOR_CLICK:
self.place_handles(msg.extents)
@ -746,7 +748,7 @@ class CreateAnnotation:
self.place_single_handle(self.right_handle, extents.end)
class ViewAnnotation:
class ViewAnnotation: # {{{
container_id = 'view-annotation-overlay'
@ -833,3 +835,4 @@ class ViewAnnotation:
if self.showing_uuid:
self.view.create_annotation.edit_highlight(self.showing_uuid)
self.hide()
# }}}

View File

@ -704,9 +704,9 @@ class IframeBoss:
end_reference_mode()
def create_annotation(self, data):
self.initiate_creation_of_annotation()
self.initiate_creation_of_annotation(None, data.start_in_notes_edit)
def initiate_creation_of_annotation(self, existing):
def initiate_creation_of_annotation(self, existing, start_in_notes_edit):
self.auto_scroll_action('stop')
in_flow_mode = current_layout_mode() is 'flow'
self.send_message(
@ -715,6 +715,7 @@ class IframeBoss:
in_flow_mode=in_flow_mode,
extents=selection_extents(in_flow_mode),
existing=existing or None,
start_in_notes_edit=v'!!start_in_notes_edit',
)
def annotations_msg_received(self, data):

View File

@ -33,6 +33,7 @@ class SelectionBar:
bar.appendChild(cb('copy', _('Copy to clipboard'), self.copy_to_clipboard))
if ui_operations.toggle_lookup:
bar.appendChild(cb('library', _('Lookup/search selected word'), self.lookup))
bar.appendChild(cb('highlight', _('Highlight selection'), self.create_highlight))
bar.appendChild(cb('close', _('Clear the selection'), self.clear_selection))
@property
@ -63,6 +64,9 @@ class SelectionBar:
def clear_selection(self):
self.view.on_handle_shortcut({'name': 'clear_selection'})
def create_highlight(self):
self.view.initiate_create_annotation(True)
def update_position(self):
cs = self.view.currently_showing
if not cs.has_selection:

View File

@ -1235,14 +1235,14 @@ class View:
else:
self.show_name(sr.file_name, initial_position={'type':'search_result', 'search_result':sr, 'replace_history':True})
def initiate_create_annotation(self):
self.iframe_wrapper.send_message('create_annotation')
def initiate_create_annotation(self, start_in_notes_edit):
self.iframe_wrapper.send_message('create_annotation', start_in_notes_edit=v'!!start_in_notes_edit')
def highlight_action(self, uuid, which):
if self.create_annotation.is_visible:
return
if which is 'create':
self.iframe_wrapper.send_message('create_annotation')
self.initiate_create_annotation(False)
return
spine = self.book.manifest.spine
spine_index = self.annotations_manager.spine_index_for_highlight(uuid, spine)