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