From c859f3b7eb25dded87fb5d4f3e0f314f52fbef28 Mon Sep 17 00:00:00 2001 From: Daniel Johnson Date: Sat, 23 Mar 2024 08:50:00 -0400 Subject: [PATCH] Restore the ability to have single-game category windows (so you can compare side by side). If you multi-select, we will have a single common multi-category dialog. This can lead to overlap, where a game categories are in two windows. This doesn't seem to cause any real problems. Also, move the game count into a subtitle so it fits better. --- lutris/game_actions.py | 13 +++++++++--- lutris/gui/config/edit_game_categories.py | 24 +++++++++++++++-------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/lutris/game_actions.py b/lutris/game_actions.py index dada1d2fb..8e26cb247 100644 --- a/lutris/game_actions.py +++ b/lutris/game_actions.py @@ -159,11 +159,18 @@ class GameActions: def on_edit_game_categories(self, _widget): """Edit game categories""" + games = self.get_games() + if len(games) == 1: + # Individual games get individual separate windows + self.application.show_window(EditGameCategoriesDialog, game=games[0], parent=self.window) + else: - def add_games(window): - window.add_games(self.get_games()) + def add_games(window): + window.add_games(self.get_games()) - self.application.show_window(EditGameCategoriesDialog, update_function=add_games, parent=self.window) + # Multi-select means a common categories window for all of them; we can wind + # up adding games to it if it's already open + self.application.show_window(EditGameCategoriesDialog, update_function=add_games, parent=self.window) class MultiGameActions(GameActions): diff --git a/lutris/gui/config/edit_game_categories.py b/lutris/gui/config/edit_game_categories.py index 7a7e696a3..3d37282bc 100644 --- a/lutris/gui/config/edit_game_categories.py +++ b/lutris/gui/config/edit_game_categories.py @@ -13,8 +13,10 @@ from lutris.gui.dialogs import QuestionDialog, SavableModelessDialog class EditGameCategoriesDialog(SavableModelessDialog): """Game category edit dialog.""" - def __init__(self, parent): - super().__init__(_("Categories"), parent=parent, border_width=10) + def __init__(self, game=None, parent=None): + title = game.name if game else _("Categories") + + super().__init__(title, parent=parent, border_width=10) self.set_default_size(350, 250) self.category_checkboxes = {} @@ -31,6 +33,9 @@ class EditGameCategoriesDialog(SavableModelessDialog): self.vbox.pack_start(self._create_category_checkboxes(), True, True, 0) self.vbox.pack_start(self._create_add_category(), False, False, 0) + if game: + self.add_games([game]) + self.vbox.show_all() def add_games(self, games: Sequence[Game]) -> None: @@ -61,8 +66,11 @@ class EditGameCategoriesDialog(SavableModelessDialog): if g.id not in self.game_ids: add_game(g) - title = self.games[0].name if len(self.games) == 1 else _("%d games") % len(self.games) - self.set_title(title) + if len(self.games) > 1: + subtitle = _("%d games") % len(self.games) + header_bar = self.get_header_bar() + if header_bar: + header_bar.set_subtitle(subtitle) def _create_category_checkboxes(self): frame = Gtk.Frame() @@ -70,10 +78,10 @@ class EditGameCategoriesDialog(SavableModelessDialog): for category in self.categories: label = category - checkbutton_option = Gtk.CheckButton(label) - checkbutton_option.connect("toggled", self.on_checkbutton_toggled) - self.checkbox_grid.attach_next_to(checkbutton_option, None, Gtk.PositionType.BOTTOM, 3, 1) - self.category_checkboxes[category] = checkbutton_option + checkbutton = Gtk.CheckButton(label) + checkbutton.connect("toggled", self.on_checkbutton_toggled) + self.checkbox_grid.attach_next_to(checkbutton, None, Gtk.PositionType.BOTTOM, 3, 1) + self.category_checkboxes[category] = checkbutton scrolledwindow.add(self.checkbox_grid) frame.add(scrolledwindow)