From af59788c71f591230f143ae4e0b616e39e0f1a3d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 19 Dec 2020 08:28:21 +0530 Subject: [PATCH] Consolidate the various modal overlays --- src/pyj/read_book/read_aloud.pyj | 2 ++ src/pyj/read_book/view.pyj | 33 ++++++++++++++++---------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/pyj/read_book/read_aloud.pyj b/src/pyj/read_book/read_aloud.pyj index 42185bb923..ea556a6222 100644 --- a/src/pyj/read_book/read_aloud.pyj +++ b/src/pyj/read_book/read_aloud.pyj @@ -21,6 +21,8 @@ STOPPED = 4 class ReadAloud: + dont_hide_on_content_loaded = True + def __init__(self, view): self.view = view self._state = HIDDEN diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index 51323ebdf9..9a1272b9d7 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -321,6 +321,7 @@ class View: self.selection_bar = SelectionBar(self) self.read_aloud = ReadAloud(self) self.hints = Hints(self) + self.modal_overlays = v'[self.selection_bar, self.read_aloud, self.hints]' self.processing_spine_item_display = False self.pending_load = None self.currently_showing = {'selection': {'empty': True}} @@ -457,9 +458,8 @@ class View: if ui_operations.overlay_visibility_changed: ui_operations.overlay_visibility_changed(visible) if visible: - self.selection_bar.hide() - self.read_aloud.hide() - self.hints.hide() + for x in self.modal_overlays: + x.hide() else: self.selection_bar.update_position() @@ -679,18 +679,16 @@ class View: self.focus_iframe() def focus_iframe(self): - if self.selection_bar.is_visible: - self.selection_bar.focus() - elif self.read_aloud.is_visible: - self.read_aloud.focus() - elif self.hints.is_visible: - self.hints.focus() - else: - self.iframe.contentWindow.focus() + for x in self.modal_overlays: + if x.is_visible: + x.focus() + return + self.iframe.contentWindow.focus() def start_read_aloud(self, dont_start_talking): - self.selection_bar.hide() - self.hints.hide() + for x in self.modal_overlays: + if x is not self.read_aloud: + x.hide() self.read_aloud.show() if not dont_start_talking: self.read_aloud.play() @@ -705,8 +703,9 @@ class View: if self.hints.is_visible: self.hints.hide() else: - self.selection_bar.hide() - self.read_aloud.hide() + for x in self.modal_overlays: + if x is not self.hints: + x.hide() self.hints.show() def show_chrome(self, data): @@ -1306,7 +1305,9 @@ class View: ) def on_content_loaded(self, data): - self.selection_bar.hide() + for x in self.modal_overlays: + if not x.dont_hide_on_content_loaded: + x.hide() self.processing_spine_item_display = False self.currently_showing.loading = False self.hide_loading()