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