Add a preference to turn off the selection popup bar

This commit is contained in:
Kovid Goyal 2020-07-27 19:26:05 +05:30
parent 0848740051
commit 20b76a0ae7
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 80 additions and 1 deletions

View File

@ -12,6 +12,7 @@ from read_book.prefs.colors import commit_colors, create_colors_panel
from read_book.prefs.fonts import commit_fonts, create_fonts_panel
from read_book.prefs.head_foot import commit_head_foot, create_head_foot_panel
from read_book.prefs.keyboard import commit_keyboard, create_keyboard_panel
from read_book.prefs.selection import commit_selection, create_selection_panel
from read_book.prefs.scrolling import commit_scrolling, create_scrolling_panel
from read_book.prefs.layout import commit_layout, create_layout_panel
from read_book.prefs.misc import commit_misc, create_misc_panel
@ -91,6 +92,7 @@ class Prefs:
ci(_('Styles'), 'user_stylesheet', _('Style rules for text and background image'))
ci(_('Headers and footers'), 'head_foot', _('Customize the headers and footers'))
ci(_('Scrolling behavior'), 'scrolling', _('Control how the viewer scrolls'))
ci(_('Selection behavior'), 'selection', _('Control how the viewer selects text'))
ci(_('Keyboard shortcuts'), 'keyboard', _('Customize the keyboard shortcuts'))
if runtime.is_standalone_viewer:
ci(_('Fonts'), 'fonts', _('Font choices'))
@ -145,6 +147,12 @@ class Prefs:
def close_scrolling(self):
commit_scrolling(self.onchange, self.container)
def display_selection(self, container):
self.create_panel(container, 'selection', create_selection_panel)
def close_selection(self):
commit_selection(self.onchange, self.container)
def create_prefs_panel(container, close_func, on_change):
return Prefs(container, close_func, on_change)

View File

@ -0,0 +1,68 @@
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
from __python__ import bound_methods, hash_literals
from elementmaker import E
from gettext import gettext as _
from book_list.globals import get_session_data
from dom import unique_id
from read_book.prefs.utils import create_button_box
from session import defaults
CONTAINER = unique_id('selection-settings')
def restore_defaults():
container = get_container()
for control in container.querySelectorAll('input[name]'):
val = defaults[control.getAttribute('name')]
if control.type is 'checkbox':
control.checked = val
elif control.type is 'number':
control.valueAsNumber = val
else:
control.value = val
def get_container():
return document.getElementById(CONTAINER)
def create_selection_panel(container, apply_func, cancel_func):
container.appendChild(E.div(id=CONTAINER, style='margin: 1rem'))
container = container.lastChild
sd = get_session_data()
def cb(name, text):
ans = E.input(type='checkbox', name=name)
if sd.get(name):
ans.checked = True
return E.div(style='margin-top:1ex', E.label(ans, '\xa0' + text))
container.appendChild(cb(
'show_selection_bar', _('Show a popup bar with common actions next to selected text')))
container.appendChild(create_button_box(restore_defaults, apply_func, cancel_func))
develop = create_selection_panel
def commit_selection(onchange):
sd = get_session_data()
container = get_container()
changed = False
for control in container.querySelectorAll('input[name]'):
name = control.getAttribute('name')
if control.type is 'checkbox':
val = control.checked
elif control.type is 'number':
val = control.valueAsNumber
else:
val = control.value
if val is not sd.get(name) and control.validity.valid:
sd.set(name, val)
changed = True
if changed:
onchange()

View File

@ -5,6 +5,7 @@ from __python__ import bound_methods, hash_literals
from elementmaker import E
from gettext import gettext as _
from book_list.globals import get_session_data
from book_list.theme import get_color
from dom import clear, svgicon
from read_book.globals import runtime, ui_operations
@ -66,7 +67,8 @@ class SelectionBar:
self.container.style.display = 'none'
def show(self):
if not self.view.create_annotation.is_visible:
sd = get_session_data()
if not self.view.create_annotation.is_visible and sd.get('show_selection_bar'):
self.container.style.display = 'block'
@property

View File

@ -64,6 +64,7 @@ defaults = {
'word_actions': v'[]',
'highlight_style': None,
'custom_highlight_colors': v'[]',
'show_selection_bar': True,
}
is_local_setting = {