game-details: Deactivate action when required properties are missing
This commit is contained in:
committed by
Laura Kramolis
parent
093c10f574
commit
1383384cb5
@@ -297,11 +297,12 @@ template $GameDetails: Adw.NavigationPage {
|
||||
|
||||
Button {
|
||||
action-name: "details.edit-done";
|
||||
label: _("Done");
|
||||
label: _("Apply");
|
||||
halign: center;
|
||||
|
||||
styles [
|
||||
"pill",
|
||||
"suggested-action",
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
@@ -51,7 +51,6 @@ class GameDetails(Adw.NavigationPage):
|
||||
self.insert_action_group("details", group := Gio.SimpleActionGroup())
|
||||
group.add_action_entries((
|
||||
("edit", lambda *_: self.edit()),
|
||||
("edit-done", lambda *_: self.edit_done()),
|
||||
(
|
||||
"search-on",
|
||||
lambda _action, param, *_: Gio.AppInfo.launch_default_for_uri(
|
||||
@@ -61,6 +60,20 @@ class GameDetails(Adw.NavigationPage):
|
||||
),
|
||||
))
|
||||
|
||||
group.add_action(edit_done := Gio.SimpleAction.new("edit-done"))
|
||||
edit_done.connect("activate", lambda *_: self._edit_done())
|
||||
|
||||
entries = tuple(
|
||||
Gtk.PropertyExpression.new(
|
||||
Adw.EntryRow,
|
||||
Gtk.ConstantExpression.new_for_value(getattr(self, f"{prop}_entry")),
|
||||
"text",
|
||||
)
|
||||
for prop in _REQUIRED_PROPERTIES
|
||||
)
|
||||
valid = Gtk.ClosureExpression.new(bool, lambda _, *values: all(values), entries)
|
||||
valid.bind(edit_done, "enabled")
|
||||
|
||||
def edit(self):
|
||||
"""Enter edit mode."""
|
||||
for prop in _EDITABLE_PROPERTIES:
|
||||
|
||||
Reference in New Issue
Block a user