Ctrl + Z for import undo

This commit is contained in:
kramo
2023-08-15 21:19:27 +02:00
parent 9b97e8c355
commit 5551756111
2 changed files with 25 additions and 18 deletions

View File

@@ -331,13 +331,19 @@ class CartridgesWindow(Adw.ApplicationWindow):
def on_undo_action(self, _widget, game=None, undo=None):
if not game: # If the action was activated via Ctrl + Z
try:
game = tuple(self.toasts.keys())[-1][0]
undo = tuple(self.toasts.keys())[-1][1]
except IndexError:
return
if shared.importer.imported_game_ids or shared.importer.removed_game_ids:
undo = "import"
else:
try:
game = tuple(self.toasts.keys())[-1][0]
undo = tuple(self.toasts.keys())[-1][1]
except IndexError:
return
if undo == "hide":
if undo == "import":
shared.importer.undo_import()
elif undo == "hide":
game.toggle_hidden(False)
elif undo == "remove":
@@ -345,8 +351,9 @@ class CartridgesWindow(Adw.ApplicationWindow):
game.save()
game.update()
self.toasts[(game, undo)].dismiss()
self.toasts.pop((game, undo))
if game:
self.toasts[(game, undo)].dismiss()
self.toasts.pop((game, undo))
def on_open_menu_action(self, *_args):
if self.stack.get_visible_child() == self.library_view: