mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Viewer: Fix shortcuts preferences not being translated
This commit is contained in:
parent
d744eb1a6d
commit
23dcafa265
@ -9,7 +9,8 @@ from book_list.globals import get_session_data
|
||||
from book_list.item_list import create_item, create_item_list
|
||||
from dom import clear, svgicon, unique_id
|
||||
from read_book.shortcuts import (
|
||||
GROUP_DESC, SHORTCUTS, key_as_text, keyevent_as_shortcut, shortcut_differs
|
||||
key_as_text, keyevent_as_shortcut, shortcut_differs, shortcuts_definition,
|
||||
shortcuts_group_desc
|
||||
)
|
||||
from widgets import create_button
|
||||
|
||||
@ -22,7 +23,7 @@ def restore_defaults(close_func):
|
||||
get_container().dataset.changed = 'true'
|
||||
for item in get_container().querySelectorAll('[data-user-data]'):
|
||||
q = JSON.parse(item.dataset.userData)
|
||||
q.shortcuts = SHORTCUTS[q.name].shortcuts
|
||||
q.shortcuts = shortcuts_definition()[q.name].shortcuts
|
||||
item.dataset.userData = JSON.stringify(q)
|
||||
close_func()
|
||||
|
||||
@ -127,7 +128,7 @@ def customize_shortcut(sc_name):
|
||||
container = container.lastChild
|
||||
clear(container)
|
||||
container.dataset.scName = sc_name
|
||||
sc = SHORTCUTS[sc_name]
|
||||
sc = shortcuts_definition()[sc_name]
|
||||
container.appendChild(E.h4(sc.short))
|
||||
if sc.long:
|
||||
container.appendChild(E.div(sc.long, style='font-style: italic; font-size: smaller; margin-top: 1ex'))
|
||||
@ -155,9 +156,9 @@ def create_keyboard_panel(container, close_func, onchange):
|
||||
container = container.firstChild
|
||||
sd = get_session_data()
|
||||
custom_shortcuts = sd.get('keyboard_shortcuts')
|
||||
groups = as_groups(SHORTCUTS)
|
||||
groups = as_groups(shortcuts_definition())
|
||||
for group_name in Object.keys(groups):
|
||||
container.appendChild(E.h3(style='margin-top: 1ex', GROUP_DESC[group_name]))
|
||||
container.appendChild(E.h3(style='margin-top: 1ex', shortcuts_group_desc()[group_name]))
|
||||
group = groups[group_name]
|
||||
items = []
|
||||
for sc_name in sorted(Object.keys(group), key=sort_group_key.bind(None, group)):
|
||||
@ -188,7 +189,7 @@ def commit_keyboard(onchange):
|
||||
vals = {}
|
||||
for item in get_container().querySelectorAll('[data-user-data]'):
|
||||
q = JSON.parse(item.dataset.userData)
|
||||
if shortcuts_differ(q.shortcuts, SHORTCUTS[q.name].shortcuts):
|
||||
if shortcuts_differ(q.shortcuts, shortcuts_definition()[q.name].shortcuts):
|
||||
vals[q.name] = q.shortcuts
|
||||
sd.set('keyboard_shortcuts', vals)
|
||||
create_keyboard_panel.onchange = None
|
||||
|
@ -86,13 +86,10 @@ def key_as_text(evt):
|
||||
return mods + key
|
||||
|
||||
|
||||
GROUP_DESC = {
|
||||
'scroll': _('Navigation'),
|
||||
'ui': _('Interface'),
|
||||
}
|
||||
|
||||
|
||||
SHORTCUTS = {
|
||||
def shortcuts_definition():
|
||||
ans = shortcuts_definition.ans
|
||||
if not ans:
|
||||
ans = shortcuts_definition.ans = {
|
||||
'start_of_file': desc(
|
||||
v"['Ctrl+ArrowUp', 'Ctrl+ArrowLeft', 'Home']",
|
||||
'scroll',
|
||||
@ -248,31 +245,44 @@ SHORTCUTS = {
|
||||
'ui',
|
||||
_('Show the viewer controls'),
|
||||
),
|
||||
}
|
||||
}
|
||||
return ans
|
||||
|
||||
|
||||
def shortcuts_group_desc():
|
||||
ans = shortcuts_group_desc.ans
|
||||
if not ans:
|
||||
ans = shortcuts_group_desc.ans = {
|
||||
'scroll': _('Navigation'),
|
||||
'ui': _('Interface'),
|
||||
}
|
||||
return ans
|
||||
|
||||
|
||||
|
||||
def add_standalone_viewer_shortcuts():
|
||||
ismacos = 'macos' in window.navigator.userAgent
|
||||
SHORTCUTS['toggle_bookmarks'] = desc(
|
||||
sc = shortcuts_definition()
|
||||
sc['toggle_bookmarks'] = desc(
|
||||
v"['Ctrl+b']",
|
||||
'ui',
|
||||
_('Show/hide bookmarks'),
|
||||
)
|
||||
|
||||
SHORTCUTS['toggle_inspector'] = desc(
|
||||
sc['toggle_inspector'] = desc(
|
||||
v"['Ctrl+i']",
|
||||
'ui',
|
||||
_('Show/hide Inspector'),
|
||||
)
|
||||
|
||||
SHORTCUTS['toggle_lookup'] = desc(
|
||||
sc['toggle_lookup'] = desc(
|
||||
v"['Ctrl+l']",
|
||||
'ui',
|
||||
_('Show/hide the word lookup panel'),
|
||||
)
|
||||
|
||||
quit_shortcut = 'Meta+q' if ismacos else 'Ctrl+q'
|
||||
SHORTCUTS['quit'] = desc(
|
||||
sc['quit'] = desc(
|
||||
quit_shortcut,
|
||||
'ui',
|
||||
_('Quit the viewer'),
|
||||
@ -280,8 +290,9 @@ def add_standalone_viewer_shortcuts():
|
||||
|
||||
def create_shortcut_map(custom_shortcuts):
|
||||
ans = {}
|
||||
for sc_name in Object.keys(SHORTCUTS):
|
||||
entry = SHORTCUTS[sc_name]
|
||||
scd = shortcuts_definition()
|
||||
for sc_name in Object.keys(scd):
|
||||
entry = scd[sc_name]
|
||||
shortcuts = entry.shortcuts
|
||||
if custom_shortcuts and custom_shortcuts[sc_name]:
|
||||
shortcuts = custom_shortcuts[sc_name]
|
||||
|
@ -28,7 +28,6 @@ runtime.is_standalone_viewer = True
|
||||
runtime.FAKE_HOST = FAKE_HOST
|
||||
runtime.SANDBOX_HOST = FAKE_HOST.rpartition('.')[0] + '.sandbox'
|
||||
runtime.FAKE_PROTOCOL = FAKE_PROTOCOL
|
||||
add_standalone_viewer_shortcuts()
|
||||
book = None
|
||||
view = None
|
||||
|
||||
@ -288,6 +287,7 @@ if window is window.top:
|
||||
TRANSLATIONS_DATA = v'__TRANSLATIONS_DATA__'
|
||||
if TRANSLATIONS_DATA:
|
||||
install(TRANSLATIONS_DATA)
|
||||
add_standalone_viewer_shortcuts()
|
||||
ui_operations.get_file = get_file
|
||||
ui_operations.get_mathjax_files = get_mathjax_files
|
||||
ui_operations.update_url_state = update_url_state
|
||||
@ -360,3 +360,4 @@ else:
|
||||
footnotes_main()
|
||||
else:
|
||||
iframe_main()
|
||||
add_standalone_viewer_shortcuts()
|
||||
|
Loading…
x
Reference in New Issue
Block a user