From 9ac0ac9ca1b535f021e42cb34b49d06d49dbbad2 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Thu, 29 Sep 2022 16:06:46 +0200 Subject: [PATCH] Squish: Store opened suites into session Opened test suites will now be stored into the session and re-opened automatically when the session is loaded. Change-Id: I5b7e55bf511918cb2e9eeec6f943cc7baced0a8f Reviewed-by: David Schulz --- src/plugins/squish/squishfilehandler.cpp | 32 ++++++++++++++++++++++++ src/plugins/squish/squishfilehandler.h | 3 +++ 2 files changed, 35 insertions(+) diff --git a/src/plugins/squish/squishfilehandler.cpp b/src/plugins/squish/squishfilehandler.cpp index 6c3bfea6a06..435d3d70644 100644 --- a/src/plugins/squish/squishfilehandler.cpp +++ b/src/plugins/squish/squishfilehandler.cpp @@ -12,6 +12,8 @@ #include #include +#include +#include #include #include @@ -22,12 +24,17 @@ namespace Squish { namespace Internal { +static const char SK_OpenSuites[] = "SquishOpenSuites"; + static SquishFileHandler *m_instance = nullptr; SquishFileHandler::SquishFileHandler(QObject *parent) : QObject(parent) { m_instance = this; + auto sessionManager = ProjectExplorer::SessionManager::instance(); + connect(sessionManager, &ProjectExplorer::SessionManager::sessionLoaded, + this, &SquishFileHandler::onSessionLoaded); } SquishFileHandler *SquishFileHandler::instance() @@ -191,6 +198,7 @@ void SquishFileHandler::openTestSuites() } } emit suitesOpened(); + ProjectExplorer::SessionManager::setValue(SK_OpenSuites, m_suites.values()); } void SquishFileHandler::openTestSuite(const Utils::FilePath &suitePath, bool isReopen) @@ -221,6 +229,7 @@ void SquishFileHandler::openTestSuite(const Utils::FilePath &suitePath, bool isR m_suites.insert(suiteName, suitePathStr); emit testTreeItemCreated(item); } + ProjectExplorer::SessionManager::setValue(SK_OpenSuites, m_suites.values()); } void SquishFileHandler::closeTestSuite(const QString &suiteName) @@ -232,9 +241,16 @@ void SquishFileHandler::closeTestSuite(const QString &suiteName) // TODO remove file watcher m_suites.remove(suiteName); emit suiteTreeItemRemoved(suiteName); + ProjectExplorer::SessionManager::setValue(SK_OpenSuites, m_suites.values()); } void SquishFileHandler::closeAllTestSuites() +{ + closeAllInternal(); + ProjectExplorer::SessionManager::setValue(SK_OpenSuites, m_suites.values()); +} + +void SquishFileHandler::closeAllInternal() { // TODO close respective editors if there are any // TODO remove file watcher @@ -395,5 +411,21 @@ void SquishFileHandler::openObjectsMap(const QString &suiteName) } } +void SquishFileHandler::onSessionLoaded() +{ + // remove currently opened "silently" (without storing into session) + closeAllInternal(); + + const QVariant variant = ProjectExplorer::SessionManager::value(SK_OpenSuites); + const Utils::FilePaths suitePaths = Utils::transform(variant.toStringList(), + &Utils::FilePath::fromString); + + // open suites of the old session + for (const Utils::FilePath &fp : suitePaths) { + if (fp.exists()) + openTestSuite(fp); + } +} + } // namespace Internal } // namespace Squish diff --git a/src/plugins/squish/squishfilehandler.h b/src/plugins/squish/squishfilehandler.h index adaccbf0f46..e1ea6f29bb8 100644 --- a/src/plugins/squish/squishfilehandler.h +++ b/src/plugins/squish/squishfilehandler.h @@ -40,6 +40,9 @@ signals: void suitesOpened(); private: + void closeAllInternal(); + void onSessionLoaded(); + QMap m_suites; QStringList m_sharedFolders;