From 1cc40a335ee396fb87f9055dd9d8f119bfb78c57 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 25 Sep 2016 12:01:22 +0530 Subject: [PATCH] Apply changes to reader preferences when the preferences panel is closed --- src/pyj/book_list/boss.pyj | 3 +++ src/pyj/read_book/overlay.pyj | 15 ++++++++++++--- src/pyj/read_book/prefs/main.pyj | 13 +++++++------ src/pyj/read_book/ui.pyj | 3 +++ src/pyj/read_book/view.pyj | 3 +++ 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/pyj/book_list/boss.pyj b/src/pyj/book_list/boss.pyj index f2399eaee3..f9e312a72b 100644 --- a/src/pyj/book_list/boss.pyj +++ b/src/pyj/book_list/boss.pyj @@ -113,6 +113,9 @@ class Boss: def reload_book(self): self.read_ui.reload_book() + def redisplay_book(self): + self.read_ui.redisplay_book() + def return_to_book_list(self, book_id): # Note that book_id could refer to a deleted book, that is, a book no # longer in local storage diff --git a/src/pyj/read_book/overlay.pyj b/src/pyj/read_book/overlay.pyj index 78168f2245..b342e4e3d1 100644 --- a/src/pyj/read_book/overlay.pyj +++ b/src/pyj/read_book/overlay.pyj @@ -192,7 +192,9 @@ class MainOverlay: self.timer = setInterval(self.update_time, 1000) def update_time(self): - document.getElementById(self.timer_id).textContent = self.date_formatter.format(Date()) + tm = document.getElementById(self.timer_id) + if tm: + tm.textContent = self.date_formatter.format(Date()) def on_hide(self): if self.timer is not None: @@ -233,13 +235,20 @@ class PrefsOverlay: # {{{ def __init__(self, overlay): self.overlay = overlay + self.changes_occurred = False def on_container_click(self, evt): pass # Dont allow panel to be closed by a click def show(self, container): + self.changes_occurred = False container.style.backgroundColor = get_color('window-background') - create_prefs_panel(container, self.overlay.hide_current_panel) + create_prefs_panel(container, self.overlay.hide_current_panel, def():self.changes_occurred=True;) + + def on_hide(self): + if self.changes_occurred: + self.changes_occurred = False + get_boss().redisplay_book() # }}} @@ -317,5 +326,5 @@ class Overlay: self.show_current_panel() def show_prefs(self): - self.panels.push(PrefsOverlay(self)) + self.panels = [PrefsOverlay(self)] self.show_current_panel() diff --git a/src/pyj/read_book/prefs/main.pyj b/src/pyj/read_book/prefs/main.pyj index 443c24d7b0..877482484d 100644 --- a/src/pyj/read_book/prefs/main.pyj +++ b/src/pyj/read_book/prefs/main.pyj @@ -11,10 +11,10 @@ from read_book.prefs.colors import create_colors_panel, commit_colors class Prefs: - def __init__(self, container, close_func): + def __init__(self, container, close_func, on_change): self.close_func = close_func - self.changes_occurred = False - title = E.h2(_('Configure book reader')) + self.on_change = on_change + title = E.h2() self.title_id = ensure_id(title) container.appendChild(E.div( style='display: flex; justify-content: space-between; padding: 1ex 1em; border-bottom: solid 1px currentColor', @@ -27,7 +27,7 @@ class Prefs: self.display_top(container.lastChild) def onchange(self): - self.changes_occurred = True + self.on_change() def onclose(self): if self.stack.length > 1: @@ -53,6 +53,7 @@ class Prefs: self.display_panel(which) def display_top(self, container): + document.getElementById(self.title_id).textContent = _('Configure book reader') c = E.div() container.appendChild(c) build_list(c, [ @@ -71,5 +72,5 @@ class Prefs: document.getElementById(self.title_id).textContent = _('Page Layout') -def create_prefs_panel(container, close_func): - Prefs(container, close_func) +def create_prefs_panel(container, close_func, on_change): + Prefs(container, close_func, on_change) diff --git a/src/pyj/read_book/ui.pyj b/src/pyj/read_book/ui.pyj index 46efbe3564..217a52cdb8 100644 --- a/src/pyj/read_book/ui.pyj +++ b/src/pyj/read_book/ui.pyj @@ -107,6 +107,9 @@ class ReadUI: metadata = self.metadata or self.interface_data.metadata[book_id] self.load_book(book_id, self.base_url_data.fmt, metadata, True) + def redisplay_book(self): + self.view.redisplay_book() + @property def url_data(self): ans = {'book_id':self.base_url_data.book_id, 'fmt': self.base_url_data.fmt} diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index bb525acfb5..d2514ccb41 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -233,6 +233,9 @@ class View: pos.type, pos.cfi = 'cfi', '/' + rest self.show_name(name, initial_position=pos) + def redisplay_book(self): + self.display_book(self.book) + def show_name(self, name, initial_position=None): if self.currently_showing.loading: return