More work on the Go to implementation

This commit is contained in:
Kovid Goyal 2017-01-01 19:32:12 +05:30
parent 6756388c24
commit 443070cd8d
5 changed files with 27 additions and 12 deletions

View File

@ -15,6 +15,10 @@ def set_boss(b):
def get_boss():
return _boss
def current_book():
return current_book.book
current_book.book = None
class Messenger:
def __init__(self):

View File

@ -6,9 +6,23 @@ from dom import set_css, svgicon
from elementmaker import E
from gettext import gettext as _
from book_list.item_list import create_item, build_list
from read_book.toc import get_toc_maps, get_border_nodes
from read_book.globals import current_book
def create_goto_list(onclick):
return E.div()
ans = E.div()
items = v'[]'
toc = current_book().manifest.toc
id_map = get_toc_maps(toc)[1]
before, after = get_border_nodes(toc, id_map)
if after:
items.push(create_item(_('Next Section'), icon='caret-right', subtitle=after.title, action=onclick.bind(after.dest, after.frag)))
if before:
items.push(create_item(_('Previous Section'), icon='caret-left', subtitle=before.title, action=onclick.bind(before.dest, before.frag)))
build_list(ans, items)
return ans
def create_goto_panel(book, container, onclick, onclose):
@ -17,10 +31,7 @@ def create_goto_panel(book, container, onclick, onclose):
E.h2(_('Go to...')),
E.div(svgicon('close'), style='cursor:pointer', onclick=def(event):event.preventDefault(), event.stopPropagation(), onclose(event);, class_='simple-link'),
))
def handle_click(event, li):
if event.button is 0:
onclick(li.dataset.tocDest, li.dataset.tocFrag)
panel = create_goto_list(handle_click)
panel = create_goto_list(onclick)
set_css(container, display='flex', flex_direction='column')
set_css(panel, flex_grow='10')
container.appendChild(panel)

View File

@ -6,7 +6,7 @@ import traceback
from aes import GCM
from gettext import install, gettext as _
from read_book.cfi import at_current, scroll_to as scroll_to_cfi
from read_book.globals import set_boss, set_current_spine_item, current_layout_mode, current_spine_item, set_layout_mode
from read_book.globals import set_boss, set_current_spine_item, current_layout_mode, current_spine_item, set_layout_mode, current_book
from read_book.mathjax import apply_mathjax
from read_book.toc import update_visible_toc_anchors
from read_book.resources import finalize_resources, unserialize_html
@ -94,7 +94,7 @@ class IframeBoss:
def display(self, data):
self.encrypted_communications = True
self.book = data.book
self.book = current_book.book = data.book
spine = self.book.manifest.spine
index = spine.indexOf(data.name)
set_layout_mode('flow' if FORCE_FLOW_MODE else data.settings.read_mode)

View File

@ -8,7 +8,7 @@ from elementmaker import E
from gettext import gettext as _
from modals import error_dialog
from widgets import create_tree, find_text_in_tree, scroll_tree_item_into_view
from read_book.globals import toc_anchor_map, set_toc_anchor_map, current_spine_item, current_layout_mode, get_boss
from read_book.globals import toc_anchor_map, set_toc_anchor_map, current_spine_item, current_layout_mode, current_book
def update_visible_toc_nodes(visible_anchors):
@ -36,7 +36,7 @@ def get_border_nodes(toc, id_map):
return before, after
# Find the ToC entries that point to the closest files on either side of the
# current spine item
spine = get_boss().book.manifest.spine
spine = current_book().manifest.spine
spine_before, spine_after = {}, {}
which = spine_before
csi = current_spine_item()
@ -82,7 +82,7 @@ def get_highlighted_toc_nodes(toc, parent_map, id_map):
def get_toc_maps(toc):
if not toc:
toc = get_boss().book.manifest.toc
toc = current_book().manifest.toc
parent_map, id_map = {}, {}
def process_node(node, parent):

View File

@ -6,7 +6,7 @@ from book_list.globals import get_session_data, get_boss
from dom import set_css, add_extra_css, build_rule, svgicon
from elementmaker import E
from gettext import gettext as _
from read_book.globals import messenger, iframe_id
from read_book.globals import messenger, iframe_id, current_book
from read_book.resources import load_resources
from read_book.overlay import Overlay
from read_book.prefs.colors import resolve_color_scheme
@ -225,7 +225,7 @@ class View:
self.overlay.hide_loading_message()
def display_book(self, book):
self.book = book
self.book = current_book.book = book
self.ui.db.update_last_read_time(book)
self.loaded_resources = {}
pos = {'replace_history':True}