mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DRYer
This commit is contained in:
parent
443070cd8d
commit
9b17f78001
@ -2,7 +2,7 @@
|
|||||||
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
from __python__ import hash_literals, bound_methods
|
from __python__ import hash_literals, bound_methods
|
||||||
|
|
||||||
from dom import set_css, svgicon
|
from dom import set_css
|
||||||
from elementmaker import E
|
from elementmaker import E
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
|
||||||
@ -26,11 +26,6 @@ def create_goto_list(onclick):
|
|||||||
|
|
||||||
|
|
||||||
def create_goto_panel(book, container, onclick, onclose):
|
def create_goto_panel(book, container, onclick, onclose):
|
||||||
container.appendChild(E.div(
|
|
||||||
style='display: flex; justify-content: space-between; padding: 1ex 1em; border-bottom: solid 1px currentColor',
|
|
||||||
E.h2(_('Go to...')),
|
|
||||||
E.div(svgicon('close'), style='cursor:pointer', onclick=def(event):event.preventDefault(), event.stopPropagation(), onclose(event);, class_='simple-link'),
|
|
||||||
))
|
|
||||||
panel = create_goto_list(onclick)
|
panel = create_goto_list(onclick)
|
||||||
set_css(container, display='flex', flex_direction='column')
|
set_css(container, display='flex', flex_direction='column')
|
||||||
set_css(panel, flex_grow='10')
|
set_css(panel, flex_grow='10')
|
||||||
|
@ -218,16 +218,22 @@ class MainOverlay:
|
|||||||
|
|
||||||
class TOCOverlay: # {{{
|
class TOCOverlay: # {{{
|
||||||
|
|
||||||
def __init__(self, overlay, create_func):
|
def __init__(self, overlay, create_func, title):
|
||||||
self.overlay = overlay
|
self.overlay = overlay
|
||||||
self.create_func = create_func or create_toc_panel
|
self.create_func = create_func or create_toc_panel
|
||||||
|
self.title = title or _('Table of Contents')
|
||||||
|
|
||||||
def on_container_click(self, evt):
|
def on_container_click(self, evt):
|
||||||
pass # Dont allow panel to be closed by a click
|
pass # Dont allow panel to be closed by a click
|
||||||
|
|
||||||
def show(self, container):
|
def show(self, container):
|
||||||
container.style.backgroundColor = get_color('window-background')
|
container.style.backgroundColor = get_color('window-background')
|
||||||
self.create_func(self.overlay.view.book, container, self.handle_activate, self.overlay.hide_current_panel)
|
container.appendChild(E.div(
|
||||||
|
style='padding: 1ex 1em; border-bottom: solid 1px currentColor',
|
||||||
|
E.h2(self.title, style='float:left'),
|
||||||
|
E.div(svgicon('close'), style='cursor:pointer; float:right', onclick=def(event):event.preventDefault(), event.stopPropagation(), self.overlay.hide_current_panel(event);, class_='simple-link'),
|
||||||
|
))
|
||||||
|
self.create_func(self.overlay.view.book, container, self.handle_activate)
|
||||||
|
|
||||||
def handle_activate(self, dest, frag):
|
def handle_activate(self, dest, frag):
|
||||||
self.overlay.hide()
|
self.overlay.hide()
|
||||||
@ -337,7 +343,7 @@ class Overlay:
|
|||||||
self.show_current_panel()
|
self.show_current_panel()
|
||||||
|
|
||||||
def show_goto(self):
|
def show_goto(self):
|
||||||
self.panels.push(TOCOverlay(self, create_goto_panel))
|
self.panels.push(TOCOverlay(self, create_goto_panel, _('Go to…')))
|
||||||
self.show_current_panel()
|
self.show_current_panel()
|
||||||
|
|
||||||
def show_prefs(self):
|
def show_prefs(self):
|
||||||
|
@ -119,12 +119,7 @@ def do_search(text):
|
|||||||
'The text "{}" was not found in the Table of Contents').format(text))
|
'The text "{}" was not found in the Table of Contents').format(text))
|
||||||
scroll_tree_item_into_view(a)
|
scroll_tree_item_into_view(a)
|
||||||
|
|
||||||
def create_toc_panel(book, container, onclick, onclose):
|
def create_toc_panel(book, container, onclick):
|
||||||
container.appendChild(E.div(
|
|
||||||
style='display: flex; justify-content: space-between; padding: 1ex 1em; border-bottom: solid 1px currentColor',
|
|
||||||
E.h2(_('Table of Contents')),
|
|
||||||
E.div(svgicon('close'), style='cursor:pointer', onclick=def(event):event.preventDefault(), event.stopPropagation(), onclose(event);, class_='simple-link'),
|
|
||||||
))
|
|
||||||
def handle_click(event, li):
|
def handle_click(event, li):
|
||||||
if event.button is 0:
|
if event.button is 0:
|
||||||
onclick(li.dataset.tocDest, li.dataset.tocFrag)
|
onclick(li.dataset.tocDest, li.dataset.tocFrag)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user