window: Add game to collection automatically
This commit is contained in:
@@ -172,7 +172,7 @@ template $GameDetails: Adw.NavigationPage {
|
||||
|
||||
popover: PopoverMenu {
|
||||
menu-model: menu {
|
||||
item (_("New Collection"), "win.add-collection")
|
||||
item (_("New Collection"), "details.add-collection")
|
||||
|
||||
item {
|
||||
custom: "collections";
|
||||
|
||||
@@ -52,7 +52,7 @@ template $GameItem: Box {
|
||||
}
|
||||
|
||||
section {
|
||||
item (_("New Collection"), "win.add-collection")
|
||||
item (_("New Collection"), "item.add-collection")
|
||||
|
||||
item {
|
||||
custom: "collections";
|
||||
|
||||
@@ -10,7 +10,7 @@ from gettext import gettext as _
|
||||
from typing import Any, TypeVar, cast
|
||||
from urllib.parse import quote
|
||||
|
||||
from gi.repository import Adw, Gdk, Gio, GObject, Gtk
|
||||
from gi.repository import Adw, Gdk, Gio, GLib, GObject, Gtk
|
||||
|
||||
from cartridges import games
|
||||
from cartridges.config import PREFIX
|
||||
@@ -79,6 +79,12 @@ class GameDetails(Adw.NavigationPage):
|
||||
),
|
||||
"s",
|
||||
),
|
||||
(
|
||||
"add-collection",
|
||||
lambda *_: self.activate_action(
|
||||
"win.add-collection", GLib.Variant.new_string(self.game.game_id)
|
||||
),
|
||||
),
|
||||
))
|
||||
|
||||
group.add_action(apply := Gio.SimpleAction.new("apply"))
|
||||
|
||||
@@ -46,6 +46,12 @@ class GameItem(Gtk.Box):
|
||||
"win.edit", GLib.Variant.new_uint32(self.position)
|
||||
),
|
||||
),
|
||||
(
|
||||
"add-collection",
|
||||
lambda *_: self.activate_action(
|
||||
"win.add-collection", GLib.Variant.new_string(self.game.game_id)
|
||||
),
|
||||
),
|
||||
))
|
||||
|
||||
self._reveal_buttons()
|
||||
|
||||
@@ -128,7 +128,11 @@ class Window(Adw.ApplicationWindow):
|
||||
"u",
|
||||
),
|
||||
("add", lambda *_: self._add()),
|
||||
("add-collection", lambda *_: self._add_collection()),
|
||||
(
|
||||
"add-collection",
|
||||
lambda _action, param, *_: self._add_collection(param.get_string()),
|
||||
"s",
|
||||
),
|
||||
(
|
||||
"edit-collection",
|
||||
lambda _action, param, *_: self._edit_collection(param.get_uint32()),
|
||||
@@ -257,8 +261,12 @@ class Window(Adw.ApplicationWindow):
|
||||
|
||||
self.details.edit()
|
||||
|
||||
def _add_collection(self):
|
||||
details = CollectionDetails(collection=Collection())
|
||||
def _add_collection(self, game_id: str | None = None):
|
||||
collection = Collection()
|
||||
if game_id:
|
||||
collection.game_ids.append(game_id)
|
||||
|
||||
details = CollectionDetails(collection=collection)
|
||||
details.present(self)
|
||||
|
||||
def _edit_collection(self, pos: int):
|
||||
|
||||
Reference in New Issue
Block a user