diff --git a/data/gtk/help-overlay.blp b/data/gtk/help-overlay.blp index ccf3480..9dba591 100644 --- a/data/gtk/help-overlay.blp +++ b/data/gtk/help-overlay.blp @@ -32,7 +32,7 @@ ShortcutsWindow help_overlay { ShortcutsShortcut { title: _("Undo"); - action-name: "win.undo_remove"; + action-name: "win.undo"; } ShortcutsShortcut { diff --git a/po/cartridges.pot b/po/cartridges.pot index 8cc0281..f49a710 100644 --- a/po/cartridges.pot +++ b/po/cartridges.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Cartridges\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-04-03 09:37+0200\n" +"POT-Creation-Date: 2023-04-03 10:36+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -19,7 +19,7 @@ msgstr "" #: data/hu.kramo.Cartridges.desktop.in:3 #: data/hu.kramo.Cartridges.metainfo.xml.in:6 data/gtk/window.blp:29 -#: src/main.py:111 +#: src/main.py:109 msgid "Cartridges" msgstr "" @@ -188,7 +188,8 @@ msgstr "" msgid "Shortcuts" msgstr "" -#: data/gtk/help-overlay.blp:34 src/main.py:212 src/preferences.py:121 +#: data/gtk/help-overlay.blp:34 src/main.py:175 src/main.py:228 +#: src/preferences.py:121 msgid "Undo" msgstr "" @@ -322,17 +323,27 @@ msgid "Bottles Install Location" msgstr "" #. Translators: Replace this with your name for it to show up in the about window -#: src/main.py:126 +#: src/main.py:124 msgid "translator_credits" msgstr "" #. The variable is the title of the game -#: src/main.py:153 +#: src/main.py:151 msgid "{} launched" msgstr "" #. The variable is the title of the game -#: src/main.py:211 +#: src/main.py:171 +msgid "{} hidden" +msgstr "" + +#. The variable is the title of the game +#: src/main.py:174 +msgid "{} unhidden" +msgstr "" + +#. The variable is the title of the game +#: src/main.py:227 msgid "{} removed" msgstr "" diff --git a/src/main.py b/src/main.py index 299a1e4..8c97153 100644 --- a/src/main.py +++ b/src/main.py @@ -94,9 +94,7 @@ class CartridgesApplication(Adw.Application): "toggle_search", self.win.on_toggle_search_action, ["f"], self.win ) self.create_action("escape", self.win.on_escape_action, ["Escape"], self.win) - self.create_action( - "undo_remove", self.win.on_undo_remove_action, ["z"], self.win - ) + self.create_action("undo", self.win.on_undo_action, ["z"], self.win) self.create_action("open_menu", self.win.on_open_menu_action, ["F10"], self.win) self.win.sort = Gio.SimpleAction.new_stateful( "sort_by", GLib.VariantType.new("s"), GLib.Variant("s", "a-z") @@ -160,10 +158,28 @@ class CartridgesApplication(Adw.Application): self.win.show_overview(None, self.win.active_game_id) def on_hide_game_action(self, _widget, _callback=None): + game_id = self.win.active_game_id + if self.win.stack.get_visible_child() == self.win.overview: self.win.on_go_back_action(None, None) - self.win.games[self.win.active_game_id].toggle_hidden() - self.win.update_games([self.win.active_game_id]) + self.win.games[game_id].toggle_hidden() + self.win.update_games([game_id]) + + title = self.win.games[game_id].name + if self.win.games[game_id].hidden: + # The variable is the title of the game + toast = Adw.Toast.new(_("{} hidden").format(title)) + else: + # The variable is the title of the game + toast = Adw.Toast.new(_("{} unhidden").format(title)) + toast.set_button_label(_("Undo")) + toast.connect("button-clicked", self.win.on_undo_action, game_id, "hide") + toast.set_priority(Adw.ToastPriority.HIGH) + if (game_id, "hide") in self.win.toasts.keys(): + # Dismiss the toast if there already is one + self.win.toasts[(game_id, "hide")].dismiss() + self.win.toasts[(game_id, "hide")] = toast + self.win.toast_overlay.add_toast(toast) def on_edit_details_action(self, _widget, _callback=None): create_details_window(self.win, self.win.active_game_id) @@ -210,9 +226,9 @@ class CartridgesApplication(Adw.Application): # The variable is the title of the game toast = Adw.Toast.new(_("{} removed").format(title)) toast.set_button_label(_("Undo")) - toast.connect("button-clicked", self.win.on_undo_remove_action, game_id) + toast.connect("button-clicked", self.win.on_undo_action, game_id, "remove") toast.set_priority(Adw.ToastPriority.HIGH) - self.win.toasts[game_id] = toast + self.win.toasts[(game_id, "remove")] = toast self.win.toast_overlay.add_toast(toast) def on_quit_action(self, _widget, _callback=None): diff --git a/src/utils/lutris_parser.py b/src/utils/lutris_parser.py index b1b1a44..8961fe1 100644 --- a/src/utils/lutris_parser.py +++ b/src/utils/lutris_parser.py @@ -57,6 +57,7 @@ def lutris_parser(parent_widget): db_cache_dir = parent_widget.cache_dir / "cartridges" / "lutris" db_cache_dir.mkdir(parents=True, exist_ok=True) + # Copy the file because sqlite3 doesn't like databases in /run/user/ database_tmp_path = db_cache_dir / "pga.db" copyfile(database_path, database_tmp_path) diff --git a/src/window.py b/src/window.py index 7aa7f0b..2bb7c8e 100644 --- a/src/window.py +++ b/src/window.py @@ -417,20 +417,25 @@ class CartridgesWindow(Adw.ApplicationWindow): search_button.set_active(False) search_entry.set_text("") - def on_undo_remove_action(self, _widget, game_id=None): - # Remove the "removed=True" property from the game and dismiss the toast - - if not game_id: + def on_undo_action(self, _widget, game_id=None, undo=None): + if not game_id: # If the action was activated via Ctrl + Z try: - game_id = list(self.toasts)[-1] + game_id = tuple(self.toasts.keys())[-1][0] + undo = tuple(self.toasts.keys())[-1][1] except IndexError: return - data = get_games(self, [game_id])[game_id] - data.pop("removed", None) - save_game(self, data) + + if undo == "hide": + self.games[game_id].toggle_hidden() + + elif undo == "remove": + data = get_games(self, [game_id])[game_id] + data.pop("removed", None) + save_game(self, data) + self.update_games([game_id]) - self.toasts[game_id].dismiss() - self.toasts.pop(game_id) + self.toasts[(game_id, undo)].dismiss() + self.toasts.pop((game_id, undo)) def on_open_menu_action(self, _widget, _unused): if self.stack.get_visible_child() != self.overview: