From 1b9f9a57d36de6f09d9bd23be6b8c8ed3defb28f Mon Sep 17 00:00:00 2001 From: Pedro Acebes Date: Tue, 1 Oct 2024 17:36:53 +0200 Subject: [PATCH] Fix #24678: Remember which tab was last open within a session Final code review fix --- src/appshell/iappshellconfiguration.h | 3 +++ src/appshell/internal/appshellconfiguration.cpp | 10 ++++++++++ src/appshell/internal/appshellconfiguration.h | 5 +++++ src/appshell/view/preferences/preferencesmodel.cpp | 8 +++++++- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/appshell/iappshellconfiguration.h b/src/appshell/iappshellconfiguration.h index ed0bb20e18304..b7d6c1965f113 100644 --- a/src/appshell/iappshellconfiguration.h +++ b/src/appshell/iappshellconfiguration.h @@ -66,6 +66,9 @@ class IAppShellConfiguration : MODULE_EXPORT_INTERFACE virtual bool needShowSplashScreen() const = 0; virtual void setNeedShowSplashScreen(bool show) = 0; + virtual const QString& preferencesDialogLastOpenedPageId() const = 0; + virtual void setPreferencesDialogLastOpenedPageId(const QString& lastOpenedPageId) = 0; + virtual void startEditSettings() = 0; virtual void applySettings() = 0; virtual void rollbackSettings() = 0; diff --git a/src/appshell/internal/appshellconfiguration.cpp b/src/appshell/internal/appshellconfiguration.cpp index 6387abf93ced0..68099a3366308 100644 --- a/src/appshell/internal/appshellconfiguration.cpp +++ b/src/appshell/internal/appshellconfiguration.cpp @@ -188,6 +188,16 @@ void AppShellConfiguration::setNeedShowSplashScreen(bool show) settings()->setSharedValue(SPLASH_SCREEN_VISIBLE_KEY, Val(show)); } +const QString& AppShellConfiguration::preferencesDialogLastOpenedPageId() const +{ + return m_preferencesDialogCurrentPageId; +} + +void AppShellConfiguration::setPreferencesDialogLastOpenedPageId(const QString& lastOpenedPageId) +{ + m_preferencesDialogCurrentPageId = lastOpenedPageId; +} + void AppShellConfiguration::startEditSettings() { settings()->beginTransaction(); diff --git a/src/appshell/internal/appshellconfiguration.h b/src/appshell/internal/appshellconfiguration.h index 0b6f2589526a0..e21a79c44138e 100644 --- a/src/appshell/internal/appshellconfiguration.h +++ b/src/appshell/internal/appshellconfiguration.h @@ -85,6 +85,9 @@ class AppShellConfiguration : public IAppShellConfiguration, public muse::Inject bool needShowSplashScreen() const override; void setNeedShowSplashScreen(bool show) override; + const QString& preferencesDialogLastOpenedPageId() const override; + void setPreferencesDialogLastOpenedPageId(const QString& lastOpenedPageId) override; + void startEditSettings() override; void applySettings() override; void rollbackSettings() override; @@ -106,6 +109,8 @@ class AppShellConfiguration : public IAppShellConfiguration, public muse::Inject muse::Ret writeSessionState(const QByteArray& data); muse::io::paths_t parseSessionProjectsPaths(const QByteArray& json) const; + + QString m_preferencesDialogCurrentPageId; }; } diff --git a/src/appshell/view/preferences/preferencesmodel.cpp b/src/appshell/view/preferences/preferencesmodel.cpp index 4f8047498988e..48f6415741d77 100644 --- a/src/appshell/view/preferences/preferencesmodel.cpp +++ b/src/appshell/view/preferences/preferencesmodel.cpp @@ -143,7 +143,12 @@ void PreferencesModel::load(const QString& currentPageId) if (!currentPageId.isEmpty()) { setCurrentPageId(currentPageId); } else { - setCurrentPageId("general"); + const QString& lastOpenedPageId = configuration()->preferencesDialogLastOpenedPageId(); + if (lastOpenedPageId.isEmpty()) { + setCurrentPageId("general"); + } else { + setCurrentPageId(lastOpenedPageId); + } } m_rootItem = new PreferencePageItem(); @@ -275,6 +280,7 @@ void PreferencesModel::setCurrentPageId(QString currentPageId) } m_currentPageId = currentPageId; + configuration()->setPreferencesDialogLastOpenedPageId(currentPageId); emit currentPageIdChanged(m_currentPageId); }