Add toast notifications for hiding/unhiding games
This commit is contained in:
@@ -32,7 +32,7 @@ ShortcutsWindow help_overlay {
|
||||
|
||||
ShortcutsShortcut {
|
||||
title: _("Undo");
|
||||
action-name: "win.undo_remove";
|
||||
action-name: "win.undo";
|
||||
}
|
||||
|
||||
ShortcutsShortcut {
|
||||
|
||||
@@ -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 <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\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 ""
|
||||
|
||||
|
||||
30
src/main.py
30
src/main.py
@@ -94,9 +94,7 @@ class CartridgesApplication(Adw.Application):
|
||||
"toggle_search", self.win.on_toggle_search_action, ["<primary>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, ["<primary>z"], self.win
|
||||
)
|
||||
self.create_action("undo", self.win.on_undo_action, ["<primary>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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user