From 6a888242d3b874d71624ef065fcf9a1fba425227 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Wed, 1 Feb 2023 12:03:16 +0100 Subject: [PATCH] Squish: Close opened squish files ..when switching sessions or closing test suites. There is no need to keep them opened inside QC. Change-Id: I5b4ddec64ca11a0d82b28d2946bebff9fa0a4bac Reviewed-by: David Schulz --- src/plugins/squish/squishfilehandler.cpp | 27 ++++++++++++------------ 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/plugins/squish/squishfilehandler.cpp b/src/plugins/squish/squishfilehandler.cpp index 808b3491e14..956f9488227 100644 --- a/src/plugins/squish/squishfilehandler.cpp +++ b/src/plugins/squish/squishfilehandler.cpp @@ -291,12 +291,22 @@ void SquishFileHandler::openTestSuite(const Utils::FilePath &suiteConfPath, bool ProjectExplorer::SessionManager::setValue(SK_OpenSuites, suitePathsAsStringList()); } +static void closeOpenedEditorsFor(const Utils::FilePath &filePath, bool askAboutModifiedEditors) +{ + const QList openDocuments = Utils::filtered( + Core::DocumentModel::openedDocuments(), [filePath](Core::IDocument *doc) { + return doc->filePath().isChildOf(filePath); + }); + // for now just ignore modifications - files will be removed completely + Core::EditorManager::closeDocuments(openDocuments, askAboutModifiedEditors); +} + void SquishFileHandler::closeTestSuite(const QString &suiteName) { if (!m_suites.contains(suiteName)) return; - // TODO close respective editors if there are any + closeOpenedEditorsFor(m_suites.value(suiteName).parentDir(), true); // TODO remove file watcher m_suites.remove(suiteName); emit suiteTreeItemRemoved(suiteName); @@ -309,16 +319,6 @@ void SquishFileHandler::closeAllTestSuites() ProjectExplorer::SessionManager::setValue(SK_OpenSuites, suitePathsAsStringList()); } -static void closeOpenedEditorsFor(const Utils::FilePath &filePath) -{ - const QList openDocuments = Utils::filtered( - Core::DocumentModel::openedDocuments(), [filePath](Core::IDocument *doc) { - return doc->filePath().isChildOf(filePath); - }); - // for now just ignore modifications - files will be removed completely - Core::EditorManager::closeDocuments(openDocuments, false); -} - void SquishFileHandler::deleteTestCase(const QString &suiteName, const QString &testCaseName) { if (!m_suites.contains(suiteName)) @@ -334,7 +334,7 @@ void SquishFileHandler::deleteTestCase(const QString &suiteName, const QString & const Utils::FilePath suiteConfPath = m_suites.value(suiteName); SuiteConf suiteConf = SuiteConf::readSuiteConf(suiteConfPath); const Utils::FilePath testCaseDirectory = suiteConfPath.parentDir().pathAppended(testCaseName); - closeOpenedEditorsFor(testCaseDirectory); + closeOpenedEditorsFor(testCaseDirectory, false); QString error; if (!testCaseDirectory.removeRecursively(&error)) { QString detail = Tr::tr("Deletion of Test Case failed."); @@ -352,8 +352,9 @@ void SquishFileHandler::deleteTestCase(const QString &suiteName, const QString & void SquishFileHandler::closeAllInternal() { - // TODO close respective editors if there are any // TODO remove file watcher + for (auto suiteConfFilePath : m_suites) + closeOpenedEditorsFor(suiteConfFilePath.parentDir(), true); const QStringList &suiteNames = m_suites.keys(); m_suites.clear(); for (const QString &suiteName : suiteNames)