From 106c84e8b7137b2829a1b1f7d01b03f1cbfbf2e3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 22 Jul 2020 17:12:31 +0530 Subject: [PATCH] Add a highlight button to the selection bar --- src/pyj/read_book/create_annotation.pyj | 5 ++++- src/pyj/read_book/iframe.pyj | 5 +++-- src/pyj/read_book/selection_bar.pyj | 4 ++++ src/pyj/read_book/view.pyj | 6 +++--- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/pyj/read_book/create_annotation.pyj b/src/pyj/read_book/create_annotation.pyj index e212e209cf..f41e7e0de3 100644 --- a/src/pyj/read_book/create_annotation.pyj +++ b/src/pyj/read_book/create_annotation.pyj @@ -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() +# }}} diff --git a/src/pyj/read_book/iframe.pyj b/src/pyj/read_book/iframe.pyj index daa9846f18..de526c0740 100644 --- a/src/pyj/read_book/iframe.pyj +++ b/src/pyj/read_book/iframe.pyj @@ -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): diff --git a/src/pyj/read_book/selection_bar.pyj b/src/pyj/read_book/selection_bar.pyj index 4f50976426..f078352101 100644 --- a/src/pyj/read_book/selection_bar.pyj +++ b/src/pyj/read_book/selection_bar.pyj @@ -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: diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index 0559437ead..0c27652596 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -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)