Viewer: Fix changes to keyboard shortcuts not being applied until viewer is restarted. Fixes #1851045 [Change the shortcut for word lookup does not work](https://bugs.launchpad.net/calibre/+bug/1851045)

This commit is contained in:
Kovid Goyal 2019-11-03 14:08:19 +05:30
parent 0b05e33224
commit 21de8718d7
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 12 additions and 6 deletions

View File

@ -425,7 +425,10 @@ class PrefsOverlay: # {{{
def show(self, container): def show(self, container):
self.changes_occurred = False self.changes_occurred = False
container.style.backgroundColor = get_color('window-background') container.style.backgroundColor = get_color('window-background')
self.prefs = create_prefs_panel(container, self.overlay.hide_current_panel, def():self.changes_occurred=True;) self.prefs = create_prefs_panel(container, self.overlay.hide_current_panel, self.on_change)
def on_change(self):
self.changes_occurred = True
def handle_escape(self): def handle_escape(self):
self.prefs.onclose() self.prefs.onclose()

View File

@ -145,7 +145,7 @@ def customize_shortcut(sc_name):
def create_keyboard_panel(container, close_func, onchange): def create_keyboard_panel(container, apply_func, cancel_func, onchange):
create_keyboard_panel.onchange = onchange create_keyboard_panel.onchange = onchange
container.appendChild(E.div(id=unique_id('keyboard-settings'), style='margin: 1rem')) container.appendChild(E.div(id=unique_id('keyboard-settings'), style='margin: 1rem'))
container = container.lastChild container = container.lastChild
@ -168,7 +168,7 @@ def create_keyboard_panel(container, close_func, onchange):
create_item_list(container.lastChild, items) create_item_list(container.lastChild, items)
container.appendChild(E.div( container.appendChild(E.div(
style='margin-top: 1rem', create_button(_('Restore defaults'), action=restore_defaults.bind(None, close_func)) style='margin-top: 1rem', create_button(_('Restore defaults'), action=restore_defaults.bind(None, apply_func))
)) ))

View File

@ -55,9 +55,12 @@ class Prefs:
else: else:
self.close_func() self.close_func()
def create_panel(self, container, which, create_func): def create_panel(self, container, which, create_func, needs_onchange):
document.getElementById(self.title_id).textContent = self.title_map[which] or which document.getElementById(self.title_id).textContent = self.title_map[which] or which
create_func(container, self.onclose, self.cancel) if needs_onchange:
create_func(container, self.onclose, self.cancel, self.onchange)
else:
create_func(container, self.onclose, self.cancel)
@property @property
def container(self): def container(self):
@ -131,7 +134,7 @@ class Prefs:
commit_head_foot(self.onchange, self.container) commit_head_foot(self.onchange, self.container)
def display_keyboard(self, container): def display_keyboard(self, container):
self.create_panel(container, 'keyboard', create_keyboard_panel) self.create_panel(container, 'keyboard', create_keyboard_panel, True)
def close_keyboard(self): def close_keyboard(self):
commit_keyboard(self.onchange, self.container) commit_keyboard(self.onchange, self.container)