From 367f0a47820a513881bc87a32b1ca8f4814f5e5c Mon Sep 17 00:00:00 2001 From: mrvladus Date: Fri, 22 Dec 2023 19:21:04 +0300 Subject: [PATCH] refactor shortcuts --- errands/resources/errands.gresource.xml | 1 + errands/resources/gtk/help-overlay.ui | 45 ++++++++++++++++++ errands/widgets/lists.py | 2 +- errands/widgets/shortcuts_window.py | 63 ------------------------- errands/widgets/task_list.py | 8 ++++ errands/widgets/window.py | 4 -- 6 files changed, 55 insertions(+), 68 deletions(-) create mode 100644 errands/resources/gtk/help-overlay.ui delete mode 100644 errands/widgets/shortcuts_window.py diff --git a/errands/resources/errands.gresource.xml b/errands/resources/errands.gresource.xml index 92d4a76c..6f38c975 100644 --- a/errands/resources/errands.gresource.xml +++ b/errands/resources/errands.gresource.xml @@ -3,6 +3,7 @@ resources/style.css resources/style-dark.css + resources/gtk/help-overlay.ui resources/icons/errands-up.svg diff --git a/errands/resources/gtk/help-overlay.ui b/errands/resources/gtk/help-overlay.ui new file mode 100644 index 00000000..c5f658af --- /dev/null +++ b/errands/resources/gtk/help-overlay.ui @@ -0,0 +1,45 @@ + + + + + + + + + General + + + + Show keyboard shortcuts + <Control>question + + + + + + Toggle sidebar + F9 + + + + + + Preferences + <Control>comma + + + + + + Quit + <Control>q <Control>w + + + + + + + + + + \ No newline at end of file diff --git a/errands/widgets/lists.py b/errands/widgets/lists.py index 8a3af604..c2efd673 100644 --- a/errands/widgets/lists.py +++ b/errands/widgets/lists.py @@ -131,7 +131,7 @@ def _build_ui(self): menu: Gio.Menu = Gio.Menu.new() menu.append(_("Sync / Fetch Tasks"), "app.sync") # type:ignore menu.append(_("Preferences"), "app.preferences") # type:ignore - menu.append(_("Keyboard Shortcuts"), "app.shortcuts") # type:ignore + menu.append(_("Keyboard Shortcuts"), "win.show-help-overlay") # type:ignore menu.append(_("About Errands"), "app.about") # type:ignore menu_btn = Gtk.MenuButton( menu_model=menu, diff --git a/errands/widgets/shortcuts_window.py b/errands/widgets/shortcuts_window.py deleted file mode 100644 index 149408e8..00000000 --- a/errands/widgets/shortcuts_window.py +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright 2023 Vlad Krupinskii -# SPDX-License-Identifier: MIT - -from gi.repository import Adw, Gtk - -xml = f""" - - - -""" - - -@Gtk.Template(string=xml) -class ShortcutsWindow(Gtk.ShortcutsWindow): - __gtype_name__ = "ShortcutsWindow" - - def __init__(self, window: Adw.ApplicationWindow): - super().__init__() - self.set_transient_for(window) - self.present() diff --git a/errands/widgets/task_list.py b/errands/widgets/task_list.py index 6ea8e4c2..85c3f7d1 100644 --- a/errands/widgets/task_list.py +++ b/errands/widgets/task_list.py @@ -37,6 +37,14 @@ def build_ui(self): icon_name="sidebar-show-symbolic", tooltip_text=_("Toggle Sidebar"), # type:ignore ) + toggle_ctrl = Gtk.ShortcutController(scope=1) + toggle_ctrl.add_shortcut( + Gtk.Shortcut( + trigger=Gtk.ShortcutTrigger.parse_string("F9"), + action=Gtk.ShortcutAction.parse_string("activate"), + ) + ) + self.toggle_sidebar_btn.add_controller(toggle_ctrl) # Delete completed button self.delete_completed_btn = Gtk.Button( valign="center", diff --git a/errands/widgets/window.py b/errands/widgets/window.py index 100eac12..9fc8c5dd 100644 --- a/errands/widgets/window.py +++ b/errands/widgets/window.py @@ -5,7 +5,6 @@ from errands.widgets.trash import Trash from gi.repository import Gio, Adw, Gtk from errands.widgets.lists import Lists -from errands.widgets.shortcuts_window import ShortcutsWindow from errands.widgets.preferences import PreferencesWindow from errands.utils.sync import Sync from errands.utils.gsettings import GSettings @@ -121,9 +120,6 @@ def _sync(*args): lambda *_: PreferencesWindow(self).show(), ["comma"], ) - _create_action( - "shortcuts", lambda *_: ShortcutsWindow(self), ["question"] - ) _create_action("about", _about) _create_action("sync", _sync, ["s"]) _create_action(