From 662586765b5f987b9480741c9b34c178288ff762 Mon Sep 17 00:00:00 2001 From: Sam Penny <33956017+sam1penny@users.noreply.github.com> Date: Mon, 18 Jul 2022 04:01:36 +0100 Subject: [PATCH] Load previously loaded profile (#1960) * added option to load the last loaded profile * add formatting changes for tests * fix comments - integrate as new functionality rather than as an option, fix type hinting and remove bug if profile is deleted --- qt/aqt/main.py | 4 ++++ qt/aqt/profiles.py | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/qt/aqt/main.py b/qt/aqt/main.py index e5e049d38..45d0a262f 100644 --- a/qt/aqt/main.py +++ b/qt/aqt/main.py @@ -282,8 +282,12 @@ class AnkiQt(QMainWindow): if not self.pm.name: # if there's a single profile, load it automatically profs = self.pm.profiles() + name = self.pm.last_loaded_profile_name() if len(profs) == 1: self.pm.load(profs[0]) + elif name in profs: + self.pm.load(name) + if not self.pm.name: self.showProfileManager() else: diff --git a/qt/aqt/profiles.py b/qt/aqt/profiles.py index 6d00fb6a3..0aa5bb27c 100644 --- a/qt/aqt/profiles.py +++ b/qt/aqt/profiles.py @@ -220,6 +220,7 @@ class ProfileManager: print("resetting corrupt profile") self.profile = profileConf.copy() self.save() + self.set_last_loaded_profile_name(name) return True def save(self) -> None: @@ -544,6 +545,12 @@ create table if not exists profiles def set_new_import_export(self, enabled: bool) -> None: self.meta["new_import_export"] = enabled + def last_loaded_profile_name(self) -> str | None: + return self.meta.get("last_loaded_profile_name") + + def set_last_loaded_profile_name(self, name: str) -> None: + self.meta["last_loaded_profile_name"] = name + # Profile-specific ######################################################################