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

@@ -216,33 +216,33 @@ class CartridgesApplication(Adw.Application):
DetailsWindow()
def on_import_action(self, *_args):
importer = Importer()
shared.importer = Importer()
if shared.schema.get_boolean("lutris"):
importer.add_source(LutrisSource())
shared.importer.add_source(LutrisSource())
if shared.schema.get_boolean("steam"):
importer.add_source(SteamSource())
shared.importer.add_source(SteamSource())
if shared.schema.get_boolean("heroic"):
importer.add_source(HeroicSource())
shared.importer.add_source(HeroicSource())
if shared.schema.get_boolean("bottles"):
importer.add_source(BottlesSource())
shared.importer.add_source(BottlesSource())
if shared.schema.get_boolean("flatpak"):
importer.add_source(FlatpakSource())
shared.importer.add_source(FlatpakSource())
if shared.schema.get_boolean("itch"):
importer.add_source(ItchSource())
shared.importer.add_source(ItchSource())
if shared.schema.get_boolean("legendary"):
importer.add_source(LegendarySource())
shared.importer.add_source(LegendarySource())
if shared.schema.get_boolean("retroarch"):
importer.add_source(RetroarchSource())
shared.importer.add_source(RetroarchSource())
importer.run()
shared.importer.run()
def on_remove_game_action(self, *_args):
self.win.active_game.remove_game()

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: