Apply changes to reader preferences when the preferences panel is closed

This commit is contained in:
Kovid Goyal 2016-09-25 12:01:22 +05:30
parent fdb50deca9
commit 1cc40a335e
5 changed files with 28 additions and 9 deletions

View File

@ -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

View File

@ -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()

View File

@ -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)

View File

@ -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}

View File

@ -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