From 9d4932f22e183faff6a8baee4035a7d9cdeac95b Mon Sep 17 00:00:00 2001 From: Jamie Gravendeel Date: Thu, 4 Dec 2025 01:08:53 +0100 Subject: [PATCH] game-details: Add edit cancelling --- cartridges/ui/game-details.blp | 45 ++++++++++++++++++++++++++++------ cartridges/ui/game_details.py | 12 ++++++--- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/cartridges/ui/game-details.blp b/cartridges/ui/game-details.blp index 1380413..7e991b6 100644 --- a/cartridges/ui/game-details.blp +++ b/cartridges/ui/game-details.blp @@ -6,9 +6,14 @@ template $GameDetails: Adw.NavigationPage { name: "details"; tag: "details"; title: bind $_or(template.game as <$Game>.name, _("Add Game")) as ; - hidden => $_exit(); + hidden => $_cancel(); ShortcutController { + Shortcut { + trigger: "Escape"; + action: "action(details.cancel)"; + } + Shortcut { trigger: "Delete|KP_Delete"; action: "action(details.remove)"; @@ -302,15 +307,32 @@ template $GameDetails: Adw.NavigationPage { } } - Button { - action-name: "details.apply"; - label: bind $_if_else(template.game as <$Game>.added, _("Apply"), _("Add")) as ; + Adw.WrapBox { halign: center; + wrap-reverse: true; + justify: fill; + justify-last-line: true; + child-spacing: 12; + line-spacing: 12; - styles [ - "pill", - "suggested-action", - ] + Button cancel_button { + action-name: "details.cancel"; + label: _("Cancel"); + + styles [ + "pill", + ] + } + + Button apply_button { + action-name: "details.apply"; + label: bind $_if_else(template.game as <$Game>.added, _("Apply"), _("Add")) as ; + + styles [ + "pill", + "suggested-action", + ] + } } }; } @@ -321,3 +343,10 @@ template $GameDetails: Adw.NavigationPage { }; }; } + +SizeGroup { + widgets [ + cancel_button, + apply_button, + ] +} diff --git a/cartridges/ui/game_details.py b/cartridges/ui/game_details.py index 568bc63..74db3a6 100644 --- a/cartridges/ui/game_details.py +++ b/cartridges/ui/game_details.py @@ -55,6 +55,7 @@ class GameDetails(Adw.NavigationPage): self.insert_action_group("details", group := Gio.SimpleActionGroup()) group.add_action_entries(( ("edit", lambda *_: self.edit()), + ("cancel", lambda *_: self._cancel()), ("remove", lambda *_: self._remove()), ( "search-on", @@ -104,16 +105,19 @@ class GameDetails(Adw.NavigationPage): self.game.added = int(time.time()) games.model.append(self.game) - self._exit() - - @Gtk.Template.Callback() - def _exit(self, *_args): self.stack.props.visible_child_name = "details" @Gtk.Template.Callback() def _activate_apply(self, _entry): self.activate_action("details.apply") + @Gtk.Template.Callback() + def _cancel(self, *_args): + if self.stack.props.visible_child_name == "details" or not self.game.added: + self.activate_action("navigation.pop") + + self.stack.props.visible_child_name = "details" + def _remove(self): self.game.removed = True self.activate_action("navigation.pop")