Skip to content

Commit

Permalink
refactor shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvladus committed Dec 22, 2023
1 parent 1a9b6ae commit 367f0a4
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 68 deletions.
1 change: 1 addition & 0 deletions errands/resources/errands.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<gresource prefix="/io/github/mrvladus/Errands">
<file alias="style.css">resources/style.css</file>
<file alias="style-dark.css">resources/style-dark.css</file>
<file preprocess="xml-stripblanks" alias="gtk/help-overlay.ui">resources/gtk/help-overlay.ui</file>
</gresource>
<gresource prefix="/io/github/mrvladus/Errands/icons/scalable/actions/">
<file preprocess="xml-stripblanks" alias="errands-up.svg">resources/icons/errands-up.svg</file>
Expand Down
45 changes: 45 additions & 0 deletions errands/resources/gtk/help-overlay.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<interface>
<object class="GtkShortcutsWindow" id="help_overlay">
<child>
<object class="GtkShortcutsSection">

<!-- General -->
<child>
<object class="GtkShortcutsGroup">
<property name="title" translatable="yes">General</property>

<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes">Show keyboard shortcuts</property>
<property name="accelerator">&lt;Control&gt;question</property>
</object>
</child>

<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes">Toggle sidebar</property>
<property name="accelerator">F9</property>
</object>
</child>

<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes">Preferences</property>
<property name="accelerator">&lt;Control&gt;comma</property>
</object>
</child>

<child>
<object class="GtkShortcutsShortcut">
<property name="title" translatable="yes">Quit</property>
<property name="accelerator">&lt;Control&gt;q &lt;Control&gt;w</property>
</object>
</child>

</object>
</child>
</object>
</child>
</object>

</interface>
2 changes: 1 addition & 1 deletion errands/widgets/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
63 changes: 0 additions & 63 deletions errands/widgets/shortcuts_window.py

This file was deleted.

8 changes: 8 additions & 0 deletions errands/widgets/task_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 0 additions & 4 deletions errands/widgets/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -121,9 +120,6 @@ def _sync(*args):
lambda *_: PreferencesWindow(self).show(),
["<primary>comma"],
)
_create_action(
"shortcuts", lambda *_: ShortcutsWindow(self), ["<primary>question"]
)
_create_action("about", _about)
_create_action("sync", _sync, ["<primary>s"])
_create_action(
Expand Down

0 comments on commit 367f0a4

Please sign in to comment.