game-details: Add edit cancelling
This commit is contained in:
@@ -6,9 +6,14 @@ template $GameDetails: Adw.NavigationPage {
|
||||
name: "details";
|
||||
tag: "details";
|
||||
title: bind $_or(template.game as <$Game>.name, _("Add Game")) as <string>;
|
||||
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 <string>;
|
||||
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 <string>;
|
||||
|
||||
styles [
|
||||
"pill",
|
||||
"suggested-action",
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -321,3 +343,10 @@ template $GameDetails: Adw.NavigationPage {
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
SizeGroup {
|
||||
widgets [
|
||||
cancel_button,
|
||||
apply_button,
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user