From 566855ed550a14fd48e452c67f789aa37396dc5d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 25 Aug 2019 20:59:25 +0530 Subject: [PATCH] Shortcuts for UI panels --- src/pyj/read_book/prefs/keyboard.pyj | 4 ++-- src/pyj/read_book/shortcuts.pyj | 29 ++++++++++++++++++++++++++-- src/pyj/read_book/ui.pyj | 4 ++++ src/pyj/read_book/view.pyj | 8 ++++++++ src/pyj/viewer-main.pyj | 7 ++++--- 5 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/pyj/read_book/prefs/keyboard.pyj b/src/pyj/read_book/prefs/keyboard.pyj index 7e0a778f03..da3c195e5a 100644 --- a/src/pyj/read_book/prefs/keyboard.pyj +++ b/src/pyj/read_book/prefs/keyboard.pyj @@ -147,10 +147,10 @@ def create_keyboard_panel(container, close_func): sd = get_session_data() custom_shortcuts = sd.get('keyboard_shortcuts') groups = as_groups(SHORTCUTS) - items = [] for group_name in Object.keys(groups): - container.appendChild(E.h3(GROUP_DESC[group_name])) + container.appendChild(E.h3(style='margin-top: 1ex', GROUP_DESC[group_name])) group = groups[group_name] + items = [] for sc_name in sorted(Object.keys(group), key=sort_group_key.bind(None, group)): sc = group[sc_name] items.push(sc_as_item(sc_name, sc, custom_shortcuts[sc_name])) diff --git a/src/pyj/read_book/shortcuts.pyj b/src/pyj/read_book/shortcuts.pyj index 740f6fd5ea..57265d6281 100644 --- a/src/pyj/read_book/shortcuts.pyj +++ b/src/pyj/read_book/shortcuts.pyj @@ -67,7 +67,8 @@ def key_as_text(evt): GROUP_DESC = { - 'scroll': _('Navigation') + 'scroll': _('Navigation'), + 'ui': _('Interface'), } @@ -150,11 +151,35 @@ SHORTCUTS = { _('Forward'), ), - + 'toggle_toc': desc( + v"['Ctrl+t']", + 'ui', + _('Show/hide Table of Contents'), + ), } +def add_standalone_viewer_shortcuts(): + SHORTCUTS['toggle_bookmarks'] = desc( + v"['Ctrl+b']", + 'ui', + _('Show/hide bookmarks'), + ) + + SHORTCUTS['toggle_inspector'] = desc( + v"['Ctrl+i']", + 'ui', + _('Show/hide Inspector'), + ) + + SHORTCUTS['toggle_lookup'] = desc( + v"['Ctrl+l']", + 'ui', + _('Show/hide the word lookup panel'), + ) + + def create_shortcut_map(custom_shortcuts): ans = {} for sc_name in Object.keys(SHORTCUTS): diff --git a/src/pyj/read_book/ui.pyj b/src/pyj/read_book/ui.pyj index e4b3739f31..11d0fffcab 100644 --- a/src/pyj/read_book/ui.pyj +++ b/src/pyj/read_book/ui.pyj @@ -68,6 +68,7 @@ class ReadUI: ui_operations.goto_bookpos = self.goto_bookpos.bind(self) ui_operations.delete_book = self.delete_book.bind(self) ui_operations.focus_iframe = self.focus_iframe.bind(self) + ui_operations.toggle_toc = self.toggle_toc.bind(self) def on_resize(self): self.view.on_resize() @@ -166,6 +167,9 @@ class ReadUI: def focus_iframe(self): self.view.focus_iframe() + def toggle_toc(self): + self.view.overlay.show_toc() + def update_color_scheme(self): self.view.update_color_scheme() diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index 64f01735c8..7868d749a4 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -221,6 +221,14 @@ class View: window.history.back() elif data.name is 'forward': window.history.forward() + elif data.name is 'toggle_toc': + ui_operations.toggle_toc() + elif data.name is 'toggle_bookmarks': + ui_operations.toggle_bookmarks() + elif data.name is 'toggle_inspector': + ui_operations.toggle_inspector() + elif data.name is 'toggle_lookup': + ui_operations.toggle_lookup() def on_selection_change(self, data): self.currently_showing.selected_text = data.text diff --git a/src/pyj/viewer-main.pyj b/src/pyj/viewer-main.pyj index 3f3b46e430..c1283c7f0c 100644 --- a/src/pyj/viewer-main.pyj +++ b/src/pyj/viewer-main.pyj @@ -9,24 +9,25 @@ from gettext import gettext as _, install import initialize # noqa: unused-import from ajax import ajax from book_list.globals import set_session_data -from book_list.theme import get_color, get_font_family from book_list.library_data import library_data +from book_list.theme import get_color, get_font_family from dom import get_widget_css, set_css from modals import create_modal_container, error_dialog from qt import from_python, to_python from read_book.db import new_book +from read_book.footnotes import main as footnotes_main from read_book.globals import runtime, ui_operations from read_book.iframe import main as iframe_main +from read_book.shortcuts import add_standalone_viewer_shortcuts from read_book.view import View -from read_book.footnotes import main as footnotes_main from session import session_defaults from utils import encode_query_with_path, parse_url_params from viewer.constants import FAKE_HOST, FAKE_PROTOCOL - runtime.is_standalone_viewer = True runtime.FAKE_HOST = FAKE_HOST runtime.FAKE_PROTOCOL = FAKE_PROTOCOL +add_standalone_viewer_shortcuts() book = None view = None